CSS Grid
Flexbox rules one dimension; Grid rules two. Columns and rows declared on the parent, children snapping into cells — it's the layout system page-level design waited twenty years for.
1. Columns, rows, and the fr unit
.layout {
display: grid;
grid-template-columns: 200px 1fr 1fr; /* fixed + 2 shares */
gap: 20px;
}The fr unit divides leftover space into fractions: 1fr 2fr gives the second column twice the first. repeat(3, 1fr) shortens equal columns, and children fill cells automatically, left-to-right, wrapping to new rows.
2. The self-responsive card grid
.cards {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
gap: 16px;
}Read it as: "as many columns as fit, each at least 220px, sharing extra space equally." Shrink the container and columns drop out one by one. This single line powers the tool grid on this site's home page.
3. Spanning and placing
.feature {
grid-column: span 2;
grid-row: span 2;
}Any child can claim more cells with span, or exact tracks with line numbers (grid-column: 1 / 3). For whole page skeletons, grid-template-areas lets you draw the layout as ASCII art — explore it in the Grid Playground.
4. Try it yourself
Turn the container into a responsive grid with repeat(auto-fill, minmax(140px, 1fr)) and a 12px gap, then make the first card span two columns.
5. Quiz — check your understanding
CSS Grid Quiz
4 questions · pass at 60%Q1. grid-template-columns: 1fr 2fr gives the second column…
Q2. Which one-liner creates a self-responsive card grid?
Q3. A child spans two columns with…
Q4. Grid vs Flexbox in one sentence:
Every lesson quiz you pass (60%+) is saved in your browser and counts toward the CSSmatic Certificate of Completion.