grid-template-areas property represents named areas withing a grid. These grid areas may consist of more than one cells. These named grid areas are used by other grid properties to place the items.
grid-template-columns: 90px 1fr 100px;
grid-template-rows: 150px 1fr 120px;
grid-template-areas: "h h h"
"a b c"
"f f f";
What is grid area?
A grid area covers up one on more adjacent cells and is bounded by four grid lines. It may contain one or more items. Number of cells in a grid area determine the size of grid area.
It gives us an idea about the structure i.e. how many rows and column are in the grid.
grid-template-areas = strings+ | none
strings+ = space separated list of strings
The value of grid-template-areas is none or space separated list of strings. The following are the values of a grid-template-areas.
It represents that no named grid area is created and thus there is no track.
The value of grid-template-areas consists of space separated strings. This set of string also represents a structural view of a grid. Each string represents one row. And each cell or token within that string represents a column
There are few rules that need to be considered while using string as the value.
A string consists of space separated named tokens (area names) within double quotationa marks.
Sequence of dots ('.') in a string means a null area.
Spaces are nothing to do but separate the named areas.
Any other characters used as the token names create null areas.
The named tokens in a string that start with numbers such as "5th 6th 7th" have to be escaped while using their names in other properties such as \35th means 5th area.
It is applicable to all of the elements including pseudo elements (::before, ::after, ::marker).
The grid-template-areas property has been covered up completely. If you are an advanced learner and want to get more on grid-template-areas property, continue to the remaining part otherwise skip to the next tutorial.
There are two methods to place the items within a grid.