Skip to main content
← 🎨 CSS as a design systemΒ·Module B3 Β· Lesson 6
TaskBuild a dashboard using grid-template-areas. .dashboard: display: grid, grid-template-columns: 200px 1fr, grid-template-rows: 60px 1fr 40px, grid-template-areas: 'header header' 'sidebar main' 'footer footer', min-height: 200px. Children: header.h, aside.s, main.m, footer.f β€” each assigned via grid-area.

grid-template-areas: named regions

100 XP9 min
Theory

Visual layout as ASCII

The most readable grid syntax in CSS:

.dashboard {
  display: grid;
  grid-template-columns: 200px 1fr;
  grid-template-rows: 60px 1fr 40px;
  grid-template-areas:
    "header  header"
    "sidebar main"
    "footer  footer";
  min-height: 100vh;
}
.dashboard > header { grid-area: header; }
.dashboard > .sidebar { grid-area: sidebar; }
.dashboard > .main { grid-area: main; }
.dashboard > footer { grid-area: footer; }

The strings inside grid-template-areas are the layout WIRE-FRAME. Each name marks a region. Then assign each child to a region with grid-area.

Why this is unbeatable for layouts

  • You can SEE the layout in the CSS.
  • Reordering means moving names around β€” no math.
  • Empty cell? Use . (a period).
  • Same area on multiple lines? It spans.
grid-template-areas:
  "header header header"
  "sidebar main main"
  "sidebar . extras"          /* . = empty cell */
  "footer footer footer";

Responsive: just rewrite the areas

@media (max-width: 700px) {
  .dashboard {
    grid-template-columns: 1fr;        /* stack everything */
    grid-template-areas:
      "header"
      "main"
      "sidebar"
      "footer";
  }
}

The CHILD selectors don't change. You just describe a new wire-frame for the smaller screen.

πŸ”’

Sign up to start coding

Theory is open to everyone. The interactive editor, live preview, and check are unlocked with a 7-day free trial β€” card required, cancel anytime.

Sign up β€” free trial β†’

First 10 lessons in each track are free. No card needed for those.

← PreviousNext lesson β†’

Get one Python or web tip a day β€” by email

Short, hand-written, no spam. Unsubscribe in one click.