The fr Unit and Repeat
Use the fractional fr unit and the repeat() function to create flexible grid tracks.
The fr Unit and Repeat is a free CSS Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the CSS Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What is the fr Unit?
The fr (fraction) unit is exclusive to CSS Grid. It represents a fraction of the remaining free space in the grid container after all non-flexible tracks are sized.
Simple fr Example
Two equal columns each getting half the available space:
.grid {
display: grid;
grid-template-columns: 1fr 1fr;
}Mixed Tracks
fr space is calculated after fixed tracks are subtracted:
.layout {
display: grid;
grid-template-columns: 200px 1fr 1fr;
/* 200px sidebar, two equal flexible columns */
}Unequal Fractions
Different fr values create proportional columns:
.thirds {
grid-template-columns: 1fr 2fr 1fr;
/* 25% | 50% | 25% of available space */
}The repeat() Function
repeat() avoids repeating the same track size. The first argument is the count; the second is the track size.
.grid {
grid-template-columns: repeat(4, 1fr);
/* same as: 1fr 1fr 1fr 1fr */
}repeat() with Mixed Tracks
You can repeat a pattern of tracks:
.grid {
grid-template-columns: repeat(3, 1fr 2fr);
/* 6 columns: 1fr 2fr 1fr 2fr 1fr 2fr */
}auto-fill
repeat(auto-fill, ...) creates as many columns as fit the container at the given size. Empty tracks are preserved at the end.
.grid {
grid-template-columns: repeat(auto-fill, 200px);
}auto-fit
repeat(auto-fit, ...) like auto-fill but collapses empty tracks, allowing existing items to stretch to fill the container.
.grid {
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}minmax() in repeat
minmax(min, max) defines a track size range. Combined with auto-fit it creates a responsive grid with no media queries:
.responsive-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 24px;
}fr vs Percentage
Unlike percentages, fr automatically excludes gap space. 1fr 1fr with a 24px gap gives two equal columns without any math. Equivalent percentage math would be calc(50% - 12px).
fr with min-content max-content
Combine fr with content-based sizing for mixed layouts:
.grid {
grid-template-columns: min-content 1fr max-content;
/* label | flexible content | action button */
}Quick Check
What does repeat(auto-fit, minmax(200px, 1fr)) create?
Recap
The fr unit distributes remaining grid space proportionally. repeat() avoids repetitive track declarations. The powerful repeat(auto-fit, minmax(250px, 1fr)) pattern creates fully responsive card grids with no media queries needed.
Frequently asked questions
Is the “The fr Unit and Repeat” lesson free?
Yes — the full text of “The fr Unit and Repeat” is free to read here on the web, and the CSS Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the CSS Academy course, upgrade to CoddyKit PRO.
What will I learn in “The fr Unit and Repeat”?
Use the fractional fr unit and the repeat() function to create flexible grid tracks. You practise CSS Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start CSS Academy?
No prior experience is required. CSS Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “The fr Unit and Repeat” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this CSS Academy lesson?
Yes. Every CSS Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Display Grid and Template Columns Rows
- The fr Unit and Repeat
- Gap and Grid Placement
- Grid Template Areas