Skip to content

The repeat() Function

Writing this is fine… once:

grid-template-columns: 1fr 1fr 1fr 1fr;

Writing it all semester is not.

repeat() lets you define track patterns cleanly — and scale them without rewriting your template every time.


grid-template-columns: repeat(4, 1fr);

That means:

  • Make 4 columns
  • Each column is 1fr

Same result. Less noise.


grid-template-columns: repeat(6, 1fr);

You didn’t rewrite the track list — you changed the count.

That’s the whole point.


grid-template-rows: repeat(3, 10rem);

Any track size works: fr, rem, %, minmax(), etc.


Long templates are a smell.
Patterns are power.


Use repeat() when:

  • Your grid has repeated structure
  • You want to scale column/row counts quickly
  • You want templates that stay readable under pressure

📘 Grid repeat() function Study Guide (PDF)

📘 Grid repeat() function Infographic (PNG)

Infographic explaining CSS Flexbox direction and axes, showing how flex-direction defines the main axis and cross axis, with visual examples for row, row-reverse, column, and column-reverse, and how justify-content and align-items map to each axis.

There will always be more items than expected in a container. Where will they go?