liveBook · Manning

Repeat()

As explained in Tiny CSS Projects

The repeat() CSS function represents repeated track definitions in grid-template-columns or grid-template-rows values.

repeat() is a built-in CSS function for declaring repeated grid columns or rows without writing the same track definition multiple times. It accepts two comma-separated values: the repetition count and the size of each track. section 2.3.1

Use repeat() when several grid tracks share the same sizing:

  • Write repeat(2, minmax(auto, 1fr)) for two flexible columns. section 2.3.1
  • Place the function inside grid-template-columns or grid-template-rows. section 2.3.1
  • Combine it with fr units, as in 3fr repeat(3, 1fr), to give one column half the available fraction space and divide the rest equally. section 2.3.4

A three-column grid

main { display: grid; grid-template-columns: repeat(2, minmax(auto, 1fr)) 250px; } This creates two equal flexible columns followed by a 250-pixel column. section 2.3.1

Listing 2.4 Setting the amount of columns
main {
  display: grid;
  grid-template-columns: repeat(2, minmax(auto, 1fr)) 250px;
}

Inspect the complete grid declaration and see how repeat() reduces duplicated column sizing in a practical layout. section 2.3.1

How Tiny CSS Projects covers it

How deep it goes
Defines arguments and demonstrates combined sizing, but stops short of broader function authoring or advanced repetition behavior.
Examples
Uses repeated flexible columns, a fixed 250-pixel column, and a 3fr repeat(3, 1fr) fraction layout.
What it assumes
Assumes basic CSS knowledge and teaches built-in functions, parameters, grid tracks, and fractional sizing in context.
What you can do after
Apply it via CSS Grid to write shorter repeated column and row definitions with flexible or fixed track sizing.
How it connects
Connects CSS Grid with grid-template-columns, grid-template-rows, minmax(), fr units, and implicit grids.

Also explained in

Compare how 3 books explain repeat() →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Tiny CSS Projects. The section links point to the parts of the book it draws on.