🎨 The Subgrid That Built Its Own Tracks Anyway
CSS Grid Level 2 lets a nested grid inherit its parent’s column or row tracks with grid-template-columns: subgrid, but that keyword only applies to the axis you actually set it on – the other axis defaults to behaving like an ordinary, independent grid unless you explicitly subgrid it too. Set it on columns and forget rows, and the child aligns its columns to the parent perfectly while its rows size themselves with no relationship to the parent at all.
🔎 The Problem
.parent {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-template-rows: repeat(3, 80px);
}
.child {
grid-column: 1 / 5;
grid-row: 1 / 4;
display: grid;
grid-template-columns: subgrid; /* inherits parent's columns */
/* grid-template-rows was never set to subgrid - this
axis silently falls back to an ordinary grid with its
own auto-sized rows, unrelated to the parent's 80px
row tracks the rest of the layout is aligned to. */
}
✅ Fix: Set subgrid Explicitly on Every Axis That Needs It
- Set
grid-template-rows: subgridalongsidegrid-template-columns: subgridwhenever the child needs to align on both axes – there’s no shorthand that applies subgrid to both at once, each axis has to name it independently. - If you only need one axis to inherit the parent’s tracks (columns aligned, rows free to size by content), that’s a legal and often intentional combination – just be certain you meant to leave the other axis independent, rather than having simply forgotten to set it.
- Check support before relying on this for layout-critical alignment – subgrid shipped later than the rest of Grid Level 1 across browsers, so confirm your target browser matrix actually supports it before the parent/child alignment becomes something users depend on.
⚠️ Why This Is Easy to Miss
- Nothing throws an error or a warning – an axis that isn’t subgridded is simply valid, ordinary grid behavior on its own, so DevTools shows a perfectly normal-looking nested grid with no indication that one axis was supposed to inherit and didn’t.
- The misalignment is often subtle rather than dramatic – rows that are close to the parent’s sizing by coincidence can look almost right, which makes the bug easy to sign off on in a quick visual check and only notice later at a different viewport size or content length.
Subgrid doesn’t inherit the parent’s layout – it inherits exactly the one axis you named, and leaves the other to fend for itself.

