Course contentsShow
← Web Development
Lesson 318 of 2,9826. CSS GridFree lesson

The fr Unit: Fractional Space Distribution

How fr units divide available space proportionally, the most powerful sizing unit in Grid.

The fr Unit: Fractional Space Distribution

You'll learn how the fr unit proportionally divides available space in CSS Grid, making it the most powerful sizing tool for flexible layouts.

What is the fr Unit?

The fr unit stands for "fraction" and represents a fraction of the available space in your grid container. Unlike fixed units like pixels or percentages, fr units intelligently divide up leftover space after fixed-size tracks are calculated.

Think of it like slicing a pizza: if you have 3 equal slices, each gets 1fr of the whole pizza. If one slice is 2fr and two are 1fr, the first slice gets twice as much as the others.

How fr Units Work

When you write grid-template-columns: 1fr 2fr 1fr, Grid does this:

  1. Calculates any fixed-size columns first
  2. Looks at remaining space
  3. Divides that space proportionally based on fr values
  4. The middle column gets 2 parts, outer columns get 1 part each (2:1:1 ratio)
.container {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr; /* Three equal columns */
}

.container-mixed {
  display: grid;
  grid-template-columns: 200px 1fr 2fr; /* Fixed + flexible */
}

The first example creates three equal columns. The second reserves 200px, then splits remaining space so the last column is twice as wide as the middle one.

Why fr Beats Percentages

Unlike percentages, fr units automatically account for gaps and padding, preventing overflow issues. They make Grid truly responsive without complex calculations.

Key Takeaway: The fr unit proportionally distributes available space among grid tracks, making it the most flexible and powerful way to create responsive column and row sizing in CSS Grid.