CSS Grid Generator
Draw a grid layout and copy the CSS and HTML for it
How to Build a CSS Grid Layout - Step by Step
Set Up the Columns and Rows
A CSS grid starts with its tracks. Pick a preset or press Clear, then choose how many columns and rows you need (up to 12 of each) and give every track a size.
1fr shares free space, 200px or 25% is fixed, auto fits the content, and minmax(100px, 1fr) sets a floor and a ceilinggap linefr only get room when the container has a height, so the presets set a min-height you can change or clearPlace Your Items
Drag across the dashed cells in the preview to create an item that spans them. On a phone, tap the start cell and then the end cell. Each item shows up in the list on the left, where you can rename it and fine-tune its grid-column and grid-row lines by number.
header and main and no overlaps, the output uses grid-template-areasrepeat(auto-fit, minmax(200px, 1fr)) insteadCopy the CSS and HTML
The CSS tab holds a .grid-container rule plus one class per item; the HTML tab has the markup that uses those classes. For the holy grail preset the CSS looks like this:
.grid-container {
display: grid;
grid-template-columns: 200px 1fr 200px;
grid-template-rows: auto 1fr auto;
grid-template-areas:
"header header header"
"sidebar main aside"
"footer footer footer";
gap: 16px;
min-height: 400px;
}
.header {
grid-area: header;
}.main-content, and the tool says so in the notesFrequently Asked Questions
How do I make a layout with this CSS grid generator?
Pick a preset or press Clear, set how many columns and rows you want, and type a size for each one (1fr, 200px, 25%, auto or minmax(100px, 1fr)). Then drag across the preview to create an item, or tap a start cell and an end cell on a phone. Each item gets a name you can change, and the CSS and HTML below the preview update as you go.
When does the generator use grid-template-areas?
When the "Use grid-template-areas" box is ticked and the layout allows it: every item name is a plain CSS identifier like header or main-content, names are unique, no two items overlap and every item sits inside the grid. Then the container gets a grid-template-areas map and each item gets grid-area: name. If any of that is not true, the generator writes grid-column and grid-row line numbers instead and tells you why.
Is the preview the same as the CSS I copy?
Yes. The preview is styled from the same list of declarations that is printed in the CSS tab, so the track sizes, gaps, alignment and item positions you see are the ones you get. The only extras in the preview are the colours, the dashed cell lines and a 14px font, which are there so you can see the grid.
What happens if I type a track size the browser does not understand?
The field turns red and a message names the column or row and the value, for example Column 2: "abc" is not a track size. While a size is wrong the preview and the code are hidden, so you never copy CSS with a track quietly missing. repeat() inside a single field is refused too, because the Columns and Rows counts already handle repetition.
How do I make a responsive card grid without media queries?
Choose Auto-fit cards (or the Card grid preset). The generator writes grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)), so the browser fits as many 200px-or-wider columns as the container allows and stretches them to fill the row. Switch to auto-fill if you want empty column slots kept when there are only a few cards.
When should I use CSS Grid instead of Flexbox?
Grid is the better fit when you care about rows and columns at the same time: page shells, dashboards, galleries, forms that line up in columns. Flexbox suits one direction at a time, like a toolbar or a row of buttons that should wrap. The two work well together, for example a grid page with a flex navigation bar inside the header.
Does my layout get uploaded anywhere?
No. The grid is built in your browser and nothing is sent to our server or kept after you leave, so a reload starts from the default layout again.
Laying out a single row or column? The CSS flexbox generator is the simpler tool for that. Once your stylesheet is done, tidy it with the CSS formatter or shrink it with the CSS minifier.
Related Tools
CSS Minifier
Minify and compress CSS code
CSS Beautifier
Beautify and format CSS code
CSS Formatter
Format and organize CSS code
CSS Fixer
Fix broken CSS automatically, repair syntax errors, missing semicolons, and malformed styles
CSS Compressor
Compress and minify CSS code
CSS Autoprefixer
Automatically add vendor prefixes for cross-browser compatibility