liveBook · Manning

Fraction unit

As explained in Web Design Playground, Second Edition

The CSS fr unit is a flexible length unit representing a fraction of the free space in a grid container.

The CSS Grid fr unit represents a fraction of the free space in a grid container. Use it in grid-template-columns or grid-template-rows to let tracks expand instead of locking them to pixel widths. section 13.4

Think of fr as sharing whatever space is left:

  • A single 1fr column takes all available free horizontal space. section 13.4
  • A 1fr and 3fr pair divides the free space into 25% and 75%. section 13.4
  • For rows, give the grid container an explicit height, such as 100vh; otherwise there may be no free vertical space to divide. section 13.4

A fixed column, another fixed column, then the leftovers

Set the first two columns to 100px and 200px, then let the final column claim the remaining space: grid-template-columns: 100px 200px 1fr;. For a more flexible three-column layout, use repeat(3, 1fr). section 13.4 section 14.3

.container {
    display: grid;
    grid-template-columns: 100px 200px 1fr;   #1
    grid-template-rows: 100px 150px;
}

Inspect the complete grid declaration showing fixed tracks beside an fr track that absorbs the remaining width. section 13.4

How Web Design Playground, Second Edition covers it

How deep it goes
Explains proportional sizing, remaining-space behavior, row-height requirements, and conversion from pixel-based layouts.
Examples
Demonstrates 1fr, 1fr-to-3fr proportions, mixed pixel and fr columns, and repeat(3, 1fr) layouts.
What it assumes
Assumes basic CSS Grid properties and teaches the free-space idea before applying proportional track values.
What you can do after
Apply it via CSS Grid to build proportional columns and convert fixed-width layouts into liquid layouts.
How it connects
Connects fr units to CSS Grid, grid-template-columns, grid-template-rows, repeat(), and liquid layouts.

Also explained in

Compare how 4 books explain fraction unit →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Design Playground, Second Edition. The section links point to the parts of the book it draws on.