Lesson 28 of 50
cssAdvanced Grid – Named Areas & Sub‑Grids
12 mins
Course progress56%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 28 of 50
css12 mins
Keep these ideas in mind as you work through the lesson.
When a layout gets intricate, named grid areas give you a semantic map for the page skeleton, while sub‑grid lets nested grids share the parent’s column definitions.
.grid {
display:grid;
grid-template-areas:
"header header header"
"nav main aside"
"footer footer footer";
grid-template-columns: 1fr 3fr 1fr;
gap:1rem;
}
header { grid-area:header; }
nav { grid-area:nav; }
main { grid-area:main; }
aside { grid-area:aside; }
footer { grid-area:footer; }
A child grid can inherit the track sizing of its parent, eliminating the need to duplicate column definitions.
.gallery {
display:grid;
grid-template-columns: repeat(auto-fill, minmax(200px,1fr));
gap:1rem;
}
.card {
display:grid; /* card becomes a grid */
grid-template-columns: subgrid; /* inherits .gallery columns */
gap:0.5rem;
}
<div class="gallery">
<article class="card">
<img src="…" alt="" />
<h2>Title</h2>
<p>Excerpt …</p>
</article>
<!-- repeat cards -->
</div>
.card can now align its internal content (image, title, text) to the same column grid as its siblings, guaranteeing perfect vertical rhythm.layout.css.subgrid.enabled). Provide a fallback using normal grid definitions for those browsers.When you restructure using named areas, keep the DOM order logical for keyboard navigation. If visual order diverges, use aria‑order or tabindex carefully.