OnlineCBT Logo OnlineCBT
CSS Tutorial
CSS · LESSON 32

Grid Template Areas

By Ratan Updated: 15 Oct 2026

Design visual page layouts effortlessly using named grid-template-areas.

Level: Beginner to Advanced
Duration: ~60 Mins Deep-Dive

Name regions to describe a page layout

grid-template-areas gives readable names to rectangular regions. Each quoted row describes cells; repeated names join into an area. Every named area must form one rectangle, and each row must contain the same number of cells.

.page {
  display: grid;
  grid-template-columns: 14rem minmax(0, 1fr);
  grid-template-areas:
    "header header"
    "sidebar main"
    "footer footer";
  gap: 1rem;
}
.header { grid-area: header; }
.sidebar { grid-area: sidebar; }
.main { grid-area: main; min-width: 0; }
.footer { grid-area: footer; }

Apply these classes to four direct children. The header and footer span both columns; sidebar and main occupy separate cells in the middle row. A dot can represent an unnamed empty cell.

Change the map for narrow screens

@media (max-width: 45rem) {
  .page {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "header"
      "main"
      "sidebar"
      "footer";
  }
}

The same elements now occupy a single column. Keep source order sensible: CSS placement changes the visual layout but does not automatically rewrite reading or focus order. If main content should precede the sidebar semantically, write the HTML accordingly.

Common errors

A nonrectangular area, inconsistent cell counts or a misspelled area name can invalidate the layout or place an item unexpectedly. Area names are identifiers; use clear names and keep the template and item declarations synchronized.

When areas help

Named areas are useful for a small set of stable page regions. For a large automatically generated catalogue, repeated tracks and auto-placement are often simpler. Choose the layout description that makes future edits understandable.

Exercises

  1. Add a notices region above main and decide whether it should span one or both columns.
  2. Deliberately create an L-shaped repeated name and inspect why it is invalid.
  3. Test the mobile map at 200% zoom and with long sidebar content.
  4. Compare the DOM order with visual order using keyboard navigation.

📝 Live Lesson Practice

HTML/CSS JavaScript Python C++ C PHP
⌨️ Practice Inputs (लाइव इनपुट भरें) (खाली होने पर RED, भरने पर GREEN underline)
💻 Code Editor (Monaco VS Code Engine)
👀 Live Preview
Address Contact

+91 7877547686

E-mail

onlinecbtportal@gmail.com

Helpline Number

+91 7877547686


Click To Download
Get it on Google Play

ऐप डाउनलोड करने
के लिए Google Play पर
उपलब्ध है

WhatsApp Chat