CSS Reference ยท Units and Values
The fr unit
Reference for the CSS fr unit: how flexible fractions share leftover grid space, how minmax() and auto interact with it, and common mistakes.
The fr unit is a flexible length used only for grid tracks. One fr is a share of the space left over in the grid container after fixed-size tracks and gaps have been subtracted. Two tracks of 1fr split the leftover space equally; a 2fr track gets twice as much as a 1fr track.
Because fr is not a normal length, it works in grid-template-columns, grid-template-rows, grid-auto-columns, grid-auto-rows and inside minmax() and repeat(), but not in width, margin or calc().
.layout { display: grid; grid-template-columns: 200px 1fr 2fr; }
Try it
Syntax
<flex> = <number [0,โ]>fr
Initial value, inheritance and animatability depend on the property that uses it (for example grid-template-columns). The fr unit itself has no computed value outside a track list.
Values
| Value | Description |
|---|---|
1fr |
One share of the free space. |
2.5fr |
Fractions are allowed; the number must not be negative. |
0.5fr |
If all flex factors in a track list add up to less than 1, the tracks use only that fraction of the free space and the rest stays empty. |
Usage notes
1frmeansminmax(auto, 1fr). The automatic minimum is the content's minimum size, so a track with a long word or wide image can grow beyond its fair share. Writeminmax(0, 1fr)when you need strictly equal tracks.- Fixed tracks come first. Pixel,
%,autoand content-sized tracks and the gaps are resolved beforefrshares the remainder. - Needs a definite size to share. In a row direction with an indefinite height,
frrows fall back to content size. - Ratios, not percentages.
1fr 3fris a 1:3 split of the free space, not 25% and 75% of the container. - Not usable in
calc().calc(1fr + 10px)is invalid. Useminmax()or a fixed track plus1frinstead. - Flexbox is different. Flex items are sized with
flex-grow, notfr.
Browser support
Supported in all current browsers for grid layouts.
Related
grid-template-columnsโ wherefris most often usedminmax()โ set a minimum for a flexible trackrepeat()โ repeat tracks- Lesson: Grid Tracks