Each track has a minimum and a maximum sizing function. Three kinds:
- Fixed: a length or percentage.
- Intrinsic:
min-content,max-content,auto,fit-content(limit). Sized from the items in the track. - Flexible:
fr. A share of the leftover space: what remains after the other tracks and the gaps are sized.100px 1fr 2frin400pxgives100 100 200.
minmax(min, max) gives a range. A bare 1fr means minmax(auto, 1fr): its minimum is auto, which takes the items' content-based minimum. So 1fr 1fr isn't guaranteed equal; a wide child forces its column open. minmax(0, 1fr) is.
auto as a whole track is minmax(auto, auto): at least the content minimum, up to max-content, and when justify-content is normal or stretch, auto tracks share any space left at the end.
repeat(n, …) repeats a track list. With auto-fill instead of n, the browser creates as many tracks as fit in the container, gaps included, measuring each by its fixed max, or else its fixed min: minmax(100px, 1fr) counts as 100px. auto-fit does the same, then collapses repeated tracks that no item occupies to 0, gutters included, so the fr tracks with items absorb the space. With enough items to fill every track, the two are identical.
The track sizing algorithm runs per axis (columns first, then rows) in five steps: initialise each track's base size and growth limit, resolve intrinsic sizes from the items, grow tracks to their limits with free space, expand fr tracks, then stretch auto tracks.
getComputedStyle(grid).gridTemplateColumns returns the used track sizes, which makes all of this easy to inspect.