A grid only lays out its direct children. Make a grid item a grid too and it gets an independent grid: its tracks are sized only from its own children. Two cards in the same parent row can't know about each other, so a short header in one card and a tall header in the next leave their bodies and footers at different heights.
subgrid fixes that. On a grid item, grid-template-rows: subgrid and/or grid-template-columns: subgrid mean "don't define tracks in this axis; use the ones I span in my parent":
- The subgrid's explicit tracks are the parent tracks it covers. It has as many as its span, so a card needs
grid-row: span 3to get three rows. - Its children are laid out in the parent's track sizing, so the tallest header in the row sizes the header row for every card.
- Line numbers restart at
1inside the subgrid, and the parent's line names are inherited. - There are no implicit tracks in a subgridded axis: items placed beyond its tracks are clamped into them.
- Gaps are inherited by default (
gap: normal); a subgrid may set its own. - The other axis stays independent unless it's subgridded too (
grid-template: subgrid / subgrid).
Without a parent grid, or when the box must be an independent formatting context (for example under contain: layout), subgrid behaves as none.
Before subgrid, the workarounds were fixed heights, which break on longer content, or display: contents on the card, which makes its children direct grid items but removes the card's own box, so its border, background and padding disappear.
Supported since Firefox 71, Safari 16 and Chrome 117.