# subgrid

> The `subgrid` CSS keyword lets a nested grid adopt the tracks of its parent grid.

## How do I align content across cards with CSS subgrid?

The value of `grid-template-columns` and `grid-template-rows` that makes a nested grid use the tracks defined by its parent grid. Allows aligning the contents of cards or form rows across different grid items.

- Topic: Grids
- Type: keyword
- Browser support: Chrome 117+, Chrome Android 117+, Edge 117+, Firefox 71+, Firefox Android 79+, Safari 16+, Safari iOS 16+

## Example

Wrong:

```css
.card {
  display: grid;
  grid-template-rows: auto 1fr auto;
}
```

Right:

```css
.card {
  display: grid;
  grid-row: span 3;
  grid-template-rows: subgrid;
}
```

With `subgrid`, each card uses the parent's rows, so titles and buttons line up across cards.

## Common mistakes

- Forgetting `grid-row: span N`, so the subgrid has only one row.

## Key points

- The child is `display: grid` with `grid-template-rows: subgrid` and spans the rows it needs, like `grid-row: span 3`.
- Equal alignment comes from subgrid, not fixed heights or JavaScript equal-height code.

## Interview questions

### Does subgrid inherit the parent's gap?

Yes by default, but the subgrid can set its own `gap` to override it.

### Can I use subgrid for columns and rows at once?

Yes. Set both `grid-template-columns: subgrid` and `grid-template-rows: subgrid` on the nested grid.

### Does subgrid work with flexbox?

No. The parent must be a grid container, and the child must be a grid item set to `display: grid`.

## Related cards

- [grid](https://wonderium.dev/css/grid.md)
- [grid-template-rows](https://wonderium.dev/css/grid-template-rows.md)
- [grid-template-columns](https://wonderium.dev/css/grid-template-columns.md)
- [grid-row](https://wonderium.dev/css/grid-row.md)
- [gap](https://wonderium.dev/css/gap.md)

---

- Level: [CSS](https://wonderium.dev/css.md)
- HTML version: https://wonderium.dev/css/subgrid
- Last updated: 2026-11-25
