Build grid-template-columns and rows from presets or your own track list, set gaps and alignment, and copy the rule with a live preview beside it.
.grid-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(2, auto);
gap: 12px;
}CSS Grid Generator runs entirely on your device — nothing is uploaded.
You’re on the Free plan. Compare plans
The useful part of grid is not the number of columns, it is `fr` and `minmax()`. An `fr` is a share of the space left after everything fixed has been laid out, which is why `1fr 1fr` and `50% 50%` behave differently the moment you add a gap: the percentages ignore the gap and overflow, the fractions do not.
`repeat(auto-fit, minmax(16rem, 1fr))` is the one line worth memorising. It fills the row with as many columns as fit at the minimum width and stretches them to share what is left, so a card layout reflows at every width with no media queries and no breakpoints to maintain. `auto-fill` is the same except it keeps empty tracks, which matters when the row is half full.
A grid item that will not shrink below its content is usually hitting `min-width: auto`, which is the default and means a track cannot be smaller than the longest unbreakable thing inside it. `minmax(0, 1fr)` instead of `1fr` is the standard fix, and it is the reason a long word or a wide table can blow out a layout that looks fine until real content arrives.
The output is a rule you can paste. Gap, justification and alignment are included only when they differ from the defaults, and the preview is drawn from the same values, so a track list that would not parse shows as nothing rather than quietly rendering something else.
An fr is a share of the free space remaining after gaps and fixed tracks are accounted for; a percentage is a share of the whole container and ignores the gap. Two 50% columns with a gap overflow their container, two 1fr columns do not.
auto-fit collapses empty tracks, so a half-full row stretches its items across the width. auto-fill keeps the empty tracks, so items stay at their natural size and the row has a gap at the end. For card grids auto-fit is usually what people mean.
Because a track's automatic minimum size is its content, so a long word or a wide table sets a floor. Use minmax(0, 1fr) instead of 1fr to let the track shrink past its content, and pair it with overflow or word-break on the item.
Not usually. Named areas are clearest for a page-level layout you will read often; for a repeating list of similar items, a template with repeat() is shorter and easier to make responsive.
Grid when rows and columns need to line up with each other. Flexbox for a single direction where items size themselves. They compose well, and a grid cell can be a flex container.