KodingKaro
CSS · Advanced · Advanced Grid and Flexbox Layouts

Named areas and intrinsic Grid sizing

Named grid areas help express a page shell, while intrinsic sizing lets tracks respond to the content they contain.

✓ What you will learn in this topic

  • Explain the key idea: Named areas clarify page structure and intrinsic sizing helps tracks respond to content.
  • Apply the concept: The named areas describe a main region beside a sidebar, while the flexible track can shrink without forcing overflow.
  • Avoid this common mistake:

Concept explanation

grid-template-areas gives tracks readable names. minmax(), min-content, max-content, and auto describe how tracks relate to content and available space. Use minmax(0, 1fr) when a flexible track must be allowed to shrink below its min-content size.

Area names should reflect page structure, and responsive changes should preserve a logical reading order.

Syntax

A CSS rule has a selector followed by declarations. Each declaration is a property and a value; the braces group the declarations that apply to matching elements.

.demo {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 16rem;
  grid-template-areas: "main aside";
  gap: 1rem;
}

Example 1: a small page element

Use this HTML as the target and place the CSS in a stylesheet linked to the page, or inside a <style> element while experimenting.

<main class="demo card-grid course-grid dashboard-panel course-card-list dashboard-grid card-layout"><h2>Learning card</h2><p>Clear styles make this information easier to scan.</p><nav class="site-nav"><a href="/learn">Courses</a></nav><label class="form-field"><span>Email</span><input type="email" aria-invalid="true"></label><article class="card course-card dashboard-card theme-dark"><span class="badge status">New</span><div class="course-card__image"></div><h2 class="course-card__title card__title">Course update</h2><p class="status">New lessons are available this week.</p><a href="/learn" aria-current="page">Read the details</a><div class="actions course-card__actions dashboard-panel__actions"><button type="button">View lessons</button><button type="button" disabled>Unavailable</button></div></article></main>
.demo {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 16rem;
  grid-template-areas: "main aside";
  gap: 1rem;
}

Expected result: The named areas describe a main region beside a sidebar, while the flexible track can shrink without forcing overflow.

Example 2: a practical interface card

The same idea can style a reusable card on a course page. The class selector keeps the rule attached to this component rather than changing every element of that type.

<section class="demo card-grid course-grid dashboard-panel course-card-list dashboard-grid card-layout"><h2>Learning card</h2><p>Clear styles make this information easier to scan.</p><nav class="site-nav"><a href="/learn">Courses</a></nav><label class="form-field"><span>Email</span><input type="email" aria-invalid="true"></label><article class="card course-card dashboard-card theme-dark"><span class="badge status">New</span><div class="course-card__image"></div><h2 class="course-card__title card__title">Course update</h2><p class="status">New lessons are available this week.</p><a href="/learn" aria-current="page">Read the details</a><div class="actions course-card__actions dashboard-panel__actions"><button type="button">View lessons</button><button type="button" disabled>Unavailable</button></div></article></section>
.dashboard {
  display: grid;
  grid-template: "header header" auto "nav main" 1fr / 14rem minmax(0, 1fr);
  min-height: 100vh;
}

Expected result: The course update reads as a distinct interface card, and its content follows the spacing, color, and layout choices in the rule.

Common mistake

Using visual reordering to create a reading order that contradicts the HTML source.

Best practice

Keep source order meaningful and use Grid for macro structure with Flexbox for local one-axis alignment.

Practice exercise

Build a dashboard shell with named grid areas and a responsive card section; use Flexbox inside each card for actions. Apply it to the example above and inspect the result at a narrow and a wide viewport.

Section summary

  • Named areas clarify page structure and intrinsic sizing helps tracks respond to content.
  • Keep source order meaningful and use Grid for macro structure with Flexbox for local one-axis alignment.

Knowledge check

Why use minmax(0, 1fr) for some flexible tracks?

Reveal the explanation

The zero minimum can prevent long intrinsic content from forcing a grid wider than its container.

Finish the module lessons, then take the server-scored module quiz to check your understanding.

Practical example

css
.demo {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 16rem;
  grid-template-areas: "main aside";
  gap: 1rem;
}

Expected result:

The named areas describe a main region beside a sidebar, while the flexible track can shrink without forcing overflow.

Hands-on practice task

Build a dashboard shell with named grid areas and a responsive card section; use Flexbox inside each card for actions.

In this section

Other lessons in Advanced Grid and Flexbox Layouts

Broaden your knowledge

Related learning topics