# repeat()

> The `repeat()` CSS function defines a repeating pattern for grid tracks.

## How do I use repeat() in grid-template-columns?

The function used in grid layouts to repeat a pattern of columns or rows. It simplifies the grid definition by enabling to specify how many times a certain pattern should repeat, making it easier to create complex, responsive layouts.

- Topic: Grids
- Type: function
- Browser support: Chrome 57+, Chrome Android 57+, Edge 16+, Firefox 76+, Firefox Android 79+, Safari 10.1+, Safari iOS 10.3+

## Example

Wrong:

```css
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, 1fr);
}
```

Right:

```css
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}
```

Auto-repeat needs a track with a definite minimum, so `minmax(200px, 1fr)` makes it valid.

## Common mistakes

- Writing `repeat(auto-fit, 1fr)`, which is invalid.
- Expecting `auto-fill` to stretch items when there are few of them.

## Key points

- Responsive grids use `auto-fill` or `auto-fit` with `minmax()` inside `repeat()`.
- `auto-fill` and `auto-fit` are not combined with flexible-only tracks like `repeat(auto-fill, 1fr)`.

## Interview questions

### auto-fill vs auto-fit in repeat(): what is the difference?

Both fit as many tracks as possible. `auto-fit` collapses empty tracks so items stretch, while `auto-fill` keeps them.

### Can repeat() hold more than one track?

Yes. `repeat(3, 100px 1fr)` repeats the two-track pattern three times.

## Related cards

- [minmax()](https://wonderium.dev/css/minmax.md)
- [grid-template-columns](https://wonderium.dev/css/grid-template-columns.md)
- [fit-content()](https://wonderium.dev/css/fit-content.md)
- [grid-auto-columns](https://wonderium.dev/css/grid-auto-columns.md)

---

- Level: [CSS](https://wonderium.dev/css.md)
- HTML version: https://wonderium.dev/css/repeat
- Last updated: 2026-11-25
