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|minmax()|length|percentage|fit-content()|repeat()|subgrid|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 | |
minmax(min, max) | Defines a size-range greater than or equal to min and less than or equal to max | |
length | Sets the size of the columns, by using a legal length value. Read about length units | Demo ❯ |
percentage | Sets the size of the columns, in percent, relative to the inline size of the container | |
fit-content() | Sets the size of the columns in length or %, and works like the column will use the available space, but it will never expand the max-content size | |
repeat() | Represents a repeated fragment of the track list | |
subgrid | Indicates that the grid will adopt the spanned portion of its parent grid in that axis | |
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