If you have ever counted grid lines on your fingers to place a sidebar, grid-template-areas is the property that ends that pain. Instead of positioning items with numeric line references, you draw the page in your stylesheet with names and let each element claim its spot. This checklist walks through the whole process, from naming areas to redefining them in media queries, with a complete header / sidebar / main / footer example and the mistakes that silently break the layout.
Quick answer: what does grid-template-areas do?
grid-template-areas lets you define a grid as a series of quoted strings, where each string is a row and each word inside it is a cell occupied by a named area. Any grid item that declares grid-area: header is then placed into every cell carrying the name header, and repeating a name across cells makes that area span those columns or rows. In short: the property maps a human readable ASCII drawing of your layout onto the real grid tracks defined by grid-template-columns and grid-template-rows.

The checklist at a glance
- Sketch the layout and give every region a short name.
- Create the grid container and define the column and row tracks.
- Write the
grid-template-areasstrings, one quoted string per row. - Check that every area forms a perfect rectangle.
- Check that every string has the same number of cells.
- Assign
grid-area: nameto each child element. - Use a dot for cells that must stay empty.
- Redefine the areas inside media queries for other screen sizes.
- Verify names, spelling and DOM order before shipping.
Step 1: Name the areas before you write CSS
Area names are custom identifiers, so pick names that describe the role of the block, not its look. sidebar, main, footer and hero age far better than left, right or box2, because a left sidebar on desktop often becomes a bottom block on mobile. Much the same conclusion turns up on cssreference.io.
- Names are case sensitive:
Mainandmainare two different areas. - Do not wrap names in quotes individually, do not use commas between them, and do not use the reserved word
span. - Avoid names starting with a digit and avoid spaces inside a name.
- Keep names short: you will be aligning them visually in a text block.
Bonus: each named area creates named lines
Declaring an area called main automatically creates the implicit lines main-start and main-end on both axes. That means another element can be positioned with grid-column: main-start / main-end without being part of the template at all. It is a handy escape hatch for overlays and full bleed backgrounds.

Step 2: Create the container and the tracks
grid-template-areas does not create tracks by itself in the sense of sizing them. It creates the cells, but without track sizes every column would be auto sized. Always pair it with grid-template-columns and, when the vertical rhythm matters, grid-template-rows.
.layout {
display: grid;
grid-template-columns: 240px 1fr;
grid-template-rows: auto 1fr auto;
gap: 16px;
min-height: 100vh;
}
Here 1fr gives the main column all the leftover space and auto lets the header and footer rows take the height of their content, while the middle row stretches.
Step 3: Write the strings, one per row
Each quoted string is a row of the grid. Extra whitespace inside a string is ignored, so align the names in columns to keep the drawing readable.
.layout {
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
}
Two golden rules apply to every template:
- Every string must contain the same number of cell tokens as there are columns. Three columns means three tokens per string, every time.
- Every named area must form a rectangle. L shapes, T shapes and staircases are invalid and the whole declaration is discarded.
Valid vs invalid shapes
/* Valid: "nav" is a 2x1 rectangle */
grid-template-areas:
"nav nav main"
"side side main";
/* Invalid: "nav" forms an L shape */
grid-template-areas:
"nav nav main"
"nav side side";
Step 4: Assign grid-area to each child
Placement happens on the items, not the container. One line per child is enough.
.site-header { grid-area: header; }
.site-sidebar { grid-area: sidebar; }
.site-main { grid-area: main; }
.site-footer { grid-area: footer; }
When grid-area receives a single identifier, the browser applies that name to all four placement properties (grid-row-start, grid-column-start, grid-row-end, grid-column-end). The same shorthand also accepts four slash separated line numbers, for example grid-area: 1 / 1 / 2 / 3, which is the numeric approach that template areas are designed to replace.

Step 5: Leave cells empty with a dot
A cell that should stay empty is written as a single period, or as a run of periods with no spaces inside.
grid-template-areas:
"header header header"
"sidebar main ."
"footer footer footer";
Notes worth remembering:
.and....both mean one empty cell. Dots glued together form a single null token.. .with a space means two empty cells.- Empty cells still occupy space. The track still exists and still has a size.
- An auto placed item with no
grid-areacan land in those empty cells, so give every child an explicit area if you want the gap to stay a gap.
Step 6: Redefine the areas in media queries
This is where the property really pays off. You do not move elements, you redraw the map. Start mobile first with a single column, then switch to the two column layout on wider screens.
.layout {
display: grid;
gap: 16px;
grid-template-columns: 1fr;
grid-template-areas:
"header"
"main"
"sidebar"
"footer";
}
@media (min-width: 48rem) {
.layout {
grid-template-columns: 240px 1fr;
grid-template-rows: auto 1fr auto;
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
}
}
@media (min-width: 80rem) {
.layout {
grid-template-columns: 260px 1fr 320px;
grid-template-areas:
"header header header"
"sidebar main aside"
"footer footer footer";
}
}
Two practical points: the number of area names per string must match the number of columns in that same rule, and an element whose area name is not present in the active template becomes an auto placed item and may appear in an unexpected row. Either keep the name in every breakpoint or hide the element explicitly.
Container queries instead of media queries
If the component must adapt to its own box rather than the viewport, the same redefinition works inside a container query. The syntax of the areas does not change at all. quackit.com published something useful on the subject.
.card-wrapper { container-type: inline-size; }
@container (min-width: 40rem) {
.card {
grid-template-columns: 1fr 2fr;
grid-template-areas:
"media body"
"media actions";
}
}

Step 7: Final checks before shipping
- Open the browser devtools grid inspector and switch on area name overlays. Chrome, Firefox and Safari all display the names directly on the page.
- Confirm the visual order still makes sense for keyboard users. Grid can reorder blocks visually, but the tab order and the screen reader order follow the DOM. If the two disagree, fix the HTML order rather than the CSS.
- Check that no stray item has been auto placed into a row you did not plan.
- Test one very long word or a wide table inside
mainto confirm your1frcolumn does not blow out.minmax(0, 1fr)solves most overflow surprises.
The full example, copy and paste
<div class="layout">
<header class="site-header">Header</header>
<nav class="site-sidebar">Sidebar</nav>
<main class="site-main">Main content</main>
<footer class="site-footer">Footer</footer>
</div>
.layout {
display: grid;
gap: 16px;
min-height: 100vh;
grid-template-columns: 1fr;
grid-template-areas:
"header"
"main"
"sidebar"
"footer";
}
@media (min-width: 48rem) {
.layout {
grid-template-columns: 240px minmax(0, 1fr);
grid-template-rows: auto 1fr auto;
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
}
}
.site-header { grid-area: header; }
.site-sidebar { grid-area: sidebar; }
.site-main { grid-area: main; }
.site-footer { grid-area: footer; }
The grid-template shorthand
If you prefer to keep rows, columns and areas in a single declaration, grid-template accepts the row size after each string and the column sizes after a slash:
.layout {
display: grid;
grid-template:
"header header" auto
"sidebar main" 1fr
"footer footer" auto
/ 240px minmax(0, 1fr);
}
It is compact and the sizes sit right next to the drawing. The downside is that it resets the row and column definitions every time you redeclare it, so be deliberate when using it inside media queries.
Common mistakes and how to spot them
| Mistake | What you see | Fix |
|---|---|---|
| Non rectangular area (L or T shape) | The whole declaration is invalid and items fall back to auto placement | Split the region into two rectangles, or nest a second grid |
| Strings with a different number of tokens | Declaration ignored, layout collapses to one column | Count the names in every string, they must all match the column count |
Typo in a name (sidbar vs sidebar) |
One block drops to the end of the grid in a new implicit row | Use the devtools grid overlay, or copy and paste names instead of retyping |
| Missing quotes, or one quote per word | Property invalid, nothing is placed | One pair of quotes per row, no commas anywhere |
Quoting the name in grid-area |
Item is not placed | Write grid-area: main; with no quotes |
| Area name used in the desktop template only | The element reappears in a random place on mobile | Include the name in every breakpoint or hide the element |
| Expecting dots to remove the track | An empty column still takes its full width | Change the track size, or redefine the template with fewer columns |
| Visual order different from DOM order | Confusing tab order for keyboard and screen reader users | Reorder the HTML so the source matches the meaningful reading order |

How grid-template-areas fits with the other grid properties
| Property | Applies to | What it does |
|---|---|---|
grid-template-columns |
Container | Defines the number and width of the columns |
grid-template-rows |
Container | Defines the number and height of the rows |
grid-template-areas |
Container | Names the cells so items can be placed by name |
grid-area |
Item | Places the item into a named area or between four lines |
grid-auto-flow |
Container | Controls how items with no explicit placement are auto placed (row, column, dense) |
gap |
Container | Adds spacing between tracks without touching the template |
When not to use grid-template-areas
Template areas shine for page level and component level layouts with a fixed, known structure: a dashboard shell, an article page, a product card, a form with a predictable arrangement. They are a poor fit when the number of items is dynamic, for example a product listing or a photo gallery. In those cases grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)) with auto placement does the job with far less code.
FAQ
What does grid-template-areas do exactly?
It assigns names to the cells of a grid container using quoted strings, so grid items can be positioned by name with grid-area instead of by line numbers. Repeating a name in neighbouring cells makes the area span those cells. There’s a good explainer over at mozilla.net.
Do I still need grid-template-columns?
In practice, yes. The template strings create the cell structure, but without explicit track sizes the columns are auto sized from their content, which rarely gives the proportions you want. Define your columns, and define your rows whenever vertical sizing matters.
Can a grid area be non rectangular?
No. The specification requires every named area to form a single rectangle. If any name forms an L, a T or a disconnected shape, the entire grid-template-areas value is invalid and browsers ignore it.
How do I leave a cell empty?
Use a period as the cell token, for example "sidebar main .". A sequence of periods with no spaces counts as one empty cell, while periods separated by spaces count as several.
What does the grid-auto-flow property do?
It controls the placement algorithm for items that have no explicit position. row (the default) fills the grid row by row, column fills column by column, and adding dense lets the browser backfill earlier holes with later items. With a complete set of named areas, auto flow rarely comes into play, which is exactly why unnamed or misspelled items suddenly appear in odd places.
Can I reuse the same area name twice in one template?
Only if the cells are adjacent and form a rectangle. Two separate blocks with the same name in different corners of the grid are invalid.
Is grid-template-areas well supported by browsers?
Yes. CSS Grid, including template areas, is supported by all current versions of Chrome, Edge, Firefox and Safari, and has been for many years. No prefix or fallback is needed for a modern audience.
Can I animate grid-template-areas?
No, the value is not animatable. If you need a transition between two layouts, animate the track sizes in grid-template-columns or grid-template-rows, or animate the properties of the items themselves.
Should I use grid-template-areas or Flexbox?
Use grid with template areas when you are arranging a two dimensional structure, rows and columns at the same time. Use Flexbox for one dimensional runs of content such as a navigation bar, a toolbar or a row of buttons. They work well together: a grid shell with flex components inside is a very common and very maintainable combination.
Takeaway
The appeal of css grid template areas is that the CSS looks like the layout it produces. Name the regions, keep every string the same length, keep every area rectangular, assign one grid-area per child, and redraw the map at each breakpoint. Run through the checklist above before you publish and you will avoid the handful of errors that cause almost every broken grid.