CSS grid-area property
Example
The following example sets "item8" to start at row 2 and column 1, spanning 2 rows and 3 columns:
.item8
{
grid-area:
2
/
1
/
span
2
/
span
3
;
}
Try it »
Browser support
The numbers in the table indicate the first browser version that supports this property.
| property | |||||
|---|---|---|---|---|---|
| grid-area | 57 | 16 | 52 | 10 | 44 |
Property definition and usage
The grid-area property specifies the size and position of a grid item in the grid layout; it is the shorthand for the following properties:
The grid-area property can also name grid items.
Named grid items can be referenced through the container's grid-template-areas property.
| Default value: | auto / auto / auto / auto |
|---|---|
| Inherited: | no |
| Animatable: | support. Read about animatable Try it |
| Version: | CSS Grid Layout Module Level 1 |
| JavaScript syntax: | object.style.gridArea="1 / 2 / span 2 / span 3" Try it |
Syntax
grid-area: grid-row-start / grid-column-start / grid-row-end / grid-column-end | itemname;
| Value | Description |
|---|---|
| grid-row-start | Specifies which row the grid item starts displaying at. |
| grid-column-start | Specifies which column the grid item starts displaying at. |
| grid-row-end | Specifies which row the grid item stops displaying at, or how many rows it spans. |
| grid-column-end | Specifies which column the grid item stops displaying at, or how many columns it spans. |
| itemname | Specifies the grid item name |
More examples
The following example names item1 "myArea" and spans five columns:
Example
.item1
{
grid-area:
myArea
;
}
.grid-container
{
grid-template-areas:
'
myArea
myArea
myArea
myArea
myArea
'
;
}
Try it »
Each row is defined within single quotes ' ', separated by spaces.
A . indicates a grid item with no name.
Example
.item1
{
grid-area:
myArea
;
}
.grid-container
{
grid-template-areas:
'
myArea
myArea
. . .'
;
}
Try it »
To define two rows, define the columns of the second row in another set of single quotes ' '.
The following example sets "item1" to span 2 rows and 2 columns:
Example
.item1
{
grid-area:
myArea
;
}
.grid-container
{
grid-template-areas:
'
myArea
myArea
. . .'
;
}
Try it »
Name all grid items and create a web page template:
Example
.item1
{
grid-area:
header
;
}
.item2
{
grid-area:
menu
;
}
.item3
{
grid-area:
main
;
}
.item4
{
grid-area:
right
;
}
.item5
{
grid-area:
footer
;
}
.grid-container
{
grid-template-areas:
'
header
header
header
header
header
header
' '
menu
main
main
main
right
right
' '
menu
footer
footer
footer
footer
footer
'
;
}
Try it »
Related Articles
CSS Tutorial: CSS Grid Layout