CSS Grid Track Sizing Algorithm vs Flexbox & Intrinsic Sizing
Grid sizes 2D tracks before placing items, whereas Flexbox distributes 1D space from item intrinsic sizes.
Structured Comparison Matrix
| Dimension | CSS Grid Track Sizing Algorithm | Flexbox & Intrinsic Sizing |
|---|---|---|
| Mental Model | Grid resolves tracks in four passes: fixed lengths, intrinsic content bounds, minmax() clamping, and fr free-space distribution. | Flex items default to min-width: auto, preventing shrink below their min-content size unless min-width: 0 or overflow is set. |
| Maturity & Domain | Baseline · Widely · CSS & Layout Chrome 57+ · Firefox 52+ · Safari 10.1+ | Baseline · Widely · CSS & Layout Chrome 29+ · Firefox 28+ · Safari 9+ |
| Prerequisites | ||
| When Not to Use | When not to use Grid: Avoid Grid for simple inline wrapping chips or toolbars where items should size to their own content and wrap naturally, use Flexbox with flex-wrap: wrap. | When not to use Flexbox: Avoid Flexbox for strict two-dimensional card alignments where row tracks must line up across columns; use CSS Grid instead. |
Engine Mechanics & Trade-Offs
1fr is shorthand for minmax(auto, 1fr); intrinsic minimum sizing runs before fr space division, causing grid blowout unless minmax(0, 1fr) is used.
Key Pitfalls: The 1fr grid blowout: Writing 1fr instead of minmax(0, 1fr) allows unbreakable text or <pre> blocks to push the track wider than the viewport. auto-fill vs auto-fit confusion: auto-fill preserves empty ghost tracks at the end of a row; auto-fit collapses empty tracks to 0px so existing items expand.
Flex layout computes hypothetical main sizes from flex-basis, clamps against min-width: auto (min-content), and distributes remaining space.
Key Pitfalls: Truncated text refuses to ellipsis: text-overflow: ellipsis inside a flex child fails silently until min-width: 0 is set on every intermediate flex item up the chain. Misunderstanding flex: 1 vs flex: auto: flex: 1 sets flex-basis: 0% (equal columns); flex: auto sets flex-basis: auto (wider content gets a wider column)