Learn CSS Visually - CSS explained one diagram at a time - flexbox, grid, the box model and more

How Do grid-template-areas Work?

By · Updated

Disclosure: this page contains Amazon affiliate links. As an Amazon Associate we earn from qualifying purchases, at no extra cost to you.

Hey there, grid doodler! grid-template-areas is the one CSS property where you literally type a little map of your page, header across the top, sidebar on the left, and the browser builds exactly what you drew.

Under the hood it’s simple: you type the rows of the grid as quoted strings, and CSS Grid sizes and places everything to match, the closest CSS gets to sketching on a napkin.

If you like having a printed reference on the desk while you practise, the CSS Visual Dictionary paperback on Amazon draws the grid properties as pictures too.

Short answer: grid-template-areas works by turning text into a grid: each quoted string is one row, each word in it is one cell, and repeating a word makes that area span several cells. You set it on the grid container, give each child a matching grid-area name, and use a dot for an empty cell. Every area must be a rectangle.

Diagram of CSS grid-template-areas: three quoted strings, "header header header", "sidebar main ads" and "footer footer footer", map one-to-one onto three grid rows, building a header across the top, a sidebar, main content and an ads column in the middle, and a full-width footer, with grid lines numbered 1 to 4 and the implicit line names main-start and main-end marked around the main area.
Three strings, three rows: each word is a cell, and a repeated word spans cells. The main area’s edges also get the line names main-start and main-end.

What the diagram shows, in plain text:

What does grid-template-areas do?

grid-template-areas names regions of a CSS grid and draws them as text, so the layout is readable right there in the stylesheet. The W3C CSS Grid Layout Module Level 1, the CSS Working Group’s specification, describes it like this:

This property specifies named grid areas, which are not associated with any particular grid item, but can be referenced from the grid-placement properties. The syntax of the grid-template-areas property also provides a visualization of the structure of the grid, making the overall layout of the grid container easier to understand.

That “visualization” part is why MDN Web Docs’ Grid template areas guide says You will see very quickly why we sometimes call this the ascii-art method of grid layout! The facts about the property itself, from the spec’s property table:

Values
none, or one or more quoted strings
Default (initial value)
none — no named areas
Set on
the grid container (the element with display: grid), not on the items
Inherited
no
Animatable
discrete only — a layout swaps from one template to the next with no in-between frames

How do you build a layout with grid-template-areas, step by step?

A grid-template-areas layout takes three steps: draw the areas on the grid container, size the rows and columns, and send each child to its area with grid-area. Here is the header, sidebar, main, ads and footer page from the diagram.

/* 1. draw the areas on the container */
.page {
  display: grid;
  grid-template-areas:
    "header  header header"
    "sidebar main   ads"
    "footer  footer footer";
  /* 2. size the columns and rows */
  grid-template-columns: 200px 1fr 160px;
  grid-template-rows: auto 1fr auto;
  gap: 16px;
  min-height: 100vh;
}

/* 3. send each child to its area */
.page > header { grid-area: header; }
.page > nav    { grid-area: sidebar; }
.page > main   { grid-area: main; }
.page > aside  { grid-area: ads; }
.page > footer { grid-area: footer; }

The extra spaces inside the strings are only there to line the columns up for your eyes; any run of whitespace between names counts as one separator. The 1fr row stretches the middle row so the footer sits at the bottom of a short page.

If you leave out grid-template-rows or grid-template-columns, the spec says the tracks that grid-template-areas creates are sized by grid-auto-rows and grid-auto-columns, which default to auto.

The grid-area property on a grid item connects it to a named area: grid-area: main; puts the item in the area called main. The name has no quotes — grid-area: "main"; is invalid and gets ignored, because grid-area takes a name (a CSS identifier), while grid-template-areas takes strings.

Under the hood, grid-area: main sets all four placement properties (grid-row-start, grid-column-start, grid-row-end, grid-column-end) to main, and the browser finds the lines called main-start and main-end.

How do the strings turn into rows and columns?

In grid-template-areas, every quoted string becomes one row and every word in a string becomes one column. The W3C spec puts it in one sentence: A row is created for every separate string listed for the grid-template-areas property, and a column is created for each cell in the string.

When the same name appears in neighbouring cells, the spec says those cells create a single named grid area that spans the corresponding grid cells — that is how header stretches across all three columns.

So you can count a grid-template-areas grid without running it: 3 strings with 3 words each make a 3 x 3 grid, with 4 column lines and 4 row lines.

Spanning down works the same way as spanning across — write sidebar in the same column of two strings and the sidebar area becomes two rows tall.

Which grid lines does each named area cover?

Each named area in grid-template-areas covers the grid lines around its cells, so every area can also be written as line numbers.

We worked out the line numbers for every area in the page layout above — handy when you need to place one extra item by number, or check what a template really does.

Named areas as line numbers for the template "header header header" "sidebar main ads" "footer footer footer" — worked out by Learn CSS Visually with the W3C CSS Grid Layout Module Level 1 rules, November 12, 2026
AreaSame as grid-area: (row-start / column-start / row-end / column-end)RowsColumnsLine names it creates
header1 / 1 / 2 / 411 to 3header-start (row 1, column 1), header-end (row 2, column 4)
sidebar2 / 1 / 3 / 221sidebar-start (row 2, column 1), sidebar-end (row 3, column 2)
main2 / 2 / 3 / 322main-start (row 2, column 2), main-end (row 3, column 3)
ads2 / 3 / 3 / 423ads-start (row 2, column 3), ads-end (row 3, column 4)
footer3 / 1 / 4 / 431 to 3footer-start (row 3, column 1), footer-end (row 4, column 4)

Reading one row of the table: grid-area: 2 / 2 / 3 / 3 puts an item exactly where grid-area: main would. Our visual guide to CSS Grid explains line numbers if they’re new to you.

How do you leave a cell empty in grid-template-areas?

To leave a cell empty in grid-template-areas, write a dot (.) where a name would go. The W3C spec calls a run of one or more dots a null cell token, and it represents an unnamed area in the grid container.

.page {
  display: grid;
  grid-template-areas:
    "header header header"
    "sidebar main  main"
    ".      footer footer";   /* nothing under the sidebar */
}

Several dots in a row with no space between them, like ..., still count as one empty cell, which helps line up the columns. Dots separated by spaces, like . . ., are three empty cells.

Why is grid-template-areas not working?

grid-template-areas usually stops working because the value is invalid, and an invalid value is thrown away whole.

MDN says it plainly: The value of grid-template-areas must show a complete grid, otherwise it is invalid (and the property is ignored). Check these six things, in this order:

  1. Every row has the same number of cells. The spec: All strings must define the same number of cell tokens. Count the words (and dots) in each string.
  2. Every area is a rectangle. An L-shape, or one name in two places that don’t touch, makes the whole declaration invalid.
  3. No stray characters. Names can use letters, digits, hyphens and underscores. Anything else inside the strings (like #, / or a comma) is a trash token, which is a syntax error, and makes the declaration invalid. Also, put no commas between the strings.
  4. The container has display: grid, and the items are its direct children — grid-area on a grandchild does nothing.
  5. The names match exactly. grid-area: sidebar and "side-bar" are different names, and names are case-sensitive.
  6. grid-area has no quotes. Write grid-area: main;, not grid-area: "main";.

The fastest check: open DevTools, select the container and look at its styles. An invalid grid-template-areas line shows up struck through with a warning icon.

Which grid-template-areas values are valid and which are invalid?

A grid-template-areas value is valid only when every row has the same number of cells, every name forms one filled-in rectangle, and nothing but names, dots and spaces appears in the strings. We ran nine example templates through the spec’s rules:

Four mini grids testing grid-template-areas values: "a a b" / "a a b" is valid because a is a 2 by 2 rectangle and b a 1 by 2 column; "a a b" / "a c c" is invalid because area a forms an L-shape; "a a b" / "c c" is invalid because the rows have 3 and 2 cells; and "a b a" / "c c c" is invalid because the two a cells are split apart.
One rectangle that works and three common mistakes. Any one of them makes the browser ignore the whole grid-template-areas value.
Nine grid-template-areas values checked against the W3C CSS Grid Layout Module Level 1 rules (tokens, same cell count, rectangles) — compiled by Learn CSS Visually, November 12, 2026
ValueResultWhy
"a a b" "a a b"valid3 cells per row; a is a 2 x 2 rectangle, b a 1 x 2 column
"a a b" "a c c"invalida covers 3 cells in an L-shape, not a rectangle
"a a b" "c c"invalidrow 1 has 3 cells, row 2 has 2
"a b a" "c c c"invalidthe two a cells are not connected
"a . b" "a . b"validthe dot is an empty cell, so each row still has 3 cells
"a ... b" "a ... b"valid... with no spaces is one empty cell, not three
"a.b" "a.b"valid, but hard to readthe dot splits the string into 3 cells: a, empty, b
"nav #main" "nav #main"invalid# is a trash token (a syntax error)
"1st 2nd" "1st 2nd"validthe areas exist, but other properties must escape the name: grid-area: \31st

What the picture shows, in plain text: "a a b" "a a b" is valid (a rectangle and a column).

"a a b" "a c c" is invalid (an L-shape); "a a b" "c c" is invalid (3 cells, then 2); "a b a" "c c c" is invalid (a split area).

Can a grid area be L-shaped?

No — a grid area made with grid-template-areas must be a rectangle, so L-shapes and split areas are invalid.

The W3C spec says that if a named area’s cells do not form a single filled-in rectangle, the declaration is invalid, and adds that Non-rectangular or disconnected regions may be permitted in a future version of this module.

For now, split an L-shape into two areas with different names (for example main and main-wide) and place two elements, or let one element span with line numbers and put another on top.

What happens if grid-area uses a name that doesn’t exist?

If grid-area names an area that grid-template-areas never defined, the item doesn’t vanish — it ends up outside your layout.

The W3C rule: the browser first looks for lines called name-start and name-end; when none exist, all implicit grid lines are assumed to have that name, so the item lands in extra rows and columns the browser adds after the explicit grid, usually at the bottom right.

If one box suddenly sits in a strange new corner, look for a typo in its grid-area name.

How do you make grid-template-areas responsive?

To make grid-template-areas responsive, keep the grid-area names on the items and redraw only the template inside a media query. MDN’s advice: define the names for your areas outside of any media queries.

Real talk: there is a special kind of puzzled when a whole layout quietly vanishes because one row has two words instead of three. That is why counting the words in each string is the very first thing worth checking — it saves so much head-scratching.

Then the item called main stays main on every screen size, wherever you put it. Here’s a mobile-first version of the page: one column on phones, three columns from 700px wide.

.page {
  display: grid;
  gap: 16px;
  grid-template-areas:
    "header"
    "main"
    "sidebar"
    "ads"
    "footer";
}

@media (min-width: 700px) {
  .page {
    grid-template-columns: 200px 1fr 160px;
    grid-template-areas:
      "header  header header"
      "sidebar main   ads"
      "footer  footer footer";
  }
}

Nothing on the items changes between the two layouts — only five lines on the container.

Does moving areas around change the reading order?

No — moving areas with grid-template-areas changes only what people see, not the order screen readers read or the order the Tab key follows; both still follow the HTML source.

The W3C spec is firm about it: Authors must use order and the grid-placement properties only for visual, not logical, reordering of content.

What are header-start and header-end?

header-start and header-end are line names that grid-template-areas creates for you, one pair for every named area.

The W3C spec: For each named grid area foo, four implicitly-assigned line names are created: two named foo-start, naming the row-start and column-start lines of the named grid area, and two named foo-end, naming the row-end and column-end lines of the named grid area.

You can use them to place an item that spans from one area into another:

/* a banner from the left edge of main to the right edge of ads */
.promo {
  grid-row: footer;                /* the footer's row */
  grid-column: main-start / ads-end;
}

It also works the other way round: if you name lines hero-start and hero-end yourself in grid-template-columns and grid-template-rows, the spec says that effectively creates a named grid area, so grid-area: hero works without any grid-template-areas at all.

How does the grid-template shorthand set areas, rows and columns together?

The grid-template shorthand sets grid-template-areas, grid-template-rows and grid-template-columns in one declaration, with each row’s size written right after its string and the column sizes after a slash:

.page {
  display: grid;
  grid-template:
    "header  header header" auto
    "sidebar main   ads"    1fr
    "footer  footer footer" auto
    / 200px  1fr    160px;
}

Two catches from the W3C spec. First, repeat() isn’t allowed in this form, as the tracks are intended to visually line up one-to-one with the rows/columns in the “ASCII art”.

Second, the spec recommends the bigger grid shorthand over grid-template, because grid also resets the implicit-grid properties (grid-auto-rows, grid-auto-columns, grid-auto-flow). Both take the same syntax shown here.

Can two items share the same grid area?

Yes — two items can share one grid area, and they simply overlap, which makes grid-template-areas a neat way to put text on top of an image without position: absolute.

The W3C spec says grid items can overlap when they are positioned into intersecting grid areas; the one that comes later in the HTML paints on top, and z-index works on grid items even without position.

.hero {
  display: grid;
  grid-template-areas: "stack";
}
.hero > img,
.hero > h1 { grid-area: stack; }
.hero > h1 { align-self: end; padding: 24px; }

Our flexbox vs Grid guide lists this overlap trick among the jobs Grid does better than flexbox.

Does grid-template-areas work in every browser?

Yes — grid-template-areas works in every current browser, since it arrived with CSS Grid itself in 2017. MDN’s browser-compat-data, read on November 12, 2026, lists it from these versions:

Chrome
57
Edge
16
Firefox
52
Safari
10.1
Global support
97.39% of users worldwide for CSS Grid, according to Can I use (data updated November 11, 2026)

To see your areas on the page, both big browsers can label them. In Chrome’s Layout pane, the Chrome DevTools documentation describes a Show area names checkbox to show or hide area names, in the case of grids with named grid areas.

Firefox’s Grid Inspector has Display area names, turned on by default for grids with named areas.

Go sketch your favourite site as three or four quoted strings, paste them into a grid container, and then flip it to one column inside a media query. Watching the whole page rearrange from five lines of CSS never stops being fun.

Sources and further reading

Questions and answers

What is the difference between grid-area and grid-template-areas?

grid-template-areas goes on the grid container and draws the named areas as strings. grid-area goes on each child and says which area it fills, for example grid-area: main. grid-area can also take line numbers instead of a name, like grid-area: 2 / 2 / 3 / 3.

Do grid-template-areas names need quotes?

In grid-template-areas, each row must be a quoted string, like "header header". In grid-area the name has no quotes: grid-area: header. Writing grid-area: "header" is invalid and the browser ignores it.

How do you leave an empty cell in grid-template-areas?

Put a dot (.) where the name would go, for example ". footer footer". One or more dots with no space between them count as one empty cell, so … also works and can help line up columns.

Can you use repeat() with grid-template-areas?

No. grid-template-areas only takes quoted strings, so every cell is written out. You can still size the columns with repeat() in grid-template-columns; only the grid-template shorthand form that includes the strings forbids repeat(), per the W3C Grid specification.

Why is my grid-template-areas being ignored?

The value is probably invalid, and an invalid value is thrown away whole. Check that every string has the same number of cells, every area is a rectangle, there are no characters other than names, dots and spaces, and the container has display: grid.

How this was written: Written from the W3C CSS Grid Layout Module Level 1 (Candidate Recommendation Draft, 26 March 2025), MDN Web Docs’ grid-template-areas reference and Grid template areas guide, MDN’s browser-compat-data, the Can I use support data (updated November 11, 2026) and the Chrome and Firefox DevTools documentation, all read on November 12, 2026. The line-number map and the validity table are our own work, done by applying the specification’s rules to each example. Code samples are simplified for learning.

Oh, one more thing…

If this helped, you’ll like our free updates: the insights we discover while researching, and the moments worth sharing with other people learning CSS — no spam, no promotions.

One short email when there’s something worth your time. Unsubscribe any time.