CSS grid Property
Example
Create a three-column grid layout and set the height of the first row to 160 pixels:
.grid-container
{
display:
grid
;
grid:
160
px
/
auto
auto
auto
;
}
Try it »
Tag Definition and Usage Notes
grid is a CSS shorthand property for all grid container properties, which can be used to set the following properties:
- Explicit grid properties: grid-template-rows, grid-template-columns, and grid-template-areas.
- Implicit grid properties: grid-auto-rows, grid-auto-columns, and grid-auto-flow.
- Gutter properties: grid-column-gap and grid-row-gap.
| Default value: | none none none auto auto row |
|---|---|
| Inherited: | no |
| Animatable: | Supported, See individual properties. Read animatable Try it |
| Version: | CSS Grid Layout Module Level 1 |
| JavaScript syntax: | object.style.grid="250px / auto auto auto" Try it |
Browser support
The numbers in the table indicate the first browser version that supports this property.
| property | |||||
|---|---|---|---|---|---|
| grid | 57 | 16 | 52 | 10 | 44 |
Attribute values
| Value | Description |
|---|---|
| none | Default value. Does not define the size of rows or columns. |
| grid-template-rows / grid-template-columns | Sets the size of columns and rows. |
| grid-template-areas | Specifies the names of grid items used by the grid layout |
| grid-template-rows / grid-auto-columns | Specifies the size (height) of rows and the automatic size of columns. |
| grid-auto-rows / grid-template-columns | Specifies the automatic size of rows and sets the grid-template-columns property. |
| grid-template-rows / grid-auto-flow grid-auto-columns | Specifies the size (height) of rows, how the auto-layout algorithm works, and the automatic size of columns. |
| grid-auto-flow grid-auto-rows / grid-template-columns | Specifies how the auto-layout algorithm works, the automatic size of rows, and sets the grid-template-columns property. |
| initial | Sets the property to its default value Read initial |
| inherit | Inherits the property from the parent element, * Read inherit* |
Online example
Example
Set two rows, with item1 spanning the first two columns across the first two rows:
.item1
{
grid-area:
myArea
;
}
.grid-container
{
display:
grid
;
grid:
'
myArea
myArea
. . .' '
myArea
myArea
. . .'
;
}
Try it »
Example
Name all the items to create a ready-to-use 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:
'
header
header
header
header
header
' '
menu
main
main
main
right
right
' '
menu
footer
footer
footer
footer
'
;
}
Try it »
More content
CSS Tutorial: CSS Grid Container
CSS Reference Manual: grid-template-areas property
CSS Reference Manual: grid-template-rows property
CSS Reference Manual: grid-template-columns property
CSS Reference Manual: grid-auto-rows property
CSS Reference Manual: grid-auto-columns property
CSS Reference Manual: grid-auto-flow property
CSS Reference Manual: grid-row-gap property
CSS Reference Manual: grid-column-gap property