Grid Template Areas & CSS Subgrid
Sketch entire page layouts visually with grid-template-areas and align nested card elements across columns using subgrid.
What you'll learn
- Define readable page regions using grid-template-areas and grid-area
- Align titles, descriptions, and footers across sibling cards with grid-template-rows: subgrid
Visual Page Blueprints with grid-template-areas
Instead of counting line numbers like grid-column: 1 / 3, you can draw your layout directly in CSS:
.page {
display: grid;
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
grid-template-columns: 160px 1fr;
gap: 10px;
}
Aligning Nested Cards with subgrid
Ever had a row of 3 cards where one card has a 2-line title and its button doesn’t line up with the neighbors? grid-template-rows: subgrid lets child cards inherit the parent grid’s row tracks so every heading, body, and footer aligns perfectly!
Fill-in-the-Blank Exercise
Named Grid Area & Subgrid
Assign the header element to the 'header' area and enable row subgrid on the card.
.top {
: header;
}
.card {
display: grid;
grid-row: span 3;
grid-template-rows: ;
}Try It Yourself
Notice how all three cards keep their headings and buttons aligned even though the middle card has a longer title!
Check Your Understanding
1. What problem does grid-template-rows: subgrid solve for a row of cards?
Finished this lesson?
Your progress is saved locally in your browser, no account needed.