Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Advanced Grid – Named Areas | CSS Basics to Advanced lesson | BraveProgrammer
  1. Courses
  2. /
  3. CSS Basics to Advanced

Lesson 28 of 50

·css

Advanced Grid – Named Areas & Sub‑Grids

12 mins

Course progress56%

What you'll learn

Keep these ideas in mind as you work through the lesson.

3 points
  • `grid-template-areas` improve readability for complex layouts.
  • `subgrid` allows deeper nesting without redefining column sizes.
  • Use `auto-fit`/`auto-fill` with `minmax()` for responsive card grids.

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.

Named Areas Syntax

.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; }

Why Use Named Areas?

  • Readability – The visual intent is clear when you glance at the CSS.
  • Maintenance – Re‑ordering a layout only requires moving the area names, not changing individual column numbers.

Sub‑Grid (Chrome 111+, Safari 16+)

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;
}

Real‑World Example – Card List With Consistent Gutter Widths

<div class="gallery">
  <article class="card">
    <img src="…" alt="" />
    <h2>Title</h2>
    <p>Excerpt …</p>
  </article>
  <!-- repeat cards -->
</div>

The .card can now align its internal content (image, title, text) to the same column grid as its siblings, guaranteeing perfect vertical rhythm.

Browser Support Note

  • Chrome 111+ ✅
  • Safari 16+ ✅
  • Firefox still experimental (behind layout.css.subgrid.enabled). Provide a fallback using normal grid definitions for those browsers.

Accessibility Reminder

When you restructure using named areas, keep the DOM order logical for keyboard navigation. If visual order diverges, use aria‑order or tabindex carefully.

Make it stickPractice what you've learned1 quiz · 6 practical tests · Optional activities from CSS Basics to AdvancedBrowse activities
Previous lessonCSS Grid – FundamentalsContinue to lesson 29Flexbox – FundamentalsBack to CSS Basics to Advanced curriculum