CSS grid-template
Property
Example
Create a three-column grid layout with the first row being 150 pixels high:
.grid-container {
display: grid;
grid-template: 150px / auto auto auto;
}
Browser Support
The numbers in the table specify the first browser version that fully supports the property.
Property | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
grid-template | 57 | 16 | 52 | 10 | 44 |
Property Definition and Usage
The grid-template
property is used for grid layout, setting rows, columns, and areas in the grid.
grid-template
is a shorthand property for:
Default value: | auto |
---|---|
Inherited: | no |
--- | --- |
Animatable: | Yes. 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, does not specify the size of rows and columns. |
grid-template rows / grid-template-columns | Specifies the size of rows and columns. |
grid-template-areas | Uses grid area names to layout the grid. |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its 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 . . .';
}
Name all grid items and create a webpage 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';
}
Related Articles
CSS Tutorial: CSS Grid Layout
CSS Reference: grid-area Property
CSS Reference: grid-template-rows Property
CSS Reference: grid-template-columns Property
CSS Reference: grid-template-areas Property