CSS Grid generator
Draw a grid, drag to name an area, copy the CSS and HTML. Flexbox is on the second tab, and it all runs in your browser.
Start from a layout
Drag across the cells to name an area, or click a start cell and then an end cell. On a touch screen, tap the two corners instead, because a swipe pans the grid. With the keyboard, move between cells with the arrow keys and press Enter twice. Escape cancels.
Column sizes
Row sizes
CSS
HTML
Preview
The items are sized by their content. Give one a basis of, say, 240px to see wrapping and shrinking do something.
Per item
CSS
HTML
Draw it, paste the code.
-
Start from five layouts
Page shell, Sidebar, Dashboard, Gallery or Magazine. Undo brings your grid back.
-
Why 1fr fits and percent spills
A percent ignores the gap, so three 33.33% columns with a 16px gap run 32px over.
-
Grid or flexbox
Flexbox sizes each item by its content. Grid tracks hold across rows. Both are tabs.
Drag a box, get a rule.
Drag across cells
Or click two corners. On a touch screen tap them, and with a keyboard press Enter twice.
Lines, not cells
The numbers count grid lines, so a header across three columns ends on line 4.
One rule per area
Each rule stands alone, so it pastes into a stylesheet you already have.
Overlaps get refused
This line confirms each area. Draw across one and it names the area in the way.
How to make a CSS grid.
-
Set up the tracks
Pick a starter layout, or set columns, rows, gaps and height yourself.
-
Drag your areas
Type a name or take the suggested one, then drag across its cells.
-
Copy the code
Copy the CSS and the HTML. The preview has the same boxes you paste.
Two patterns to paste next.
Cards that wrap by themselves, with no media query. The tool cannot draw this one.
.gallery {
display: grid;
grid-template-columns:
repeat(auto-fill, minmax(240px, 1fr));
gap: 16px;
}A column one long word cannot stretch. In the tool, a minmax track with a 0 minimum.
.grid {
display: grid;
grid-template-columns:
minmax(0, 1fr) 240px;
}CSS grid generator questions.
What do the four numbers in grid-area mean?
They read row-start / column-start / row-end / column-end, and they count grid lines. So the end of a span is one higher than its last cell.
Why did my grid grow extra rows?
Those are implicit tracks. Give a grid more items than cells and the browser adds rows to hold them, sized by grid-auto-rows, which defaults to auto. Set that value, or stop declaring rows.
Do I still need margins between grid items?
No. A gap only goes between tracks, never around the outer edge, so there is no negative margin to add and no last-child rule to write. It behaves the same in grid and flexbox.
Should I use grid or flexbox?
Use grid when the layout exists before the content: a page shell, a dashboard, a gallery. Use flexbox when the content decides: a toolbar, tags, a nav bar. They nest, so a grid shell can hold a flex header.
Does the preview match what I paste?
Yes for the boxes and their sizes, because the height and the rule that keeps empty boxes visible are written into the CSS. Two things differ: fonts come from your page, and Full screen previews 100vh at 480px.
Is anything I draw uploaded?
No. The CSS and HTML are generated in this page, and nothing you draw is sent to a server.
More free tools
- Aspect ratio calculator Solve for a missing dimension, or reduce pixels to the ratio behind them.
- PX to REM Both directions against any root size, plus a type scale you can copy.
- SVG to PNG Convert SVG files to PNG at any scale, in the browser. Batch and transparent background.
- HEX to RGB Paste a hex color, get RGB, HSL and CSS you can copy.
- RGB to HEX The other direction, with the same converter underneath.
- PNG to SVG Trace a bitmap into vector paths, in the browser. Honest about when it works.
Start with the design
you already have.
Install the Figma plugin, send a frame across, and finish it on the canvas.