Tracking down cryptic grid column and row numbers across multiple media queries creates fragile, hard-to-maintain frontend architecture. Switching to the grid-template-areas property solves this by replacing invisible coordinates with a visual, ASCII-style map directly inside your CSS. This approach transforms complex responsive shifts into instantly readable code.
- Browser Support: Widely supported (Chrome 57+, Safari 10+, Edge 16+, Firefox 52+)
- Default Value:
none - Applies To: Grid containers (
display: grid) - Prerequisite: Child elements must have assigned
grid-areanames
The Visual Power of Named Grid Areas
CSS Grid usually forces you to think in terms of start and end lines. When layouts get complex, keeping track of grid-column: 1 / 3 or grid-row: 2 / 5 becomes a heavy cognitive load.
Named grid areas flip this logic entirely. You name your layout components first, then arrange those names into a string that literally looks like the layout you want to build. Anyone looking at your stylesheet instantly understands the page structure without needing to inspect the HTML or open the browser dev tools.

Basic Syntax: Defining Your Grid
To use this layout method, you need two things: a parent container with the template map, and child elements tagged with corresponding names. You define the map using strings, where each string represents a row, and each word inside the string represents a column cell.
Assigning grid-area to Child Elements
Before mapping the layout, tell CSS which element corresponds to which name. You do this using the grid-area property on the child elements. The names you choose do not need quotes.
.site-header { grid-area: header; }
.site-nav { grid-area: sidebar; }
.site-main { grid-area: content; }
.site-footer { grid-area: footer; }
Once your elements have their tags, you arrange them in the parent container. Repeating a name across multiple cells merges those cells into a single, larger area.
.container {
display: grid;
grid-template-columns: 250px 1fr;
grid-template-rows: 60px 1fr 40px;
grid-template-areas:
"header header"
"sidebar content"
"footer footer";
}
Creating Empty Cells with Dots
Sometimes you need empty space in your grid design. You can create unnamed, empty cells by using a period (.) or a sequence of periods (like ...).
This is incredibly useful for asymmetrical layouts or floating elements. Just ensure the dots are separated from your named areas by a space.
.hero-section {
display: grid;
grid-template-areas:
"image text text"
"image . ."
"image button .";
}
Real-World Example: Responsive Dashboard Layout
To see the real power of grid-template-areas, look at how it handles responsive design. Let's build a standard admin dashboard. It needs a top header, a left sidebar for navigation, a main content area, and a footer.
Desktop View Configuration
On wide screens, the sidebar sits on the left, spanning the middle and bottom rows. The header spans the entire top row.
.dashboard {
display: grid;
min-height: 100vh;
grid-template-columns: 250px 1fr;
grid-template-rows: auto 1fr auto;
grid-template-areas:
"header header"
"sidebar main"
"sidebar footer";
}
Mobile Stacking with Media Queries
When the screen size drops, line-based grids require you to manually redefine start and end points for every single element. With grid-template-areas, you leave the child elements completely alone. You only rewrite the visual map on the parent container.
@media (max-width: 768px) {
.dashboard {
grid-template-columns: 1fr;
grid-template-rows: auto auto 1fr auto;
grid-template-areas:
"header"
"sidebar"
"main"
"footer";
}
}
The layout instantly stacks vertically. You achieve a complete structural overhaul just by changing four lines of highly readable text.
Common Mistakes and Invalid Grids
Even though the syntax is forgiving, a few strict rules dictate whether your grid map will render or completely break.
- Non-rectangular areas: a named area must form a perfect rectangle. You cannot create "L" or "T" shaped areas. If you try to wrap a sidebar under the main content using the same name, the entire declaration becomes invalid.
- Mismatched columns: every row string must contain the exact same number of cells (words or dots). If row one has three columns, row two must also have three columns.
- Missing quotes: each row must be wrapped in its own set of quotation marks.
grid-template-areas vs. Line Numbers
Choosing between named areas and numerical lines depends on the specific needs of your UI component, and often comes down to the same Grid vs. Flexbox tradeoffs you weigh at the macro-layout level.
| Feature | grid-template-areas | Numerical Placement (grid-column / grid-row) |
|---|---|---|
| Readability | High. The CSS visually mirrors the final layout. | Low. Requires mental math to visualize the grid. |
| Maintenance | Easy. Rearrange the entire layout in one parent block. | Hard. Requires updating values on every individual child element. |
| Overlapping Elements | Not supported. Areas cannot overlap each other. | Fully supported. Multiple elements can share the same numerical tracks. |
| Complex/Dynamic Grids | Limited. Best for high-level macro layouts (page shells). | Ideal. Better for dense micro-layouts and auto-placement algorithms. |
