CSS Grid Generator: Visual Layout Builder with Grid Areas
Free CSS grid generator: set columns, rows and gaps, drag to create named grid-template-areas, and copy clean CSS, HTML or Tailwind code.
How to use the CSS grid generator
- Pick a starting layout under Layouts, or start from the empty 3×3 grid.
- Set the columns and rows. Use the + and − buttons to change how many there are, and type a size into each box:
1fr,200px,auto,minmax(0, 680px)and so on. A red border means the size isn’t valid CSS. - Adjust the gaps with the column gap and row gap sliders.
- Drag across the grid to create a named area. Rename it in the Areas list. Click an existing area to rename it, or drag over it to replace it.
- Copy the code as plain CSS, HTML, or Tailwind classes.
The preview is a real CSS grid, so what you see is exactly what the code does. New to the units? The CSS grid guide explains fr, repeat() and minmax() in detail.
What the generated CSS looks like
The generator writes the whole layout on the container and gives each area a one-line rule. Here is the Holy grail layout:
.container {
display: grid;
grid-template-columns: 200px 1fr 200px;
grid-template-rows: auto 1fr auto;
grid-template-areas:
"header header header"
"nav main aside"
"footer footer footer";
gap: 16px;
}
.header { grid-area: header; }
.nav { grid-area: nav; }
.main { grid-area: main; }
.aside { grid-area: aside; }
.footer { grid-area: footer; }
Each quoted string is one row, and each word is one column. Because the areas are named, the HTML order doesn’t matter: the browser places every element where its name appears in the template.
grid-template-areas rules
Named areas are the easiest way to read a layout at a glance, but the browser drops the whole grid-template-areas declaration if one rule is broken. The generator follows them for you:
- Areas must be rectangles. An L-shaped or T-shaped area is invalid. To get that shape, use two areas.
- Every row needs the same number of cells. If the grid has 3 columns, every string needs 3 words.
- A dot (
.) is an empty cell. The generator writes a dot for every cell you haven’t assigned to an area. - Names are plain identifiers. Letters, numbers, hyphens and underscores, not starting with a number. The generator cleans up names as you type, and makes duplicates unique.
Ready-made layouts
- Holy grail: header and footer across the full width, with navigation, content and a sidebar in between.
- Sidebar: a full-height sidebar next to a header, main content and footer. The classic app or docs layout.
- Dashboard: sidebar, top bar, and a content area split into stats, a chart and a table.
- Bento: a mix of large and small tiles, popular for landing pages and portfolios.
- Article: a readable center column (
minmax(0, 680px)) with flexible space on both sides, so full-width images can break out of the text column.
Make the layout responsive
The generated grid is the desktop layout. The easiest way to make it responsive is to stack everything in one column on small screens, then switch to the generated grid at a breakpoint. Only the container rules change, so the grid-area rules stay as they are:
.container {
display: grid;
grid-template-areas:
"header"
"main"
"nav"
"aside"
"footer";
gap: 16px;
}
@media (min-width: 900px) {
.container {
grid-template-columns: 200px 1fr 200px;
grid-template-rows: auto 1fr auto;
grid-template-areas:
"header header header"
"nav main aside"
"footer footer footer";
}
}
Notice that main comes before nav on mobile, without touching the HTML. For a card grid that adapts without any media query, see auto-fill and minmax() in the CSS grid guide.
Using the Tailwind output
The Tailwind tab places each item by line numbers instead of names, because Tailwind has no utility for grid-template-areas. col-start-1 col-end-4 means the item starts at column line 1 and ends at line 4, so it spans three columns. Equal 1fr tracks become grid-cols-3, and anything else uses an arbitrary value:
<div class="grid grid-cols-[200px_1fr_200px] grid-rows-[auto_1fr_auto] gap-4">
<div class="col-start-1 col-end-4 row-start-1">header</div>
<div class="col-start-1 row-start-2">nav</div>
<div class="col-start-2 row-start-2">main</div>
<div class="col-start-3 row-start-2">aside</div>
<div class="col-start-1 col-end-4 row-start-3">footer</div>
</div>
FAQ
Is this CSS grid generator free?
Yes. It runs entirely in your browser, with no sign-up and no limits, and the code is yours to use anywhere.
Why does my 1fr row have no height?
A 1fr row shares the container’s free height. If the container has no height of its own, there is nothing to share and the row shrinks to its content. Give the container a height, for example min-height: 100vh on a page layout.
What is the difference between grid-gap and gap?
None. grid-gap is the old name. Use gap, which also works in flexbox.
Can an element span cells without a named area?
Yes. Use line numbers, like grid-column: 1 / 4 to span three columns. That is what the Tailwind output does.
Should I use grid or flexbox?
Grid for two-dimensional page layouts, flexbox for rows of items like navbars and button groups. The CSS flexbox guide covers the other half.
Styling the cards inside your grid? Try the box shadow generator and the border radius generator.