Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Grid

The grid-template-areas property

Reference for grid-template-areas: draw a grid layout with named areas as strings, leave cells empty with dots, and place items with grid-area. Examples included.

The grid-template-areas property lets you draw a layout. Each string is one row, each word in a string names one cell, and cells with the same name join into a single area. Items are then placed by name with grid-area. It gives you a layout that you can read straight from the CSS, and you can redraw it inside a media query.

CSS
.page {
  display: grid;
  grid-template-columns: 180px 1fr;
  grid-template-areas:
    "header header"
    "sidebar main"
    "footer footer";
}

Try it

A layout drawn with names
Empty cells with dots

Each dot is an empty cell that no area uses.

Syntax

CSS
grid-template-areas: none | <string>+;
  • Initial value: none
  • Applies to: grid containers
  • Inherited: no
  • Animatable: no
  • Computed value: as specified

Values

Value Description
none No named areas.
"a b c" One string per row; each whitespace-separated word names a column cell.
. (one or more dots) An empty cell that belongs to no area.

Usage notes

  • Rectangles only. An area name must cover a rectangle of cells. An L-shaped area makes the whole declaration invalid.
  • Equal rows. Every string must have the same number of cells, and the strings define how many rows and columns the explicit grid has at minimum.
  • Implicit line names. An area called main also creates lines named main-start and main-end on both axes, so you can use them with grid-column.
  • Sizes come separately. Areas only name cells. Use grid-template-columns and grid-template-rows to size them, or the grid-template shorthand to do both.
  • Responsive layouts. Override the property in a media query to restack a layout; the HTML order stays the same.
  • Accessibility. The visual order can differ from the source order. Keep the DOM in a logical reading order, because keyboard focus and screen readers follow the DOM.
  • Names are identifiers. Use letters, digits and hyphens, without spaces. Names are case-sensitive.

Browser support

Supported in all current browsers.