CSS grid-template-areas

The grid-template-areas property in CSS allows you to define named grid areas for the rows and columns of your grid layout. This feature provides a convenient way to visually organize your grid layout and make it easier to understand and manage.

To use the grid-template-areas property, you need to create a grid container and specify the layout of the grid using area names. Each area name represents a cell in the grid layout, and you can use these names to place grid items within specific areas.

Let's see how the grid-template-areas property works with some examples:

Result:

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

In this example, we have defined a grid layout with three rows and three columns, with named areas for the header, sidebar, content, and footer sections. Each grid item is assigned to a specific area using the grid-area property.

By using named grid areas, you can easily rearrange and visualize the layout of your grid without having to adjust individual grid item properties.