Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Grid

The grid-template-columns property

Reference for grid-template-columns: define grid column tracks with lengths, fr, repeat(), minmax(), auto-fill and auto-fit, plus named lines, with live examples.

The grid-template-columns property defines the columns of a grid: how many there are, how wide each one is, and, optionally, names for the lines between them. It applies to grid containers (display: grid or inline-grid). Tracks that you don't define here, because items are placed beyond the list, are created automatically and sized by grid-auto-columns.

CSS
.layout { display: grid; grid-template-columns: 200px 1fr 1fr; }
.cards  { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }

Try it

Fixed, flexible and repeated columns
A responsive grid without media queries

Resize the preview: as it gets narrower, the number of columns drops, and each column never gets narrower than 120px.

Syntax

CSS
grid-template-columns: none
  | <track-list>
  | <auto-track-list>
  | subgrid <line-name-list>?;
/* track-size: <length-percentage> | <flex> | min-content | max-content | auto
              | minmax(min, max) | fit-content(<length-percentage>)           */
  • Initial value: none
  • Applies to: grid containers
  • Inherited: no
  • Animatable: yes, if the two lists have the same structure (same number of tracks and compatible types)
  • Computed value: the keyword none or the list with lengths made absolute

Values

Value Description
none No explicit columns; all columns are created implicitly.
<length> / <percentage> A fixed width. Percentages refer to the grid container's content width.
<flex> (1fr) A share of the space left after fixed tracks and gaps.
auto Takes the leftover space when stretched, otherwise sizes to content.
min-content / max-content The narrowest or widest size the content needs.
minmax(min, max) A track that is at least min and at most max.
fit-content(limit) Fits the content but never exceeds limit.
repeat(n, tracks) Repeats a track pattern n times, or with auto-fill / auto-fit as many as fit.
[name] Names the grid line at that position, for use in grid-column.
subgrid Uses the parent grid's column tracks (see the subgrid page).

Usage notes

  • fr is not a length. 1fr 1fr splits the free space equally, but a long unbreakable word can prevent that. minmax(0, 1fr) stops content from forcing a column wider.
  • auto-fill vs auto-fit. Both create as many columns as fit. With auto-fit, empty tracks collapse to zero, so existing items grow to fill the row.
  • Gaps count. gap is subtracted before fr units are calculated.
  • Percentages. Percentage columns plus gaps can exceed 100% and overflow; prefer fr.
  • Reading order. Columns follow the writing direction: the first column is on the right in right-to-left languages.

Browser support

Supported in all current browsers.