freecoding.school100% FREE · NO SIGNUP
Grid CanyonISSUE #20 of 27

subgrid · inheriting parent tracks

FlexboVSThe Float Phantom
Flexbo sayssubgrid lets a nested grid align to its parent’s tracks instead of defining its own.

Normally a nested grid has independent tracks, so child cards don't line up. grid-template-columns: subgrid (or rows) makes the nested grid inherit the parent's track lines, so inner content aligns perfectly across cards — solving the "ragged card" problem.

Power-ups you unlock

The Float Phantom attacks — common mistakes

Boss battleMake two cards whose titles and footers align by using subgrid for their rows.

Example code

<!doctype html><html><head><meta charset="utf-8">
<style>.wrap{display:grid;grid-template-columns:1fr 1fr;gap:10px}.card{display:grid;grid-template-rows:subgrid;grid-row:span 2;background:#140a28;color:#e6e0ff;padding:12px}</style></head><body style="background:#06040d;padding:20px"><div class="wrap"><div class="card"><h3>short</h3><p>foot</p></div><div class="card"><h3>a longer title</h3><p>foot aligns</p></div></div></body></html>
▶ Open the interactive comic issue
‹ Grid Items · Grid-Area · Named LinesMulti-Column · Column-Count · Column-Rule ›