# CSS Grid Track Sizing Algorithm vs CSS Subgrid

- **Canonical URL:** https://frontend.rocks/vs/css-grid-track-sizing-vs-css-subgrid/
- **Relation:** Contrasts With
- **Last Verified:** 2026-11-15
- **Verdict:** Independent nested grids size their own tracks, whereas subgrid inherits track definitions from the parent grid.

## Comparison Matrix

| Dimension | CSS Grid Track Sizing Algorithm | CSS Subgrid |
| :--- | :--- | :--- |
| **Maturity** | Baseline · Widely | Baseline · Newly |
| **Domain** | CSS & Layout | CSS & Layout |
| **Mental Model** | Grid resolves tracks in four passes: fixed lengths, intrinsic content bounds, minmax() clamping, and fr free-space distribution. | subgrid lets nested grid containers inherit parent row or column tracks so sibling cards align internal headers and footers. |
| **Prerequisites** | Block Formatting Context (BFC) (Grid establishes a grid formatting context independent of block and float flow.) | CSS Grid Track Sizing Algorithm (Subgrid participates directly in the parent grid’s track-sizing algorithm.) |
| **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 subgrid: Avoid subgrid when cards have variable numbers of internal sections, use Flexbox margin-top: auto on the footer instead. |

## CSS Grid Track Sizing Algorithm — 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](/concepts/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](/concepts/css-subgrid).

## CSS Subgrid — Under the Hood
Without `subgrid`, each card is an island measuring its own ceiling height; with `subgrid`, every card bolts its shelves onto the same wall studs.

1. **Track Adoption**: Setting `grid-template-rows: subgrid` maps the child's row lines onto the parent's spanned tracks.
2. **Upward Sizing**: Intrinsic content inside the subgrid feeds back into the parent's [Render Tree & Layout](/concepts/render-tree-layout) track-sizing pass, expanding the shared row for all siblings.
3. **Explicit Span**: The subgrid container must span enough parent tracks (`grid-row: span 3`) to hold its internal rows, otherwise extra children pile into the last track.

```css
.pricing-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.5rem;
}
.pricing-card {
  display: grid;
  grid-row: span 3;
  grid-template-rows: subgrid;
  row-gap: 0.75rem; /* Overrides parent row-gap locally */
}
```

## Interactive Labs & Dissections
- [CSS Grid Track Sizing Algorithm Lab](https://frontend.rocks/concepts/css-grid-track-sizing/#lab) ([Markdown](https://frontend.rocks/concepts/css-grid-track-sizing.md))
- [CSS Subgrid Lab](https://frontend.rocks/concepts/css-subgrid/#lab) ([Markdown](https://frontend.rocks/concepts/css-subgrid.md))

## Primary Sources
- https://drafts.csswg.org/css-grid-2/#algo-track-sizing
- https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_grid_layout
- https://drafts.csswg.org/css-grid-2/#subgrids
- https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_grid_layout/Subgrid
