The grid-area
property is a shorthand property in CSS Grid
Layout that allows you to specify where a grid item should be placed in a
grid. It works by defining the starting and ending points of a grid item.
Uuseful for creating layouts with fewer lines of code, since it combines
four separate properties: grid-row-start
,
grid-column-start
, grid-row-end
, and
grid-column-end
.
When using grid-area
with 4 values, the syntax is:
grid-area: row-start / column-start / row-end / column-end;
Each value means:
Example: grid-area: 2 / 3 / 5 / 6;
positions the item from
row line 2, column line 3 to row line 5, column line 6.
When using grid-area
with 3 values, the syntax is:
grid-area: row-start / column-start / row-end;
When only three values are provided:
auto
.
Example: grid-area: 2 / 3 / 5;
positions the item from row
line 2, column line 3 to row line 5, and spans one column.
When using grid-area
with 2 values, the syntax is:
grid-area: row-start / column-start;
When only two values are provided:
auto
.
Example: grid-area: 2 / 3;
positions the item at row line 2,
column line 3, spanning one row and one column.
Below is a 10×10 grid layout using the grid-area
property
with 4-value syntax to position elements: