🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Expert Masterclasses.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEcss

css Documentation

LOADING ENGINE...

CSS Grid Template Areas

Visualize your layout. Learn to use named areas to create complex, responsive 2D layouts with ease.

style.css
/* Grid Layout */
.container {
grid-template-areas:
"header header"
"sidebar main";
}
🏗️
layout.css
1 / 9
🏗️

Tutor:Grid Template Areas allow you to create semantic visual layouts. You name elements, then paint a map of your interface using strings.


Grid Mastery

Unlock nodes by learning layout structures.

Concept 1: The Container

CSS Grid Layout acts as a two-dimensional system. It starts with a container defined with display: grid.

System Check

Which property turns an element into a grid container?


Community Layouts

Share Grid Patterns

Created a cool dashboard layout? Share your template strings.

Enjoying this guide?

Codesyllabus is 100% free and open-source. Support our mission, pay for server infrastructure, and fuel new tutorials by buying us a coffee!

CSS Grid Template Areas

Author

Pascual Vila

Frontend Instructor.

The grid-template-areas property offers a visualization of your layout structure directly in your CSS. It allows you to name grid items and then place them into the grid container by referencing those names in a string format.

Naming Grid Items

Before you can use template areas, you must assign a name to the direct children of the grid container using the grid-area property.

.header { grid-area: hd; }
.sidebar { grid-area: sd; }
.main    { grid-area: mn; }

Defining the Layout

On the container, use grid-template-areas. Each string represents a row. Each word in the string represents a column.

.container {
  display: grid;
  grid-template-areas:
    "hd hd"
    "sd mn";
}

Handling Empty Spaces

If you need an empty cell in your grid, use a dot (.) or a series of dots. This allows for complex whitespace management without empty HTML elements.

Best Practices

Keep names short (like header, main, footer) to keep the ASCII art readable. Align your strings in the CSS file so the visual structure is apparent to other developers reading the code.

Grid Glossary

grid-template-areas
CSS property defined on the container that establishes the grid layout using named grid areas.
grid-area
CSS property defined on a child item to assign it a name that can be referenced by the template.
Grid Track
The space between two adjacent grid lines. Essentially the rows and columns of the grid.
Gap
The gutters between grid rows and columns.