CSS grid-template-columns Property
Example
Make a 4 columns grid container:
.grid-container {
display: grid;
grid-template-columns:
auto auto auto auto;
}
Try it Yourself »
Definition and Usage
The grid-template-columns
property specifies the number
(and the widths) of columns in a grid
layout.
The values are a space separated list, where each value specifies the size of the respective column.
Default value: | none |
---|---|
Inherited: | no |
Animatable: | yes. Read about animatable Try it |
Version: | CSS Grid Layout Module Level 1 |
JavaScript syntax: | object.style.gridTemplateColumns="50px 50px 50px" Try it |
Browser Support
The numbers in the table specify the first browser version that fully supports the property.
Property | |||||
---|---|---|---|---|---|
grid-template-columns | 57 | 16 | 52 | 10 | 44 |
CSS Syntax
grid-template-columns: none|auto|max-content|min-content|length|initial|inherit;
Property Values
Value | Description | Demo |
---|---|---|
none | Default value. Columns are created if needed | Demo ❯ |
auto | The size of the columns is determined by the size of the container and on the size of the content of the items in the column | Demo ❯ |
max-content | Sets the size of each column to depend on the largest item in the column | Demo ❯ |
min-content | Sets the size of each column to depend on the smallest item in the column | |
length | Sets the size of the columns, by using a legal length value. Read about length units | 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
Make a 4 columns grid container, and specify a size for each column:
.grid-container {
display: grid;
grid-template-columns:
30px 200px auto 100px;
}
Try it Yourself »
Related Pages
CSS Tutorial: CSS Grid Layout
CSS Reference: The grid-template-rows property
CSS Reference: The grid-template property