CSS grid-templateProperty


Example

Create a three-column grid layout where the first row is 150 pixels high:

.grid-container { display: grid; grid-template: 150px / auto auto auto; }

Try it Yourself »

Browser Support

The numbers in the table indicate the first browser version that supports the property.

Property
grid-template 57 16 52 10 44

Property definition and usage instructions

The grid-template property is used for grid layout, setting rows, columns, and areas in the grid.

grid-template is a shorthand for the following properties:

Default Value: auto
Inherited: no
animation: Supported.Read Aboutanimatable Try it Yourself
version: CSS Grid Layout Module Level 1
JavaScript Syntax: object.style.gridTemplate="250px / auto auto" Try it Yourself


Syntax

grid-template: none|grid-template-rows / grid-template-columns|grid-template-areas|initial|inherit;

Value Description
none Default value, no size specified for rows and columns.
grid-template rows / grid-template-columns Specifies the size of rows and columns.
grid-template-areas Use 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 its parent element. Read about inherit

More Examples

Example

Set up two rows, with "item1" spanning the first two columns in the first two rows:

.item1 { grid-area: myArea; } .grid-container { display: grid; grid-template: 'myArea myArea . . .' 'myArea myArea . . .'; }

Try it Yourself »

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 Yourself »

Related Articles

CSS Tutorial:CSS Grid Layout

CSS Reference Manual:grid-areaProperty

CSS Reference Manual:grid-template-rowsProperty

CSS Reference Manual:grid-template-columnsProperty

CSS Reference Manual:grid-template-areasProperty

other extensions