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

The fr Unit: Flexible Grid Tracks

Master the fr (fraction) unit to create proportional grid tracks that share available space.

The fr Unit: Flexible Grid Tracks

You'll learn how to create flexible, proportional grid columns and rows that automatically share available space.

What is the fr Unit?

The fr unit stands for "fraction" and is used exclusively in CSS Grid to divide up available space proportionally. Think of it like slicing a pie: if you have three slices marked 1fr, 1fr, and 2fr, you're dividing the pie into four equal parts (1+1+2), where the third slice gets twice as much as the first two.

Unlike fixed units like px or %, the fr unit is responsive by default—it automatically adjusts as the container grows or shrinks.

How fr Works

When you write grid-template-columns: 1fr 2fr, you're telling the grid:

  • First column gets 1 part of the available space
  • Second column gets 2 parts of the available space
  • Total: 3 parts, so column 1 = 33.3%, column 2 = 66.6%
.grid-container {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr; /* Three equal columns */
}

This creates three columns that each take up an equal share of the container width.

.grid-container {
  display: grid;
  grid-template-columns: 2fr 1fr; /* First column twice as wide */
}

Here, the first column gets 2/3 of the space, and the second gets 1/3.

Why Use fr?

The fr unit makes grids truly flexible without manual calculations. Instead of figuring out percentages or worrying about pixel values, you simply describe the proportions you want, and the browser handles the math.

Key Takeaway: The fr unit creates flexible, proportional grid tracks that automatically share available space based on the fractions you specify—making responsive layouts effortless.