CSS Grid generator
Build a CSS Grid container with a live preview — fixed columns or responsive auto-fit.
Runs 100% in your browserHow to use the grid generator
- Choose columns and rows. Pick a fixed column count or an auto-fit responsive grid.
- Adjust gap and minmax. Slide gap and the minimum column width to taste.
- Copy the CSS. Click Copy to grab the container rule.
A two-dimensional layout model
CSS Grid describes a layout as explicit rows and columns, then places items into the
cells those tracks create. That two-axis control is what sets it apart from flexbox, which only
ever lays out along a single line. Reach for Grid when both dimensions matter at once — a page
shell with header, sidebar, main column and footer, or a card wall where rows must stay aligned
even when individual cards differ in height. Items can span multiple tracks
(grid-column: 1 / 3) and even overlap, so Grid also handles magazine-style and
layered designs that would otherwise need absolute positioning.
Fixed tracks vs. auto-fit + minmax
This generator covers the two patterns that carry most production layouts. A
fixed column count — repeat(3, 1fr) — suits known structures: a
12-column app grid, or a 240px 1fr sidebar split. The auto-fit + minmax
pattern, repeat(auto-fit, minmax(200px, 1fr)), is the responsive workhorse: the
browser packs in as many columns as the minimum width allows, then stretches them to fill the
row — a fluid card grid with no media queries at all. Swap auto-fit for
auto-fill when you want empty trailing tracks preserved rather than collapsed.
fr units, gap and a common gotcha
The fr unit distributes leftover space after fixed sizes and gaps are
subtracted, so 200px 1fr 1fr gives the fixed column its 200px and splits the rest in
two. The most common surprise is grid blowout: a long word or a wide image forces a track past
its 1fr share, because a track's implicit minimum size is auto, not
zero. The fix is minmax(0, 1fr), which lets the track shrink below its content.
gap spaces tracks without adding outer margins, retiring the old fragile
negative-margin gutter hacks.
Frequently asked questions
- A two-dimensional layout system — you control rows and columns at the same time. Best for page-level layouts and any grid where row spans matter.
- fr (fraction) units distribute leftover space proportionally — 1fr 2fr means the second column gets twice the remaining space. Mix with fixed sizes (e.g. 200px 1fr) for sidebars.
- It creates as many same-sized columns as will fit, each at least the minmax minimum. The most common responsive grid pattern.
- Grid when both axes matter (page layouts). Flexbox when content flows in one direction (toolbars, button rows).