CSS grid-template-columnsProperty
Example
Create a grid container with 4 columns:
.grid-container {
display: grid;
grid-template-columns: auto auto auto auto;
}
Try it Yourself »
Browser Support
The numbers in the table indicate the first browser version number that supports the property.
| Property | |||||
|---|---|---|---|---|---|
| grid-template-columns | 57 | 16 | 52 | 10 | 44 |
Property definition and usage instructions
The grid-template-columns property is used to set the number of columns and their widths in a grid layout.
| Default Value: | auto |
|---|---|
| Inherited: | no |
| animation: | Supported.Read Aboutanimatable Try it Yourself |
| version: | CSS Grid Layout Module Level 1 |
| JavaScript Syntax: | object.style.gridTemplateColumns="50px 50px 50px" Try it Yourself |
Syntax
grid-template-columns: none|auto|max-content|min-content|length|initial|inherit;
| Value | Description |
|---|---|
| none | Default value; column size is not specified. |
| auto | The size of the columns is determined by the size of the container and the size of the grid element content in the columns. |
| max-content | Each column's size is set to the size of the largest grid element in that column. |
| min-content | Each column's size is set to the size of the smallest grid element in that column. |
| length | A length value, which can be a number in px or a percentage %. 0 is the default value. Learn more.Length Units。 |
| initial | Set this property to its default value.Read about initial |
| inherit | Inherit this property from the parent element. Read about inherit |
More Examples
Example
Create a grid container with 4 columns, and set a size for each column.
.grid-container {
display: grid;
grid-template-columns: 30px 200px auto 100px;
}
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