CSSgrid-template-areas Property
Example
Make the named item "myArea" span two columns in a five columns grid layout:
grid-area: myArea;
}
.grid-container {
display: grid;
grid-template-areas: "myArea myArea . . .";
}
Definition and Usage
Thegrid-template-areas property specifies areas within the grid layout.
You can name grid items by using thegrid-area property, and then reference to the name in thegrid-template-areas property.
Each area is defined by apostrophes. Use a period sign to refer to a grid item with no name.
| Default value: | none |
|---|---|
| Inherited: | no |
| Animatable: | yes.Read aboutanimatableTry it |
| Version: | CSS Grid Layout Module Level 1 |
| JavaScript syntax: | object.style.gridTemplateAreas=". . . myArea myArea" |
Browser Support
The numbers in the table specify the first browser version that fully supports the property.
| Property | |||||
|---|---|---|---|---|---|
| grid-template-areas | 57 | 16 | 52 | 10 | 44 |
CSS Syntax
Property Values
| Value | Description | Demo |
|---|---|---|
| none | Default value. No named grid areas | Demo ❯ |
| itemnames | A sequence that specifies how each columns and row should display | Demo ❯ |
More Examples
Example
Specify two rows, where "item1" spans the first two columns in the first two rows (in a five columns grid layout):
grid-area: myArea;
}
.grid-container {
display: grid;
grid-template-areas:
'myArea myArea . . .'
'myArea myArea . . .';
}
Example
Name all items, and make a ready-to-use webpage template:
.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 header'
'menu main main main right right'
'menu footer footer footer footer footer';
}
Related Pages
CSS Tutorial:CSS Grid Item
CSS Reference: Thegrid-area property
CSS Reference: Thegrid-template property

