Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Grid

The grid-area property

Reference for the CSS grid-area property: place an item in a named template area, or set its row and column start and end lines in one declaration.

The grid-area property places a grid item. It has two jobs. With a single name, it puts the item into the area of that name defined by grid-template-areas. With up to four line values separated by slashes, it is a shorthand for grid-row-start, grid-column-start, grid-row-end and grid-column-end.

CSS
.sidebar { grid-area: side; }
.hero    { grid-area: 1 / 1 / 3 / 4; }  /* row-start / col-start / row-end / col-end */

Try it

Named areas

The items are written in a different order than the layout; each lands in its named area anyway.

Four line numbers

The hero starts at row line 1, column line 2, and ends before row line 3 and column line 5, so it covers two rows and three columns.

Syntax

CSS
grid-area: <grid-line> [ / <grid-line> ]{0,3};
/* grid-line: auto | <custom-ident> | [ <integer> && <custom-ident>? ] | [ span && [ <integer> || <custom-ident> ] ] */
  • Initial value: auto (for all four longhands)
  • Applies to: grid items and absolutely positioned boxes whose containing block is a grid area
  • Inherited: no
  • Animatable: no
  • Computed value: as specified for the longhands

Values

Value Description
<name> One identifier: the item fills the template area of that name.
<row-start> / <column-start> / <row-end> / <column-end> Four lines, in that order.
<integer> A line number. 1 is the first line; negative numbers count from the end.
span <n> Spans n tracks from the other line.
<line-name> The line with that name, from named lines or an area's -start / -end lines.
auto Auto-placement decides.

Usage notes

  • Order differs from margin. The order is row-start, column-start, row-end, column-end. That is top, left, bottom, right, not the clockwise margin order.
  • Omitted values. If you leave out the later values, they default to the same name when the earlier one is a name, otherwise to auto.
  • No matching area. If a single name matches no template area, it names the lines for the item instead; this usually means the item is not where you expect. Check the spelling.
  • Names are case-sensitive. Main and main are different.
  • Overlap is allowed. Items given overlapping areas stack; use z-index to control which is on top.
  • Source order and accessibility. Placement changes the visual order only, so keep the HTML in a sensible reading order.

Browser support

Supported in all current browsers.