CSS Grid makes column layouts trivial once you settle on the right declaration. This generator builds that declaration for you: an equal-column grid with a defined gutter, optionally wrapped in a centered max-width container, plus the small span helpers you reach for most often.
How it works
The container is a grid whose columns are defined with a single repeat call:
.grid {
display: grid;
grid-template-columns: repeat(12, minmax(0, 1fr));
gap: 24px;
max-width: 1200px;
margin-inline: auto;
padding-inline: 16px;
}
repeat(N, minmax(0, 1fr)) creates N equal tracks. The minmax(0, 1fr) idiom
is important: it forces each track’s minimum size to zero so wide content cannot
stretch a column past its fair share. The resolved column width shown in the
preview is (max-width − 2 × padding − (N − 1) × gutter) / N.
Tips and example
For a classic 12-column layout at a 1200px max-width with 24px gutters and 16px
of side padding, each column resolves to roughly 75px. To place content, set
grid-column: span 6 for a half-width block or grid-column: 1 / -1 to span the
full row. For a fluid grid that wraps on its own, replace the fixed count with
repeat(auto-fit, minmax(240px, 1fr)), which keeps columns at least 240px wide
and adds or drops columns as the viewport changes.