liveBook · Manning

Repeat()

As explained in Math for Web Design

repeat() is a CSS Grid function that expands a track-size pattern into a specified number of repeated tracks or an automatically determined repetition.

repeat() compresses repeated CSS Grid track definitions into a pattern. A fixed form such as repeat(3, 100px) expands to three 100px columns, while a multi-track pattern repeats as a whole: repeat(2, 100px 200px 50px) produces six tracks. section 4.4.4

Expanding a fixed pattern

The repetition count multiplies the pattern length. With two repetitions of a three-track pattern, total tracks = 3 × 2 = 6. The CSS equivalent is grid-template-columns: 100px 200px 50px 100px 200px 50px. section 4.4.4

With auto-fill or auto-fit, the browser calculates how many repeated tracks fit. It subtracts the grid gaps from the container width, divides by the track width, and rounds down. A 450px container with 10px gaps and 100px tracks fits floor((450px − 3 × 10px) ÷ 100px) = 4 columns. section 4.4.4

Choose the automatic keyword according to how empty tracks should behave:

How Math for Web Design covers it

How deep it goes
Explains fixed expansion and automatic fit calculations, then distinguishes empty-track behavior without descending into browser implementation internals.
Examples
Uses fixed pixel columns, repeated multi-track patterns, fit calculations, and responsive card grids.
What it assumes
Assumes CSS Grid track and gap terminology while teaching repetition counts, pattern lengths, and fit arithmetic directly.
What you can do after
Apply it via CSS Grid to create repeated tracks and choose whether unused responsive columns remain or collapse.
How it connects
Connects repeat() with CSS Grid, auto-fill, auto-fit, minmax(), and fr units.

Also explained in

Compare how 3 books explain repeat() →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Math for Web Design. The section links point to the parts of the book it draws on.