Xerobit
Frontend & Design

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.

MA Mian Ali Khalid Updated Nov 19, 2026 9 min read
Free tool
CSS Grid Generator
Visual CSS Grid layout builder. Configure columns, rows, gaps, and named areas. Live preview with copyable CSS output.
Open tool →
On this page ⌄
  1. What the rules are
  2. Three layouts, measured
  3. What happens when the syntax is wrong
  4. Page layout with generator output
  5. Placing items with grid-area and named lines
  6. Reading order and accessibility
  7. Shorthand
  8. Tested
  9. Sources

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.

.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";
}
itembox
header0,0 1000x64
nav0,74 200x468
main210,74 540x468
aside760,74 240x468
footer0,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";
}
itembox
stats0,0 596x100
chart608,0 292x212
list0,112 292x212
feed304,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:

viewportheadernavmainasidefooter
6000,0 600x640,80 600x400,136 600x2000,352 600x800,448 600x48
9000,0 900x640,80 220x40236,80 664x200hidden0,296 900x48
13000,0 1300x640,80 220x40236,80 768x2001020,80 280x800,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:

valuekept?note
"a a b" "c c b"yesvalid, areas are rectangles
"a a" "a b"noa is an L-shape, not a rectangle
"a . a" "b b b"noa appears in two separate places
"a b" "b a"notwo diagonal pairs are not rectangles
"a a" "b"norows have 2 and 1 cells
"a a" ""noan empty row string
a a; b c (no quotes)noeach row needs its own quoted string
"a a b c"yesone row of four cells; legal, easy to write by accident
"a . .." "b b b"yesa run of dots is one empty cell
"a a" "a a"yesone area a covering a 2 x 2 block
". ."yesa grid of two empty cells is allowed
noneyesno named areas
"1a 1a", "side-bar main", "col2 col2"yesdigit-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 using grid-area: a, that element left the grid and measured 300,150 0x50, while b (200,0 100x100) and c (0,50 200x50) were placed correctly.
  • A grid-area name that no area defines does not raise an error. grid-area: zzz measured 300,150 0x50, outside the explicit grid. MDN's grid-area page 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

Keep reading

Related tools

Written by Mian Ali Khalid. More guides in Frontend & Design.