Grid track sizing algorithm
Definition and purpose
The track sizing algorithm resolves each track using a base size and a growth limit. Fixed tracks, intrinsic sizing functions and flexible tracks participate differently. Placement establishes the spans whose content contributes to sizing.
Fixed and equal flexible tracks
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #parent { display: grid; width: 300px; gap: 10px; } #parent > div { min-width: 0; background: #dbeafe; } #parent { grid-template-columns: 60px minmax(0, 1fr) minmax(0, 1fr); } </style> </head> <body> <div id="parent"> <div id="a">A</div> <div id="b">B</div> <div id="c">C</div> </div> </body></html>300 − 60 − 20 = 220px; each flexible track gets 110px.
Syntax and mental model
In outline: initialize sizes, resolve intrinsic contributions (including spanning items), maximize tracks, expand flexible tracks, and stretch eligible auto tracks. For a definite 300px grid with 60px fixed track, two 10px gaps and minmax(0, 1fr) plus minmax(0, 2fr), 220px remains; the flex fraction is about 73.33px, giving approximately 73.33 and 146.67px. If a base size exceeds its tentative fractional allocation the fraction must be recalculated. An indefinite axis uses a different flex fraction procedure based on content contributions. The examples choose divisible widths for exact geometry.
A minimum constrains the fraction
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #parent { display: grid; width: 300px; gap: 10px; } #parent > div { min-width: 0; background: #dbeafe; } #parent { grid-template-columns: 60px minmax(140px, 1fr) minmax(0, 1fr); } </style> </head> <body> <div id="parent"> <div id="a">A</div> <div id="b">B</div> <div id="c">C</div> </div> </body></html>The 140px minimum forces a new allocation for the remaining flexible track.
Common mistakes
A bare 1fr track implies an automatic minimum, not necessarily zero. minmax(0, 1fr) removes that track minimum but content may overflow. Include gaps before dividing free space; do not assume that all tracks are simply proportional to fr.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Grid placement algorithm. Next lesson: Subgrid and intrinsic contributions.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Grid track sizing algorithm — knowledge check
Five questions on grid track sizing algorithm.
What does each track have during sizing?
How much space remains after 60px and two 10px gaps in 320px?
How wide is the 2fr track in the exercise?
Does bare 1fr always imply zero minimum?
What if a minimum exceeds its tentative fr allocation?