CSS Grid Template Areas: Named Grid Areas Explained
CSS grid-template-areas with measured box positions in Chrome 157 for three layouts, plus error cases: non-rectangular areas, uneven rows, wrong case and tab order.
On this page ⌄
grid-template-areas lets you draw a layout as text, then place elements by name. It also fails quietly: one wrong row and the whole property is dropped with no error shown, and every named item falls out of the grid. This guide covers the syntax, then three layouts with the box positions Chrome 157 computed for them, then the error cases. Use the CSS Grid Generator for the track sizes; it outputs grid-template-columns, grid-template-rows, gap and alignment, and you add the areas by hand.
What the rules are
Each quoted string is a row, and each word in it is a cell. The CSS Grid Layout Module Level 1 (section 7.3, W3C Candidate Recommendation Draft of 26 March 2025) says all strings must define the same number of cell tokens, with at least one, or the declaration is invalid; a null cell token represents an unnamed area; if the cells of a name "do not form a single filled-in rectangle" the declaration is invalid; and none defines no named areas. For each named area foo the browser also creates four implicit line names, foo-start and foo-end on each axis. MDN describes a null cell token as one or more . characters and lists the property as widely available across browsers since October 2017.
.container {
display: grid;
grid-template-columns: 200px 1fr;
grid-template-rows: 60px 1fr 50px;
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
}
.header { grid-area: header; }
.sidebar { grid-area: sidebar; }
.main { grid-area: main; }
.footer { grid-area: footer; }
grid-area: header then places an element on the whole named region. Empty cells use a dot, and a run of dots counts as one cell: in Chrome 157, "a . .." "b b b" was kept and the computed value came back as "a . ." "b b b".
Three layouts, measured
Each layout below was built in Chrome 157 and every item's box was read with getBoundingClientRect, shown as x,y width x height relative to the container.
Layout 1: page with header, nav, content, aside and footer
.c {
display: grid; gap: 10px; width: 1000px; height: 600px;
grid-template-columns: 200px 1fr 240px;
grid-template-rows: 64px 1fr 48px;
grid-template-areas:
"header header header"
"nav main aside"
"footer footer footer";
}
| item | box |
|---|---|
| header | 0,0 1000x64 |
| nav | 0,74 200x468 |
| main | 210,74 540x468 |
| aside | 760,74 240x468 |
| footer | 0,552 1000x48 |
The middle row is 600 - 64 - 48 - 2 x 10 = 468 px tall, and main is 1000 - 200 - 240 - 2 x 10 = 540 px wide, as the table shows. A spanning area is one box: header covers three columns and the two gaps between them are inside it.
Layout 2: dashboard with a tall tile and an empty cell
.c {
display: grid; gap: 12px; width: 900px;
grid-template-columns: repeat(3, 1fr);
grid-auto-rows: 100px;
grid-template-areas:
"stats stats chart"
"list . chart"
"list feed feed";
}
| item | box |
|---|---|
| stats | 0,0 596x100 |
| chart | 608,0 292x212 |
| list | 0,112 292x212 |
| feed | 304,224 596x100 |
Nothing is drawn in the dot cell, but it still exists: an extra item placed with grid-column: 2; grid-row: 2 measured 304,112 292x100, exactly the size of the empty cell (292 px wide, 100 px tall) between list, chart, stats and feed. Here grid-auto-rows: 100px supplies the row heights because the template names rows but gives them no sizes. A two-row area is 2 x 100 + 12 = 212 px tall.
Layout 3: the same page, remapped by media query
You change the area map and the tracks; the placements stay put. Mobile first, three breakpoints:
.page {
display: grid;
gap: 16px;
grid-template-columns: 1fr;
grid-template-areas: "header" "nav" "content" "aside" "footer";
}
@media (min-width: 768px) {
.page {
grid-template-columns: 220px 1fr;
grid-template-rows: 64px 1fr auto;
grid-template-areas: "header header" "nav content" "footer footer";
}
aside { display: none; } /* the area is not in the map at this width */
}
@media (min-width: 1200px) {
.page {
grid-template-columns: 220px 1fr 280px;
grid-template-areas: "header header header" "nav content aside" "footer footer footer";
}
aside { display: block; }
}
With fixed heights of 64 px (header), 40 px (nav), 200 px (main), 80 px (aside) and 48 px (footer) set on the elements, the boxes at three viewport widths were:
| viewport | header | nav | main | aside | footer |
|---|---|---|---|---|---|
| 600 | 0,0 600x64 | 0,80 600x40 | 0,136 600x200 | 0,352 600x80 | 0,448 600x48 |
| 900 | 0,0 900x64 | 0,80 220x40 | 236,80 664x200 | hidden | 0,296 900x48 |
| 1300 | 0,0 1300x64 | 0,80 220x40 | 236,80 768x200 | 1020,80 280x80 | 0,296 1300x48 |
The display: none on aside at 768px matters. An element whose area name is missing from the map is not hidden; it is placed outside the explicit grid, as the failing cases below show.
What happens when the syntax is wrong
Each value was set on a grid container with element.style.gridTemplateAreas, and the check was whether Chrome kept it. A rejected value means the declaration is ignored as if you had not written it:
| value | kept? | note |
|---|---|---|
"a a b" "c c b" | yes | valid, areas are rectangles |
"a a" "a b" | no | a is an L-shape, not a rectangle |
"a . a" "b b b" | no | a appears in two separate places |
"a b" "b a" | no | two diagonal pairs are not rectangles |
"a a" "b" | no | rows have 2 and 1 cells |
"a a" "" | no | an empty row string |
a a; b c (no quotes) | no | each row needs its own quoted string |
"a a b c" | yes | one row of four cells; legal, easy to write by accident |
"a . .." "b b b" | yes | a run of dots is one empty cell |
"a a" "a a" | yes | one area a covering a 2 x 2 block |
". ." | yes | a grid of two empty cells is allowed |
none | yes | no named areas |
"1a 1a", "side-bar main", "col2 col2" | yes | digit-first and hyphenated names were accepted |
Rule: every named area must form one rectangle, and every row must have the same number of cells. A bad area is not an error either: if a row fails, grid-area: a points at a name that does not exist.
What the layout does when it fails
Take a container with three explicit 100px columns and grid-auto-rows: 50px, and three items with grid-area: a, b and c. With the valid value "a a b" "c c b" the boxes were a: 0,0 200x50, b: 200,0 100x100 and c: 0,50 200x50. With the L-shaped value "a a" "a b", and again with the uneven value "a a" "b", all three items measured 300,50 0x50: they stacked on each other in a zero-width implicit column to the right of the explicit grid, in the second row. Nothing warns you.
Two more traps from the same run:
- Names are case sensitive. With
"A A b" "c c b"and an element usinggrid-area: a, that element left the grid and measured300,150 0x50, whileb(200,0 100x100) andc(0,50 200x50) were placed correctly. - A
grid-areaname that no area defines does not raise an error.grid-area: zzzmeasured300,150 0x50, outside the explicit grid. MDN'sgrid-areapage says an unmatched custom identifier is treated as if the integer 1 had been specified along with it, and that implicit lines are then assumed to have that name, which fits the placement outside the explicit grid seen here.
When "nothing is where it was put", check these three things in order: row cell counts, rectangles, and name spelling and case.
More rows than grid-template-rows
If you list three area rows but only one row size, the grid still has three rows: grid-template-rows: 40px with three area rows and grid-auto-rows: 70px gave row heights 40px 70px 70px. The explicit size covers the first row only.
Page layout with generator output
Set the generator to columns 220px 1fr 280px, rows 64px 1fr auto, gap 16. It outputs:
.grid {
display: grid;
grid-template-columns: 220px 1fr 280px;
grid-template-rows: 64px 1fr auto;
gap: 16px;
justify-items: stretch;
align-items: stretch;
}
Add the areas and the placements:
.page {
display: grid;
min-height: 100vh;
gap: 16px;
grid-template-columns: 220px 1fr 280px;
grid-template-rows: 64px 1fr auto;
grid-template-areas:
"header header header"
"nav content aside"
"footer footer footer";
}
header { grid-area: header; }
nav { grid-area: nav; }
main { grid-area: content; }
aside { grid-area: aside; }
footer { grid-area: footer; }
Placing items with grid-area and named lines
grid-area also takes four values, in the order row-start, column-start, row-end, column-end, which MDN documents. In a 3 x 3 grid of 100px columns and 50px rows, grid-area: 2 / 1 / 4 / 3 measured 0,50 200x100: from row line 2 to row line 4, and from column line 1 to column line 3.
Every area creates lines called name-start and name-end on both axes. In a grid with "header header" "sidebar main", columns 100px 1fr and rows 40px 80px in a 900px container:
.overlay { grid-column: sidebar-start / main-end; grid-row: header-end / -1; }
measured 0,40 900x80: from the start of the sidebar column to the end of the main column, starting at the bottom of the header and running to the last line. Another element with grid-column: main-start; grid-row: header-start / header-end measured 100,0 800x40. This is the easy way to span or overlay things without defining more template areas.
Two items given the same area do not push each other aside: with "a b" and two items using grid-area: b, both measured 100,0 200x50 and drew on top of each other. Use it for deliberate overlays, and watch for it when a copy-pasted class repeats an area name.
Reading order and accessibility
Areas change where an item is drawn, not where it sits in the DOM. With <main> before <nav> in the HTML and grid-template-areas: "nav main", Tab order followed the HTML: first the link in main (at x=208), then the link in nav (at x=8). The keyboard focus ring jumped right to left. Screen reader behaviour was not tested. Keep DOM order and visual order the same, or reorder the HTML.
Chrome 157 also accepts reading-flow: grid-rows on the grid container, and with it the Tab order followed the visual order (n at x=8, then m at x=208). MDN marks reading-flow as experimental and not Baseline ("Limited availability"), so treat it as an enhancement, not a fix, and do not rely on it in other browsers (not tested).
Shorthand
grid-template combines rows, areas and columns in one declaration:
.container {
grid-template:
"header header" 60px
"sidebar main" 1fr
"footer footer" 50px
/ 200px 1fr;
}
Tested
2026-11-19, Chrome 157.0.8103.78 via playwright-core on Windows 11, 1300 x 800 viewport unless stated. Validity came from checking whether element.style.gridTemplateAreas kept the value; positions from getBoundingClientRect relative to the container; tab order from real Tab key presses in a fresh page per case. The .c and .page boxes use fixed pixel sizes so the arithmetic can be checked. Not tested: Firefox and Safari, right-to-left layouts, and grid-template-areas with subgrid.
Sources
- W3C: CSS Grid Layout Module Level 1, section 7.3: cell token counts, null cells, the rectangle rule,
none, implicit-startand-endlines (Candidate Recommendation Draft, 26 March 2025). - MDN: grid-template-areas: syntax, null cell tokens, rectangle rule, Baseline status.
- MDN: grid-area: four-value order and the handling of unmatched custom identifiers.
- MDN: reading-flow: what it changes and its limited availability.
Keep reading
Related tools
CSS Grid Generator
Visual CSS Grid layout builder. Configure columns, rows, gaps, and named areas. Live preview with copyable CSS output.
WebP to JPG Converter
Convert WebP to JPG, PNG or WebP in your browser. Batch files, set quality, pick a background for transparency. Nothing is uploaded.
Image Compressor
Compress JPEG, PNG, and WebP images in your browser. Adjustable quality, batch mode. Files never leave your device.
Color Picker
Pick colors, convert hex/RGB/HSL/OKLCH, and check WCAG contrast.
Written by Mian Ali Khalid. More guides in Frontend & Design.