OSCSS.007: CSS Subgrid — Align Nested Cards with Shared Grid Tracks

OSCSS.007 — shared grid rows oil painting with BitcoinVersus.tech branding

Open-Source CSS • OSCSS.007 • 30–40 minutes

Two cards can share an outer grid yet have different internal heading heights. CSS subgrid gives a nested grid access to the parent grid’s track sizing in a chosen axis, so corresponding content rows can align without forcing identical text lengths.

Learning objectives

Explain independent nested grids versus subgrids, share parent rows, preserve source order, and verify desktop alignment and narrow-screen stacking. Review CSS Grid, container queries and Flexbox.

Share tracks, not content

An ordinary nested grid defines its own tracks. In a subgrid, the grid item spans parent tracks and adopts their sizing along the specified axis. The MDN subgrid guide explains that columns and rows can be subgridded independently. In the example, each card spans three rows for a title, description and footer; the parent grid coordinates those row sizes across cards. There are two independent columns at wide widths.

Kevin Powell demonstrates a practical use of CSS subgrid. Focus on shared grid tracks rather than treating subgrid as a replacement for every nested layout. Original source.
Two-display development workstation
Farzad Nazifi, March 6, 2016, original workstation photograph, CC0. Development context, not a screenshot of the lab.

Executable layout example

Save the following snippet as an HTML document and open it in a browser. The longer heading may wrap; corresponding footers remain on the shared row. At widths of 500px or less, cards stack in one column.

<style>
.cards{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}
.card{display:grid;grid-row:span 3;grid-template-rows:subgrid;border:1px solid;padding:8px}
.card>*{margin:0}
@media(max-width:500px){.cards{grid-template-columns:1fr}}
</style>
<div class="cards">
  <article class="card"><h2>Short</h2><p>One line.</p><footer>Read more</footer></article>
  <article class="card"><h2>A much longer heading that wraps on narrower displays</h2><p>More text.</p><footer>Read more</footer></article>
</div>

Browser verification in Chromium 144.0.7559.96: CSS.supports returned true for grid-template-rows: subgrid, the two footer top coordinates were equal at 720px, and cards stacked without overlap at 390px. All three assertions passed in the local test document; this does not certify every browser or the published WordPress theme.

Fallbacks and design constraints

Use feature queries to choose a fallback when needed, for example a regular grid with locally sized tracks. Shared rows rely on placement and track span; arbitrary child counts may require a different layout. Do not move focusable content visually in a way that makes keyboard order confusing. See responsive units and grid-template-rows.

Rebuilding FIFA standings layout with CSS subgrid. Ahmad Shadeed rebuilds the World Cup bracket with a cleaner DOM: CSS Grid sets the tracks, subgrid lets nested matches inherit them, and negative grid lines keep positioning flexible. #css #layoutishadeed.com/article…

— Web Standards (@web-standards.dev) 2026-07-23T10:00:00.000Z
Web Standards, July 23, 2026: a Bluesky post highlights a World Cup standings layout that reuses parent grid tracks through subgrid. The example illustrates how the same idea extends beyond cards. Original source.

Exercises and answers

1. What does grid-row: span 3 allocate? 2. Why can the longer heading affect a neighbor’s row? 3. Does row subgrid automatically share columns? 4. What changes at 390px in the lab?

Answers: 1. Three parent rows. 2. Their tracks are shared. 3. No; choose the column axis independently. 4. Cards stack in a single column.

Editor’s Note: We volunteer daily to ensure the credibility of the information on this platform is Verifiably True.

BitcoinVersus.Tech publishes technology and financial journalism for informational purposes and does not provide financial, investment, or legal advice.

Leave a Reply