LESSON 21
Grid Layouts
Learning objective: Build responsive page layouts with Grid.
Understand
Grid can define an entire page structure.
grid-template-areas lets you name regions and place items by name, making complex layouts readable. Combined with auto-fit and minmax(), grids become responsive without media queries.
Analogy: Named grid areas are like a floor plan labelling each room's place.
See It in Action
A responsive auto-fitting grid:
.cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 16px;
}How it works:
auto-fit with minmax(200px, 1fr) fits as many 200px+ columns as possible, then stretches them — responsive by itself.Try It Yourself
- Use
repeat(auto-fit, minmax(...))for a card grid. - Resize and watch columns adjust.
- Try naming areas with grid-template-areas.
Quick Quiz
What makes auto-fit + minmax responsive?
Challenge
Build a card layout that changes its column count automatically as the screen resizes.
Success condition: Your grid adds or removes columns as the window resizes, without media queries.
+10 XP
Lesson Complete
You answered correctly and completed the required practice. Your progress has been saved on this device.
Continue to next lesson →