CSS Portal

CSS grid-template-areas Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The grid-template-areas property lets you define a visual template — a human-readable map — for laying out an element’s children inside a CSS Grid. Instead of thinking in terms of line numbers and spans, you give meaningful names to rectangular regions of the grid and describe how those regions fit together. This approach makes complex layouts easier to reason about and maintain because the arrangement is expressed as a spatial diagram rather than a set of numeric coordinates.

When you assign names in the template, child items can be placed by referring to those names, so placement becomes semantic: an item can claim the region named "sidebar" or "header" rather than being positioned by explicit start/end lines. Placing multiple items into the same named region results in them sharing that layout area (they are stacked in the same cells, subject to normal stacking rules). If a named area isn’t used by any child, it simply remains unused; conversely, a child that requests a name not present in the template won’t be positioned by the template and will follow the grid’s normal auto-placement behavior. You typically pair this property with explicit item placement using grid-area.

Because the template expresses the overall matrix of regions, it interacts with the grid’s track configuration and the fact that the element must be a grid container to take effect. The template determines how many columns and rows are considered when placing named regions, so it works together with the grid track sizing you set elsewhere (for example with grid-template-columns). Also, the property only affects elements that are using a grid layout, which you enable on the container via display. In practice, grid-template-areas is most powerful as a design-time and responsive tool: you can redefine the template at different breakpoints to rearrange large parts of the layout in a single, readable declaration.

Definition

Initial value
none
Applies to
Grid containers
Inherited
No
Computed value
As specified
Animatable
Yes
JavaScript syntax
object.style.gridTemplateAreas

Interactive Demo

One
Two
Three

Syntax

grid-template-areas : none | <string>+

Values

  • noneThe container does not define named areas of the grid layout. The default value.
  • <string>A row is created for every separate string listed, and a column is created for each cell in the string. Multiple named cell tokens within and between rows create a single named grid area that spans the corresponding grid cells. Unless those cells form a rectangle, the declaration is invalid.

Example

<div class="layout">
<header class="header">Header</header>
<aside class="sidebar">Sidebar</aside>
<main class="main">Main content</main>
<aside class="ads">Ads</aside>
<footer class="footer">Footer</footer>
</div>
:root {
  --gap: 16px;
}

* {
  box-sizing: border-box;
}

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
  margin: 0;
  padding: 20px;
  background: #f7f7f7;
}

.layout {
  display: grid;
  gap: var(--gap);
  grid-template-columns: 200px 1fr 200px;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    'header header header'
    'sidebar main ads'
    'footer footer footer';
  min-height: 70vh;
  background: #ffffff;
  padding: var(--gap);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.header {
  grid-area: header;
  background: #1f8ef1;
  color: #fff;
  padding: 16px;
  border-radius: 6px;
  font-weight: 600;
}

.sidebar {
  grid-area: sidebar;
  background: #f1f5f9;
  padding: 16px;
  border-radius: 6px;
}

.main {
  grid-area: main;
  background: #ffffff;
  padding: 16px;
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.04);
}

.ads {
  grid-area: ads;
  background: #fff7ed;
  padding: 16px;
  border-radius: 6px;
}

.footer {
  grid-area: footer;
  background: #101828;
  color: #fff;
  padding: 12px;
  text-align: center;
  border-radius: 6px;
}

@media (max-width: 700px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr auto auto;
    grid-template-areas:
      'header'
      'sidebar'
      'main'
      'ads'
      'footer';
  }
}

Browser Support

The following information will show you the current browser support for the CSS grid-template-areas property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!