Layout Advanced

Aligning nested grids without duplicating tracks

Inner grids used to repeat the parent's column definitions to align. That was fragile and got out of sync. Subgrid inherits the parent's tracks so everything lines up.

Old 8 lines
1.parent {
2  display: grid;
3  grid-template-columns: 1fr 1fr 1fr;
4}
5
6.child-grid {
7  display: grid;
8  grid-template-columns: 1fr 1fr 1fr;
9}
10/* Breaks when parent columns change */
Modern
5 lines
1.parent {
2  display: grid;
3  grid-template-columns: 1fr 1fr 1fr;
4}
5
6.child-grid {
7  display: grid;
8  grid-template-columns: subgrid;
9}

10/* Stays in sync with parent */

Single source of truth

Column tracks are defined once on the parent. Change the parent, nested content aligns automatically.

No duplication

No copying 1fr 1fr 1fr or repeat() into every nested grid. Less code, fewer mismatches.

Real alignment

Cards, lists, or forms that span the same columns actually line up across sections.

Browser Support
92%
Chrome Firefox Safari Edge
Lines Saved
8 → 5
No repeated track defs
Old Approach
Duplicate tracks
Fragile, goes out of sync
Modern Approach
subgrid
Inherits parent columns

How it works

The old way was to give the inner grid the same grid-template-columns as the parent so things visually lined up. Any time you changed the parent's columns, you had to find and update every nested grid. Easy to miss one and end up with misaligned content.

With grid-template-columns: subgrid, the child grid does not define its own columns. It reuses the parent's track list. Add or change columns on the parent once, and every subgrid lines up. You can also use grid-template-rows: subgrid for row alignment.

ESC