Named Grid Areas
What you'll learn: How to create and use named regions in CSS Grid to place items intuitively without counting grid lines.
What Are Named Grid Areas?
Named grid areas let you define labeled regions of your grid using grid-template-areas, then assign items to those regions by name. Instead of tracking line numbers, you literally draw a text-based map of your layout.
Think of it like assigning names to rooms in a floor plan. Rather than saying "the kitchen is between walls 3 and 5," you just label that space "kitchen" and place furniture there by referencing the name.
Defining Areas with grid-template-areas
On the grid container, use grid-template-areas with a string for each row. Each word represents one cell:
.container {
display: grid;
grid-template-columns: 200px 1fr 200px;
grid-template-rows: auto 1fr auto;
grid-template-areas:
"header header header"
"sidebar content aside"
"footer footer footer";
}
Each quoted string is one row. Repeating a name makes that area span multiple cells.
Placing Items into Named Areas
On grid items, use the grid-area property with the region name:
.header { grid-area: header; }
.sidebar { grid-area: sidebar; }
.content { grid-area: content; }
.aside { grid-area: aside; }
.footer { grid-area: footer; }
The item automatically fills the entire named region — no line numbers needed!
Empty Cells
Use a period (.) for cells you want to leave empty:
grid-template-areas:
"logo . login"
"nav nav nav";
Key Takeaway: Named grid areas let you create semantic, visual grid layouts using grid-template-areas on the container and grid-area on items, making complex layouts readable and maintainable.