CSS Subgrid Reference

CSS grid-template-columns/rows: subgrid syntax with span and named-line inheritance.

Reference for the CSS Subgrid feature — the subgrid value on grid-template-columns and rows, parent line and name inheritance, span sizing, and gap behaviour.

What does subgrid actually inherit?

A subgrid adopts the track sizing of the parent grid lines covered by the nested item's placement. The child element does not define its own track sizes on that axis; instead its rows or columns line up exactly with the parent's, so content across nested grids aligns.

Aligning nested grids with subgrid

By default a nested CSS grid defines its own tracks, so its rows and columns do not line up with the outer grid. The subgrid value makes a nested grid adopt the parent’s grid lines on a chosen axis, so deeply nested content aligns to one shared track structure. This reference covers the syntax and inheritance rules.

How it works

Set display: grid on the child, then set grid-template-columns: subgrid and/or grid-template-rows: subgrid. The child must itself be a grid item; the parent lines it inherits are exactly the ones its placement spans:

.parent {
  display: grid;
  grid-template-columns: [a] 1fr [b] 2fr [c] 1fr [d];
  gap: 1rem;
}
.child {
  grid-column: a / d;   /* spans all three parent columns */
  display: grid;
  grid-template-columns: subgrid;  /* adopts a / b / c / d */
}

The child’s columns now align pixel-for-pixel with the parent’s, inheriting the named lines ad and the 1rem gap. You can append your own names — subgrid [start] [mid] — and override column-gap/row-gap if you accept the resulting misalignment.

Tips and notes

  • Subgrid only mirrors the tracks the item spans — placement controls extent.
  • Inherited line names let you write grid-column: a / b inside the subgrid.
  • Both axes can be subgrid; mix subgrid on one axis with normal tracks on the other.
  • Provide a non-subgrid fallback for legacy browsers, as it degrades silently.