CSS grid-template Property


Example

Make a three columns grid layout where the first row is 150px high:

.grid-container {
  display: grid;
  grid-template: 150px / auto auto auto;
}
Try it Yourself »

Definition and Usage

The grid-template property is a shorthand property for the following properties:

Show demo ❯

Default value: none none none
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

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

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

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 about inherit

More Examples

Example

Specify two rows, where "item1" spans the first two columns in the first two rows (in a five columns grid layout):

.item1 {
  grid-area: myArea;
}
.grid-container {
  display: grid;
  grid-template:
    'myArea myArea . . .'
    'myArea myArea . . .';
}
Try it Yourself »

Example

Name all items, and make a ready-to-use webpage 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-template:
    'header header header header header header'
    'menu main main main right right'
    'menu footer footer footer footer footer';
}
Try it Yourself »

Related Pages

CSS Tutorial: CSS Grid Item

CSS Reference: The grid-area property

CSS Reference: The grid-template-rows property

CSS Reference: The grid-template-columns property

CSS Reference: The grid-template-areas property


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.