CSS grid-template-columns Property Explained

What the CSS grid-template-columns property does, with an example.

Published November 4, 2026

grid-template-columns defines the columns of a CSS grid: their number and widths, using units like px, fr, % and functions like repeat() and minmax().

How it works

The fr unit shares the remaining space in fractions. repeat(3, 1fr) makes three equal columns; repeat(auto-fill, minmax(200px, 1fr)) creates a responsive grid with no media queries.

Items fill columns row by row automatically.

Values and effects

grid-template-columns: 1fr 1fr 1fr; → three equal columns
grid-template-columns: 200px 1fr; → fixed + flexible
grid-template-columns: repeat(3, 1fr); → shorthand for equal columns
grid-template-columns: repeat(auto-fill, minmax(200px,1fr)); → responsive card grid

Practical examples

Responsive cards

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }

Sidebar layout

.layout { display: grid; grid-template-columns: 260px 1fr; }

Named areas

.page { display: grid; grid-template-columns: 1fr 3fr; grid-template-areas: 'nav main'; }

Common mistakes

  • Forgetting display: grid.
  • Using % with gap and overflowing (use fr).
  • Overly wide minmax causing horizontal scroll on phones.

Key takeaways

  • grid-template-columns in one line: grid-template-columns defines the columns of a CSS grid: their number and widths, using units like px, fr, % and functions like repeat() and minmax().
  • Inspect it live in DevTools → Styles.
  • Test across browsers and screen sizes.

FAQ

fr vs %?

fr divides the leftover space after fixed sizes and gaps; % is relative to the container.

Is grid-template-columns supported in all browsers?

Yes in all modern browsers; check caniuse.com for edge cases.

More CSS articles