Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSS grid-template-columns property

CSS grid-template-columns property

Example

Create a grid container with 4 columns:

.grid-container

{

display:

grid

;

grid-template-columns:

auto

auto

auto

auto

;

}

Try it »


Browser support

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

property
grid-template-columns 57 16 52 10 44

Property definition and usage

The grid-template-columns property is used to set the number and width of columns in a grid layout.

Default value: auto
Inherited: no
Animatable: support. Read about animatable Try it
Version: CSS Grid Layout Module Level 1
JavaScript syntax: object.style.gridTemplateColumns="50px 50px 50px" Try it

Syntax

grid-template-columns: none|auto|max-content|min-content|length|initial|inherit;

Value Description
none Default value; no column size is specified.
* auto * The column size is determined by the size of the container and the size of the content of the grid items in the column.
max-content Each column is sized to the largest grid item in that column.
* min-content* Each column is sized to the smallest grid item in that column.
* length* A length value, which can be a number in px or a percentage %. 0 is the default value. Learn moreLength Units.
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

Create a 4-column grid container and set a size for each column:

.grid-container

{

display:

grid

;

grid-template-columns:

30

px

200

px

auto

100

px

;

}

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