← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

CSS Grid Template Areas

frontend Beginner

Also Known As

grid-template-areas grid areas named grid areas grid-area

TL;DR

A CSS Grid feature that lets you name regions of a grid and assign elements to them by name, making complex layouts readable and maintainable without calculating column/row numbers.

Explanation

Grid template areas use ASCII art to define a layout visually in CSS. The `grid-template-areas` property on the container accepts a string per row, with each word representing one grid cell. Repeated words span multiple cells. A dot (`.`) represents an empty cell. Child elements are assigned to areas using `grid-area: name`. This approach decouples the visual layout from the DOM order and column/row counting, making it easy to create responsive layouts by redefining areas at breakpoints. Unlike `grid-column: 2 / 4` shorthand, area names are self-documenting. The feature also implicitly defines `grid-template-rows` and `grid-template-columns` line names based on area boundaries — each area creates `-start` and `-end` named lines automatically.

Diagram

flowchart TD
    subgraph grid-template-areas
        H[header header header]
        S[sidebar main aside]
        F[footer footer footer]
    end
    subgraph Mobile breakpoint
        MH[header]
        MM[main]
        MS[sidebar]
        MA[aside]
        MF[footer]
    end
style H fill:#1f6feb,color:#fff
style F fill:#238636,color:#fff
style MH fill:#1f6feb,color:#fff
style MF fill:#238636,color:#fff

Common Misconception

Grid template areas are only useful for simple page layouts — they work equally well for component-level layouts like card grids, dashboard widgets, and form layouts, and they shine most when layouts need to rearrange at different breakpoints.

Why It Matters

Layouts defined with column/row numbers are fragile — inserting a column breaks all subsequent placements. Named areas make layouts self-documenting, easy to rearrange at breakpoints, and immediately understandable in code review.

Common Mistakes

  • Defining a non-rectangular area — grid template areas must always form a rectangle; an L-shape or T-shape is invalid and silently ignored.
  • Mismatching the number of columns across rows — every row string must define the same number of cells.
  • Using the same area name in non-contiguous cells — an area must be a single contiguous rectangle.
  • Forgetting to set `display: grid` on the parent before using `grid-template-areas`.

Code Examples

💡 Note
The mobile breakpoint completely reorders the layout — sidebar moves below main — by redefining area strings, with no changes to the HTML or element selectors.
✗ Vulnerable
/* Hard to read — pure column/row numbers */
.layout {
    display: grid;
    grid-template-columns: 200px 1fr 200px;
    grid-template-rows: 60px 1fr 40px;
}
.header  { grid-column: 1 / 4; grid-row: 1; }
.sidebar { grid-column: 1;     grid-row: 2; }
.main    { grid-column: 2;     grid-row: 2; }
.aside   { grid-column: 3;     grid-row: 2; }
.footer  { grid-column: 1 / 4; grid-row: 3; }
✓ Fixed
/* Self-documenting with named areas */
.layout {
    display: grid;
    grid-template-columns: 200px 1fr 200px;
    grid-template-rows: 60px 1fr 40px;
    grid-template-areas:
        'header  header  header'
        'sidebar main    aside'
        'footer  footer  footer';
}
.header  { grid-area: header;  }
.sidebar { grid-area: sidebar; }
.main    { grid-area: main;    }
.aside   { grid-area: aside;   }
.footer  { grid-area: footer;  }

/* Responsive: redefine areas at breakpoint */
@media (max-width: 768px) {
    .layout {
        grid-template-columns: 1fr;
        grid-template-areas:
            'header'
            'main'
            'sidebar'
            'aside'
            'footer';
    }
}

Added 24 Mar 2026
Views 40
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 1 ping M 2 pings T 0 pings W 0 pings T 1 ping F 2 pings S 0 pings S 0 pings M 0 pings T 1 ping W 1 ping T 1 ping F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T
No pings yet today
No pings yesterday
Amazonbot 12 Perplexity 9 Google 7 ChatGPT 3 Unknown AI 3 Meta AI 1 Ahrefs 1
crawler 35 crawler_json 1
DEV INTEL Tools & Severity
🟢 Low ⚙ Fix effort: Low
⚡ Quick Fix
Replace `grid-column`/`grid-row` number placements with `grid-template-areas` on the parent and `grid-area: name` on children
📦 Applies To
web
🔗 Prerequisites
🔍 Detection Hints
Multiple grid-column and grid-row numeric placements across sibling elements that could be replaced with named areas
Auto-detectable: ✗ No
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: Medium ✗ Manual fix Fix: Low Context: File

✓ schema.org compliant