CSS grid-template-areas attribute

Definition and Usage

The grid-template-areas attribute specifies the areas in the grid layout.

You can use grid-area Name the grid item, then refer to the name in the grid-template-areas attribute.

Each area is defined by an apostrophe. Use a period to refer to unnamed grid items.

See also:

CSS Tutorial:CSS Grid Item

CSS Reference Manual:grid-area property

CSS Reference Manual:grid-template property

Example

Example 1

To make the named item "myArea" span two columns in a five-column grid layout:

.item1 {
  grid-area: myArea;
}
.grid-container {
  display: grid;
  grid-template-areas: "myArea myArea . . .";
}

Try It Yourself

Example 2

Specifies two rows, where "item1" spans the first two columns in the first two rows (in a five-column grid layout):

.item1 {
  grid-area: myArea;
}
.grid-container {
  display: grid;
  grid-template-areas:
    'myArea myArea . . .'
    'myArea myArea . . .';
}

Try It Yourself

Example 3

Name all items and create a ready-made web page template:

.item1 { grid-area: header; }
.item2 { grid-area: menu; }
.item3 { grid-area: main; }
.item4 { grid-area: right; }
.item5 { grid-area: footer; }
.grid-container {
  display: grid;
  grid-template-areas:
    'header header header header header'
    'menu main main main right right'
    'menu footer footer footer footer';
}

Try It Yourself

CSS Syntax

grid-template-areas: none|itemnames;

Attribute Value

Value Description
none Default Value.Unnamed grid areas (grid areas).
itemnames Specifies the sequence in which each column and each row should be displayed.

Technical Details

Default Value: none
Inheritance: No
Animation Creation: Supported. See also:Animation-related properties.
Version: CSS Grid Layout Module Level 1
JavaScript Syntax: object.style.gridTemplateAreas=". . . myArea myArea"

Browser Support

The numbers in the table indicate the first browser version that fully supports this attribute.

Chrome IE / Edge Firefox Safari Opera
57 16 52 10 44