grid-template-areas

Draft

Definition

The grid-template-areas CSS property is used in grid layouts to define the grid structure by assigning named grid areas to specific grid cells. It allows you to create complex grid layouts with designated areas for content placement.

The grid-template-areas property accepts a string value consisting of names enclosed in quotation marks or periods representing empty grid cells. Each row of the string corresponds to a grid row, and each character within a row represents a grid cell.

Here’s an example:

.grid-container {
  display: grid;
  grid-template-areas:
    "header header header"
    "sidebar content content"
    "footer footer footer";
}

In this example, the grid-template-areas rule defines a grid layout with three rows and three columns. The names “header”, “sidebar”, “content”, and “footer” represent the desired areas within the grid.

The layout indicates that the header area spans across all three columns in the first row, the sidebar area spans across the first column in the second row, and the content area spans across the second and third columns in the second row, and so on.

By assigning named areas to grid cells using grid-template-areas, you can create more structured and visually organized grid layouts. It provides flexibility in positioning and rearranging content within the grid.