CSS grid-template property
Example
Create a three-column grid layout where the first row is 150 pixels high:
.grid-container
{
display:
grid
;
grid-template:
150
px
/
auto
auto
auto
;
}
Try it »
Browser support
The numbers in the table indicate the first browser version that supports this property.
| property | |||||
|---|---|---|---|---|---|
| grid-template | 57 | 16 | 52 | 10 | 44 |
Property definition and usage
The grid-template property is used in grid layouts to set the rows, columns, and areas of the grid.
grid-template is a shorthand for the following properties:
| Default value: | auto |
|---|---|
| Inherited: | no |
| Animatable: | support. Read about animatable Try it |
| Version: | CSS Grid Layout Module Level 1 |
| JavaScript syntax: | object.style.gridTemplate="250px / auto auto" Try it |
Syntax
grid-template: none|grid-template-rows / grid-template-columns|grid-template-areas|initial|inherit;
| Value | Description |
|---|---|
| none | Default value; no row or column size is specified. |
| grid-template rows / grid-template-columns | Specifies the size of rows and columns. |
| grid-template-areas | Uses the names of grid items to lay out the grid. |
| initial | Sets this property to its default value. Read about initial |
| inherit | Inherits this property from the parent element. * Read about inherit* |
More examples
Example
Set two rows, where "item1" spans the first two columns of the first two rows:
.item1
{
grid-area:
myArea
;
}
.grid-container
{
display:
grid
;
grid-template:
'
myArea
myArea
. . .' '
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
{
display:
grid
;
grid-template:
'
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
CSS Reference Manual: grid-area property
CSS Reference Manual: grid-template-rows property
CSS Reference Manual: grid-template-columns property
CSS Reference Manual: grid-template-areas property