CSSgrid-template Property
Example
Make a three columns grid layout where the first row is 150px high:
display: grid;
grid-template: 150px / auto auto auto;
}
Definition and Usage
Thegrid-template property is a shorthand property for the following properties:
| Default value: | none none none |
|---|---|
| Inherited: | no |
| Animatable: | yes.Read aboutanimatableTry it |
| Version: | CSS Grid Layout Module Level 1 |
| JavaScript syntax: | object.style.gridTemplate="250px / auto auto"Try it |
Browser Support
The numbers in the table specify the first browser version that fully supports the property.
| Property | |||||
|---|---|---|---|---|---|
| grid-template | 57 | 16 | 52 | 10 | 44 |
CSS Syntax
Property Values
| Value | Description | Demo |
|---|---|---|
| none | Default value. No specific sizing of the columns or rows | |
| grid-template rows / grid-template-columns | Specifies the size(s) of the columns and rows | Demo ❯ |
| grid-template-areas | Specifies the grid layout using named items | Demo ❯ |
| initial | Sets this property to its default value. Read about initial | |
| inherit | Inherits this property from its parent element. Read aboutinherit |
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:
'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:
'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-rows property
CSS Reference: Thegrid-template-columns property
CSS Reference: Thegrid-template-areas property

