W3docs

CSS grid-template-areas Property

The grid-template-area CSS property is used to name grid items. Learn about the values and try examples.

The grid-template-areas property is used to define named grid areas by assigning names to grid cells. You can name grid items with the grid-area property. Each area is defined by double quotes. These areas may be referenced from such grid-placement properties as grid-row-start, grid-row-end, grid-column-end, grid-column-start as well as their shorthand properties, like grid-row, grid-area, and grid-column.

Initial Valuenone
Applies toGrid containers.
InheritedNo.
AnimatableYes. The property is animatable.
VersionCSS Grid Layout Module Level 1
DOM Syntaxobject.style.gridTemplateAreas = '"item1 item1 . ." "item1 item1 . ."';

Syntax

CSS grid-template-areas syntax

grid-template-areas: none | itemnames | initial | inherit;

Example of the grid-template-areas property:

CSS grid-template-areas code example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .box1 {
        grid-area: header;
      }
      .box2 {
        grid-area: menu;
      }
      .box3 {
        grid-area: main;
      }
      .box4 {
        grid-area: right;
      }
      .box5 {
        grid-area: footer;
      }
      .grid-container {
        display: grid;
        grid-template-areas: "header header header header header header" "menu main main main right right" "menu footer footer footer footer footer";
        gap: 10px;
        background-color: #ccc;
        padding: 10px;
      }
      .grid-container > div {
        background-color: #eee;
        text-align: center;
        padding: 20px 0;
        font-size: 30px;
      }
    </style>
  </head>
  <body>
    <h2>Grid-template-areas property example</h2>
    <div class="grid-container">
      <div class="box1">Header</div>
      <div class="box2">Menu</div>
      <div class="box3">Main</div>
      <div class="box4">Right</div>
      <div class="box5">Footer</div>
    </div>
  </body>
</html>

Result

CSS grid-template-areas another

Example of the grid-template-areas property, where an "item1" name is given to a grid item:

CSS grid-template-areas another code example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .box {
        grid-area: item1;
      }
      .grid-container {
        display: grid;
        grid-template-areas: "item1 item1 . . .";
        gap: 10px;
        background-color: #ccc;
        padding: 10px;
      }
      .grid-container > div {
        background-color: #eee;
        text-align: center;
        padding: 30px 0;
        font-size: 20px;
      }
    </style>
  </head>
  <body>
    <h2>Grid-template-areas property example</h2>
    <div class="grid-container">
      <div class="box">1</div>
      <div>2</div>
      <div>3</div>
      <div>4</div>
      <div>5</div>
      <div>6</div>
    </div>
  </body>
</html>

Values

ValueDescriptionPlay it
noneNo named grid areas will be defined. This is the default value of this property.Play it »
itemnamesA sequence of quoted strings that specify the grid areas.Play it »

Practice

Practice

What is the 'grid-template-areas' property in CSS used for?