repeat() CSS Function
The repeat() function repeats a pattern of grid tracks, such as repeat(3, 1fr), or as many as fit with auto-fill or auto-fit.
Description
The repeat() CSS function repeats a pattern of grid tracks a given number of times, so you do not have to write the same track sizes over and over. It is used in grid-template-columns and grid-template-rows. For example, repeat(4, 1fr) is the same as 1fr 1fr 1fr 1fr, and repeat(2, 100px 1fr) is the same as 100px 1fr 100px 1fr.
The first argument is the number of repetitions, either a positive integer or one of the keywords auto-fill and auto-fit. With these keywords the browser creates as many tracks as will fit in the container. The difference appears when there are fewer items than tracks: auto-fill keeps the empty tracks, while auto-fit collapses them so the existing items can stretch to fill the row. The second argument is the track list to repeat, which can include sizes, minmax(), fit-content() and named grid lines in square brackets.
/* Twelve-column layout */
.page {
display: grid;
grid-template-columns: repeat(12, 1fr);
}
/* Repeating a pattern with named lines */
.table {
grid-template-columns: repeat(3, [col-start] 1fr [col-end]);
}
/* As many 160px+ columns as fit */
.gallery {
grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
Interactive Demo
Syntax
repeat() = repeat( [ <integer [1,∞]> | auto-fill | auto-fit ], <track-list> )
Values
- <integer>The number of times to repeat the track list. Must be 1 or more.
- auto-fillRepeats the tracks as many times as will fit in the container without overflowing. Empty tracks are kept.
- auto-fitLike auto-fill, but empty repeated tracks collapse to 0, so the filled tracks can grow to use the space.
- <track-list>One or more track sizes to repeat, such as 1fr, 100px, minmax(), fit-content(), and optional [line-names].
Example
Browser Support
The following information will show you the current browser support for the CSS repeat() function. Hover over a browser icon to see the version that first introduced support for this CSS function.
Desktop





Tablets & Mobile





