CSS Grid Stats Section Generator
A band of key numbers with dividers between them, from a 2x2 block on mobile to one row on desktop.
Named areas. The CSS is a picture of the layout, and only the properties that actually change get repeated inside each media query.
.stats {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: auto auto;
gap: 1px;
grid-template-areas:
"stat-1 stat-2"
"stat-3 stat-4";
}
.stats > .stat-1 { grid-area: stat-1; }
.stats > .stat-2 { grid-area: stat-2; }
.stats > .stat-3 { grid-area: stat-3; }
.stats > .stat-4 { grid-area: stat-4; }
@media (min-width: 760px) {
.stats {
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-template-rows: auto;
grid-template-areas:
"stat-1 stat-2 stat-3 stat-4";
}
}
How this layout works
Two by two on mobile, four across on desktop. Four numbers in a single mobile row shrink the figures to the point where they stop being the loud thing on the page, which is their only job.
Draw the dividers with the gap, not with borders. A background colour on the grid container plus a 1px gap and opaque cells gives you hairlines that never double up at the corners.
Reserve the space for numbers that count up on scroll. A figure animating from 0 to 1,284 changes width as it goes; min-width: 4ch or font-variant-numeric: tabular-nums stops the row shuffling while it runs.
Every property used here is listed in the CSS Grid cheat sheet, with the reason to reach for it.
Frequently asked questions
How do I draw dividers between stats without doubling borders?
Why does my stats row jump around while the numbers count up?
font-variant-numeric: tabular-nums fixes the character width, or reserve the space with min-width in ch.How do I center a grid in CSS?
justify-content: center on the grid container to centre the whole grid inside it, and margin-inline: auto with a max-width to centre the container in the page. These are different jobs: the first moves the tracks within the container, the second moves the container itself.How do I center items inside a CSS grid?
place-items: center on the container. That is shorthand for align-items plus justify-items, and it centres every item inside its own cell on both axes. For a single item, use place-self: center on that item instead.How do I make a CSS grid responsive?
grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)) and it reflows at every width with no media queries at all. Add breakpoints only when the exact column count matters, or when the layout has to change shape rather than just wrap.When should I use CSS Grid instead of Flexbox?
How to use it
-
Open the pattern
The stats band loads into the editor already responsive, with every breakpoint set up.
-
Change the tracks
Edit the column and row sizes in the Tracks panel. Anything valid in a track list works.
-
Redraw at another width
Move the ruler past a breakpoint marker and rearrange. Only the placement changes.
-
Copy the code
Take CSS, HTML, Tailwind or a shadcn component. The media queries are already written.
More in Marketing sections
- Split Screen Hero
- Pricing Table
- Footer Columns
- Centered Hero Section
- Feature Grid
- Testimonial Grid
- Logo Wall