CSS Grid Areas
6 min read Quiz at the end
grid-template-areas defines named layout zones. Place items by name with grid-area. Redefine the template areas in a media query to completely rearrange the layout for different screen sizes very clearly.
Grid Template Areas .layout {
display: grid;
grid-template-columns: 260px 1fr;
grid-template-rows: 64px 1fr 48px;
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
min-height: 100vh;
}
header { grid-area: header; }
.sidebar{ grid-area: sidebar; }
main { grid-area: main; }
footer { grid-area: footer; }
@media (max-width: 768px) {
.layout {
grid-template-columns: 1fr;
grid-template-areas:
"header"
"main"
"footer";
}
.sidebar { display: none; }
}
Topic Quiz · 5 questions
Test your understanding before moving on
1. Grid template areas use:
A. Numbers for positions
B. Named string areas to position items visually
C. CSS classes
D. JavaScript objects
💡 grid-template-areas uses strings of area names to create a visual layout map.
2. A period (.) in grid-template-areas means:
A. Error
B. Decimal value
C. Empty/unnamed cell
D. Class selector
💡 A . (period) in grid-template-areas represents an empty cell.
3. How does a grid item use a named area?
A. class="area-name"
B. grid-area: areaname
C. place-in-area: name
D. grid-place: name
💡 grid-area: name places the item in the matching template area.
4. Can grid-template-areas span multiple rows?
A. No
B. Yes — repeat the area name in multiple rows
C. Only columns
D. Only with JavaScript
💡 Repeating an area name in multiple rows of grid-template-areas spans that area across those rows.
5. What is the main benefit of grid-template-areas?
A. Performance
B. Visual readability — layout visible in CSS code
C. File size
D. Browser support
💡 Named grid areas make the layout intent clear and readable directly in the CSS.
Submit answers