liveBook · Manning

Fraction unit

As explained in Tiny CSS Projects

The fr unit is a CSS Grid sizing unit that represents a share of the available space remaining after minimum sizes are applied.

The fr unit is a CSS Grid sizing unit. It divides leftover space among grid tracks after their minimum sizes have been applied, letting columns or rows share available room. section 2.3.4

Use fr values to describe proportional grid tracks:

  • grid-template-columns: 1fr gives one column all available space. section 2.3.4
  • grid-template-columns: 1fr 1fr 1fr 1fr divides the available space into four equal shares. section 2.3.4
  • grid-template-columns: 3fr repeat(3, 1fr) assigns half the space to the first track and divides the remainder among three tracks. section 2.3.4
  • grid-template-columns: repeat(2, minmax(auto, 1fr)) 250px creates two equal flexible columns beside a fixed 250-pixel column. section 2.3.1 section 2.3.3

Sharing a cake

Imagine the grid as a whole cake. Four 1fr tracks receive four equal slices. A 3fr track receives three slices while three 1fr tracks receive one slice each, so the first track gets half the cake. section 2.3.4

Listing 2.4 Setting the amount of columns
main {
  display: grid;
  grid-template-columns: repeat(2, minmax(auto, 1fr)) 250px;
}

Inspect the complete grid declaration combining fr, repeat(), minmax(), auto, and a fixed pixel track. section 2.3.4

How Tiny CSS Projects covers it

How deep it goes
Explains proportional allocation with cake diagrams and declarations, but stops short of detailed Grid sizing internals.
Examples
Uses cake portions, equal and weighted fr columns, and a three-column project declaration previewed with grid lines.
What it assumes
Assumes basic CSS knowledge and introduces Grid sizing alongside repeat() and minmax() functions.
What you can do after
Build flexible CSS Grid columns with proportional tracks, repeat(), minmax(), and fixed-size neighbors.
How it connects
Connects fr with CSS Grid, grid-template-columns, minmax(), repeat(), fixed pixel sizing, and minimum content sizes.

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 Tiny CSS Projects. The section links point to the parts of the book it draws on.