Skip to the page
css reference · grid

CSS grid-template-columns

type
property (on the grid container)
applies to
a grid container
inherits
no
common values
1fr 1fr 1fr; repeat(3, 1fr); 240px 1fr; repeat(auto-fit, minmax(200px, 1fr))

Where it goes

On the grid parent, next to display: grid. grid-template-rows is the same idea for rows, though rows are usually left to size themselves.

Example

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}
.sidebar-layout {
  grid-template-columns: 240px 1fr;
}

Common mistakes

  • Writing percentages instead of fr. 33% 33% 33% plus a gap spills out of the box, because the percentages do not know about the gap. fr does.
  • Hard-coding a column count and then needing a media query to change it on phones. repeat(auto-fit, minmax(...)) handles that on its own.
  • Expecting a wide item to span two columns on its own. Each child takes one cell unless you say otherwise with grid-column: span 2.

Related

Updated 24 October 2026. Practice it in the css route, or read more on MDN.