repeat() CSS Function – How to Define Grid Tracks with Repeated Patterns
The repeat() CSS function allows you to write more concise and readable values when specifying multiple grid tracks with repeated patterns.
Syntax of the CSS repeat()
Function
repeat()
accepts two arguments. Here is the syntax:
Argument 1: number-of-repetition
The number-of-repetition
argument specifies the number of times browsers should repeat the specified track list (the second argument).
The number-of-repetition
argument can be any of the following values:
- Number
1
or its multiple auto-fill
auto-fit
Argument 2: track-list-to-repeat
The track-list-to-repeat
argument specifies the track pattern you wish to repeat across a grid container’s horizontal or vertical axis.
In other words, track-list-to-repeat
consists of one or more values specifying the sizes of tracks browsers should repeat within a grid container.
Examples of the CSS repeat()
Function
Below are examples of how the CSS repeat()
function works.
How to create a three-column grid container with 70px
column-widths
The snippet above used the CSS repeat()
function to create three 70px
-wide columns.
Below is the non-repeat()
equivalent of the above grid-template-columns
property:
How to create a four-column grid container with one 50px
and three 90px
column-widths
The snippet above used the CSS repeat()
function to create three 90px
-wide columns.
Below is the non-repeat()
equivalent of the above grid-template-columns
property:
How to create a five-column grid container with one 40px
and two 60px 1fr
column-widths
The snippet above used the CSS repeat()
function to create two 60px 1fr
-wide columns.
Below is the non-repeat()
equivalent of the above grid-template-columns
property:
Create your web presence in no time
How to auto-fill the grid container with 70px
-wide columns
The snippet above used the CSS repeat()
function to automatically fill the grid container with 70px
-wide columns.
How to auto-fill the grid container with a minimum of 50px
and a maximum of 1fr
wide columns
The snippet above used the CSS repeat()
and minmax()
functions to automatically fill the grid container with a minimum of 50px
-wide columns and a maximum of 1fr
.
Use CSS Grid like a pro
How to auto-fit the grid container with a minimum of 50px
and a maximum of 1fr
wide columns
The snippet above used the CSS repeat()
and minmax()
functions to automatically fit the grid container with a minimum of 50px
-wide columns and a maximum of 1fr
.