Visual Grid Builder
Set columns, rows, track sizes and gaps, and see the grid change live as you work.
Build a CSS Grid layout visually. Set columns, rows and gaps, drag across the cells to place items, and copy clean HTML and CSS code. Includes ready-made layouts.
Drag across the dashed cells to create an item. You can fine-tune each item below.
Choose columns, rows, track sizes and gaps, or start from a preset.
Drag across the cells to create items, then adjust their position.
Copy the generated CSS and HTML into your project.
CSS Grid is the most powerful layout system on the web. It lets you design pages in rows and columns at the same time, place items exactly where you want them, and build complex layouts, such as dashboards, galleries, magazine pages and holy grail layouts, with a few lines of CSS and no hacks. The syntax, however, takes time to learn. This free CSS Grid generator, also known as a CSS grid layout builder or grid playground, lets you build the layout visually and then copy clean HTML and CSS.
Set the number of columns and rows, type a size for every track, adjust the gaps, then drag across the cells to create items that span them. You can switch between line numbers and grid-template-areas, start from a preset such as Holy grail, Blog, Gallery or Dashboard, and see the result live. Everything runs in your browser, so there is no signup, no installation and nothing is uploaded.
Set columns, rows, track sizes and gaps, and see the grid change live as you work.
Drag across the cells to create an item that spans them, then fine-tune its start and end lines.
Copy ready-to-use code with line numbers or grid-template-areas, using standard CSS with no dependencies.
CSS Grid Layout, usually called CSS Grid, is a two-dimensional layout system built into CSS. You turn an element into a grid container with display: grid, define its columns and rows, and then its children become grid items that can be placed in the cells. Unlike older techniques such as floats, tables and inline-block layouts, Grid was designed for layout from the start, so the code is shorter, more readable and far easier to change.
Grid works in all modern browsers, including Chrome, Edge, Firefox and Safari. If you can describe a layout as rows and columns on paper, you can describe it in CSS Grid.
You can have a working layout in less than a minute.
| Property | What it does |
|---|---|
| display: grid | Turns an element into a grid container. |
| grid-template-columns | Defines the number and width of columns. |
| grid-template-rows | Defines the number and height of rows. |
| gap, row-gap, column-gap | Sets the space between rows and columns. |
| grid-column, grid-row | Places an item using start and end lines. |
| grid-area | Places an item by name, or by all four lines at once. |
| grid-template-areas | Draws the layout with named areas. |
| justify-items, align-items | Aligns items inside their cells. |
| justify-content, align-content | Aligns the whole grid inside its container. |
The grid-template-columns property lists the width of each column, separated by spaces. The value 200px 1fr 200px creates three columns, with two fixed sidebars and a flexible middle column. The fr unit is the one that makes Grid so convenient: it means a fraction of the free space, after fixed sizes and gaps are taken out. Three columns of 1fr share the space equally, and 1fr 2fr gives the second column twice the width of the first. You can mix fr with px, rem, auto and minmax() in the same grid.
.grid-container {
display: grid;
grid-template-columns: 200px 1fr 200px;
grid-template-rows: auto 1fr auto;
gap: 10px;
}
A grid with three columns has four vertical lines, numbered 1 to 4 from the left, and a grid with three rows has four horizontal lines. You place an item by saying which lines it starts and ends at. The declaration grid-column: 1 / 3 means that an item starts at line 1 and ends at line 3, so it covers the first two columns. The keyword span gives the same result in another way: grid-column: 1 / span 2. Negative numbers count from the end, so 1 / -1 always stretches an item across the whole width, however many columns there are.
With grid-template-areas, you draw the layout as text. Each string is a row, each word is a cell, and a dot marks an empty cell. A header that spans the whole width can be written as "header header", and a sidebar next to the main content as "sidebar main". Every item then gets a name with grid-area, and the CSS reads almost like a picture of the page. This makes it easy to understand and to change inside a media query for mobile screens.
.grid-container {
display: grid;
grid-template-columns: 200px 1fr;
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
}
.header { grid-area: header; }
Areas must be rectangles and cannot overlap, so if your items overlap, the generator uses line numbers instead and tells you why.
| Feature | Line numbers | Named areas |
|---|---|---|
| CSS used | grid-column and grid-row | grid-template-areas and grid-area |
| Readability | Precise, but you must count lines | Looks like a map of the page |
| Overlapping items | Allowed | Not allowed |
| Best for | Galleries, dashboards, spanning items | Page layouts such as header, sidebar, main and footer |
Presets are a fast way to learn. The holy grail layout has a header, a footer, a main column and two side columns. The blog layout puts a wide article next to a narrower sidebar. The gallery repeats equal cells for images. The dashboard mixes small and large panels that span several rows and columns. Load one, change the track sizes, drag an item to a new position and read how the generated CSS changes. After a few tries, the syntax starts to feel natural.
Grid and Flexbox are not competitors, they solve different problems. Flexbox is one-dimensional: it lays items out along a single row or a single column, and it is perfect for navigation bars, toolbars, button groups and centering. Grid is two-dimensional: it controls rows and columns together, which makes it the better choice for page layouts, galleries and dashboards. Many real pages use both, with Grid for the page structure and Flexbox for the components inside it. You can try the other model in our CSS Flexbox generator.
The code that this generator creates is a fixed starting point, and it is easy to adapt to different screens. The simplest way is a media query that redefines the columns for small screens, for example a single column on phones. Another approach does not need media queries at all: grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)) creates as many columns as fit, and each column is at least 240px wide. Cards then rearrange themselves as the screen gets narrower. Combine this with gap for spacing and your layout stays tidy at every width.
.gallery {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
gap: 16px;
}
| Mistake | How to avoid it |
|---|---|
| Mixing up the order in grid-area | It is row-start, column-start, row-end, column-end, not x and y. |
| Forgetting the height | Rows with fr units need a container with a defined height. Without it, they only grow to fit their content. |
| Counting tracks instead of lines | Three columns have four lines, so spanning the whole width means 1 / 4. |
| Overlapping items by accident | Two items placed in the same cell are drawn on top of each other. |
| Using margins for spacing | The gap property is cleaner than margins on each item. |
| Fixed widths on small screens | Use fr, minmax() or media queries, so the grid does not overflow on phones. |
People find this page when they look for a CSS grid generator, CSS grid layout generator, CSS grid builder, grid-template-columns generator, grid-template-areas generator, visual CSS grid editor, CSS grid code generator, a holy grail layout with CSS Grid, a CSS grid gap generator, a responsive grid generator or a CSS grid playground. All of them describe the same need: a quick, visual way to get correct grid code.
Yes. The output is standard CSS and HTML with no dependencies. Rename the classes to match your project and add your own content. The generator runs in your browser, so your layout is not uploaded or stored on our server, and there is no account or limit.
Grid lets you place an item anywhere, which makes it tempting to reorder content visually. Keep in mind that keyboard focus and screen readers follow the order of your HTML, not the position on the screen. Write the HTML in a logical reading order first, then use the grid to position items. If a visual order must differ from the source order, test it with the Tab key and make sure focus never jumps around in a confusing way. A layout that looks right and also reads right is the goal.
| Property | Applies to | What it controls |
|---|---|---|
| justify-items | Grid container | Horizontal alignment of every item inside its cell. |
| align-items | Grid container | Vertical alignment of every item inside its cell. |
| justify-self, align-self | Single grid item | Overrides the container alignment for one item. |
| justify-content | Grid container | Horizontal position of the whole grid when it is smaller than the container. |
| align-content | Grid container | Vertical position of the whole grid when it is shorter than the container. |
The two groups are easy to mix up. Items alignment moves things inside their cells, while content alignment moves the entire grid inside its container. Use the alignment controls in the generator to see the difference.
Our free CSS Grid generator makes it easy to design a grid layout, see it live and copy clean HTML and CSS code in seconds. Set up your grid, drag out your items and use the code in your project, with no signup and without anything leaving your browser.
Quick answers about building grid layouts and using the generated code.
A CSS Grid generator is a visual tool that lets you design a grid layout by choosing the number of columns and rows, the size of each track and the gaps, then placing items on the grid. It writes the matching HTML and CSS for you, so you do not have to write grid-template-columns, grid-template-rows and grid-area by hand.
Set the number of columns and rows, adjust the track sizes and gaps, and then drag across the cells of the preview to create an item that spans them. You can also start from a preset such as a holy grail or dashboard layout. Copy the CSS and HTML when you are happy with the result.
The fr unit means a fraction of the available space. If you have three columns that are all 1fr, they share the space equally. A layout of 1fr 2fr gives the second column twice the width of the first. You can mix fr with px, rem, auto and minmax() in the same grid.
Line numbers place an item with grid-column and grid-row, using the numbered lines between tracks. Named areas use grid-template-areas, where you draw the layout as text and give each item a name with grid-area. Named areas are easy to read for page layouts, but they need items that do not overlap. The generator supports both.
Flexbox arranges items in one direction, either a row or a column, while CSS Grid arranges items in rows and columns at the same time. Use Grid for page layouts and two-dimensional designs, and Flexbox for aligning items in a single line, such as a navigation bar. They work well together.
Yes. The output is standard CSS and HTML with no dependencies, and CSS Grid is supported by all modern browsers. Rename the classes to match your project, and add your own content. For responsive designs, you can wrap different grid definitions in media queries.
It is free, with no signup. Everything runs in your browser, and your layout is not uploaded or stored on our server.
Build grid layouts, create one-dimensional layouts with the CSS Flexbox generator, tidy your styles with the CSS beautifier or minify CSS before you publish. Explore free developer tools to format, convert and debug your code in one place.
Explore All Developer Tools →