CSS & LayoutBaseline · Widely

CSS Grid Track Sizing Algorithm

Mental Model

CSS Grid resolves column and row tracks in deterministic passes: fixed lengths lock first, intrinsic min-content/max-content bounds resolve next, and fr units divide only the remaining free space. Crucially, 1fr means minmax(auto, 1fr), not minmax(0, 1fr).

Interactive Simulator

CSS Grid 4-Pass Track Sizing

Step through how the Grid engine resolves fixed, intrinsic, and fr tracks.

Init Tracks
Intrinsic
Distribute fr
Step 1 / 3: 1. Initialize Track Base & Limits

Fixed tracks (e.g., 240px) lock both base size and growth limit; 1fr starts as minmax(auto, 1fr).

grid-template-columns: 240px minmax(0, 1fr) 2fr;
Internal State / Memory
track1
240px
track2
0..inf
track3
0..inf

Under the Hood

Grid sizing works like dividing a restaurant bill: fixed-price items come off the top, minimum cover charges (min-content) are reserved, and fr tracks split whatever cash remains on the table.

  1. Fixed Pass: Explicit px, rem, and resolved % tracks lock immediately.
  2. Intrinsic Pass: auto, min-content, and 1fr tracks query their children's minimum content widths, just like Flexbox & Intrinsic Sizing.
  3. Flexible (fr) Pass: Leftover space divides proportionally across fr factors; minmax(0, 1fr) bypasses the intrinsic minimum floor.
CSS
.app-shell {
  display: grid;
  /* Prevents wide <pre> blocks from blowing out the main column */
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 1.5rem;
}

To share parent tracks with nested card internals, pair this with CSS Subgrid.

Problem Genealogy

  • 2011–2016: Multi-column layouts relied on float percentages, calc(), and equal-height JS hacks.
  • 2017 (Grid L1): All major browsers shipped CSS Grid simultaneously, introducing fr, minmax(), and two-dimensional track alignment.

Production Pitfalls

Production Pitfall
  • 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.
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.

Connections & Logical Next Steps

CSS & LayoutCSS Grid Track Sizing Algorithm

Mechanical Comparisons