CSS grid-area Property

The CSS grid-area property is a shorthand that positions a grid item within a grid container using a named area or grid row and column lines.

It combines four grid placement properties into a single declaration, making it possible to control where an item begins and ends across rows and columns. The property is commonly used for page layouts, dashboards, featured content, and other designs that require precise placement of grid items.

grid-area Syntax

The grid-area property accepts a named grid area or up to four slash-separated values that define an item's grid boundaries.

Basic Syntax

selector {
  grid-area: auto;
}

Named Grid Area

.item {
  grid-area: main;
}

Four-Value Syntax

.item {
  grid-area: 1 / 2 / 3 / 4;
}

The values represent row start, column start, row end, and column end, in that order.

Two-Value Syntax

.item {
  grid-area: 2 / 3;
}

Three-Value Syntax

.item {
  grid-area: 1 / 2 / 4;
}

Spanning Tracks

.item {
  grid-area: 1 / 1 / span 2 / span 3;
}

Named Grid Lines

.item {
  grid-area: content-start / main-start / content-end / main-end;
}

CSS-Wide Keywords

.item {
  grid-area: initial;
}
.item {
  grid-area: inherit;
}
.item {
  grid-area: unset;
}
.item {
  grid-area: revert;
}
.item {
  grid-area: revert-layer;
}

The property applies to grid items. The parent container must establish a grid formatting context using display: grid or display: inline-grid.

Property Values

The grid-area shorthand accepts grid line positions, named areas, spans, and automatic placement values.

Value Description
auto Allows the grid placement algorithm to determine the relevant grid boundary or span.
<integer> References a numbered grid line. Zero is not a valid grid line number.
<custom-ident> References a named grid line or a named grid area through its associated line names.
span <integer> Specifies how many grid tracks an item spans.
span <custom-ident> Specifies a span using a named grid line.
inherit Inherits the corresponding grid placement values from the parent element.
initial Resets all four grid placement longhands to their initial values.
unset Resets the non-inherited grid placement properties to their initial values.

Property Characteristics

Characteristic Value
Initial value auto for all four longhand properties
Inherited No
Applies to Grid items and absolutely positioned boxes whose containing block is a grid container
Computed value See the individual longhand properties
Animation type Discrete
Percentages Not supported
Shorthand Yes, for four grid placement properties

The grid-area shorthand does not accept lengths such as 100px or percentages such as 50% as grid line positions.

Shorthand Properties

The grid-area property combines four longhand grid placement properties.

Longhand Property Purpose
grid-row-start Defines the starting row boundary.
grid-column-start Defines the starting column boundary.
grid-row-end Defines the ending row boundary.
grid-column-end Defines the ending column boundary.

Longhand Example

.item {
  grid-row-start: 1;
  grid-column-start: 2;
  grid-row-end: 3;
  grid-column-end: 4;
}

Equivalent Shorthand

.item {
  grid-area: 1 / 2 / 3 / 4;
}

Both examples place the item between row lines 1 and 3 and column lines 2 and 4.

Property Order

Position Property
First grid-row-start
Second grid-column-start
Third grid-row-end
Fourth grid-column-end

The shorthand follows a row, column, row, column sequence rather than grouping both row values together.

How It Works

CSS Grid divides a container into rows and columns separated by grid lines. The grid-area property identifies the boundaries occupied by a grid item.

Create a Grid Container

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 100px);
  gap: 10px;
}

Position an Item

.featured {
  grid-area: 1 / 1 / 3 / 3;
}

The item begins at row line 1 and column line 1, ending at row line 3 and column line 3.

Grid Lines and Tracks

A grid with three columns has four column lines. Likewise, three rows create four row lines.

Item Dimensions

The item's grid area determines the space allocated to it. The item's actual size and alignment can also be affected by properties such as align-self, justify-self, and its intrinsic dimensions.

Explicit and Implicit Tracks

Placement can reference lines outside the explicit grid. When necessary, the browser creates implicit tracks to accommodate the item.

Important Consideration

The grid-area property controls placement, not the size of the grid tracks themselves. Track sizing belongs to the grid container.

Named Grid Areas

Named grid areas provide a readable way to position items without specifying numeric grid lines.

Define Named Areas

.layout {
  display: grid;
  grid-template-areas:
    "header header"
    "sidebar main"
    "footer footer";
  grid-template-columns: 200px 1fr;
  grid-template-rows: 80px 1fr 60px;
}

Assign Grid Items

.header {
  grid-area: header;
}
.sidebar {
  grid-area: sidebar;
}
.main {
  grid-area: main;
}
.footer {
  grid-area: footer;
}

HTML Example

<div class="layout">
  <header class="header">Header</header>
  <aside class="sidebar">Sidebar</aside>
  <main class="main">Main Content</main>
  <footer class="footer">Footer</footer>
</div>

Area Names

Area names are custom identifiers. Names such as header, sidebar, and main are not special CSS keywords.

Rectangular Areas

Each named area must form a rectangle in the grid-template-areas definition.

Important Consideration

Named areas are particularly useful when the layout structure changes at different breakpoints. The same grid item can retain its name while the container changes the arrangement of its areas.

Grid Line Numbers

Numeric grid lines allow precise placement without defining named areas.

Single Cell

.item {
  grid-area: 1 / 1 / 2 / 2;
}

The item occupies the first row and first column.

Two Columns

.item {
  grid-area: 1 / 1 / 2 / 3;
}

Two Rows

.item {
  grid-area: 1 / 1 / 3 / 2;
}

Multiple Rows and Columns

.item {
  grid-area: 2 / 2 / 4 / 5;
}

Line Numbers Begin at One

Grid line numbering begins at 1 on the start side of the explicit grid. There is no line numbered zero.

Writing Direction

Column line numbering follows the inline direction of the grid container. In right-to-left layouts, the first column line is on the right.

Important Consideration

Grid line numbers refer to boundaries, not cells. A single track occupies the space between two adjacent grid lines.

Spanning Grid Tracks

The span keyword specifies how many tracks an item should occupy.

Span Two Columns

.item {
  grid-area: 1 / 1 / 2 / span 2;
}

Span Three Columns

.item {
  grid-area: 1 / 1 / 2 / span 3;
}

Span Two Rows

.item {
  grid-area: 1 / 1 / span 2 / 2;
}

Span Rows and Columns

.item {
  grid-area: 1 / 1 / span 2 / span 3;
}

Automatic Starting Position

.item {
  grid-area: auto / auto / span 2 / span 2;
}

The auto-placement algorithm determines the starting position while the item spans two rows and two columns.

Span Requirements

A numeric span must be a positive integer. A value such as span 0 or span -2 is invalid.

Important Consideration

Spanning items can create gaps in automatic placement. The final arrangement depends on available cells and the container's grid-auto-flow setting.

Named Grid Lines

Named grid lines allow placement using meaningful identifiers instead of numeric positions.

Define Named Lines

.container {
  display: grid;
  grid-template-columns:
    [sidebar-start] 200px
    [sidebar-end main-start] 1fr
    [main-end];
  grid-template-rows:
    [content-start] 200px
    [content-end];
}

Position Using Line Names

.item {
  grid-area: content-start / main-start / content-end / main-end;
}

Named Lines with Numbers

.item {
  grid-area: 1 / main-start / 2 / main-end;
}

Repeated Line Names

.container {
  display: grid;
  grid-template-columns:
    [col] 1fr
    [col] 1fr
    [col] 1fr
    [col];
}
.item {
  grid-column: col 2 / col 4;
}

When multiple lines share a name, an integer can identify a particular occurrence.

Implicit Area Line Names

A named area such as main creates associated line names including main-start and main-end on both axes.

Important Consideration

Named grid lines and named grid areas are related but distinct features. A single custom identifier in grid-area can use the area-style start and end line names even when no matching area was explicitly declared.

The auto Value

The auto keyword allows a grid placement boundary or span to be determined automatically.

Automatic Placement

.item {
  grid-area: auto;
}

All four longhand properties receive auto, allowing normal grid auto-placement.

Fixed Row with Automatic Column

.item {
  grid-area: 2 / auto / 3 / auto;
}

The item is assigned to the second row while its column placement is determined automatically.

Automatic End Lines

.item {
  grid-area: 1 / 1 / auto / auto;
}

With definite starting lines and automatic end values, the item normally spans one track in each direction.

Mixed Automatic and Explicit Placement

.item {
  grid-area: auto / 2 / auto / 4;
}

The item spans columns 2 through 3, while its row position is determined automatically.

Important Consideration

The auto keyword does not mean that an item fills all available grid space. Its result depends on the other placement values and the auto-placement algorithm.

Negative Grid Line Numbers

Negative line numbers count backward from the end edge of the explicit grid.

Last Explicit Column

.item {
  grid-column: -2 / -1;
}

Last Explicit Row

.item {
  grid-row: -2 / -1;
}

Full Explicit Grid Width

.item {
  grid-area: 1 / 1 / 2 / -1;
}

Last Grid Cell

.item {
  grid-area: -2 / -2 / -1 / -1;
}

Responsive Use

Negative line numbers are useful when the number of explicit tracks changes, because -1 continues to reference the end edge of the explicit grid.

Important Consideration

Negative line numbers are relative to the explicit grid, not necessarily the final edge of an implicit grid that grows beyond it.

Omitted Shorthand Values

The grid-area shorthand allows fewer than four values. Omitted values are determined according to the shorthand's expansion rules.

One Named Value

.item {
  grid-area: main;
}

When the supplied value is a custom identifier, omitted values use the same identifier, allowing the item to reference the corresponding named area boundaries.

One Numeric Value

.item {
  grid-area: 2;
}

The row start becomes line 2. The remaining three values default to auto.

Two Numeric Values

.item {
  grid-area: 2 / 3;
}

The row start is line 2 and the column start is line 3. Both ending values default to auto.

Three Numeric Values

.item {
  grid-area: 1 / 2 / 4;
}

The row start is line 1, the column start is line 2, and the row end is line 4. The column end defaults to auto.

Four Values

.item {
  grid-area: 1 / 2 / 4 / 5;
}

All four grid placement boundaries are specified explicitly.

Expansion Rules

Specified Values Omitted Values
One Column start, row end, and column end use the first custom identifier if one was supplied; otherwise they use auto.
Two Row end follows the first value if it is a custom identifier; column end follows the second value if it is a custom identifier. Otherwise each omitted value uses auto.
Three Column end follows the second value if it is a custom identifier; otherwise it uses auto.
Four No values are omitted.

Important Consideration

Custom identifiers receive special treatment when shorthand values are omitted. Numeric values and span expressions do not automatically repeat into the missing positions.

grid-area vs. grid-template-areas

The grid-area and grid-template-areas properties work together, but they serve different purposes.

grid-template-areas

.container {
  display: grid;
  grid-template-areas:
    "header header"
    "sidebar main";
  grid-template-columns: 200px 1fr;
}

The grid-template-areas property defines named regions on the grid container.

grid-area

.header {
  grid-area: header;
}
.sidebar {
  grid-area: sidebar;
}
.main {
  grid-area: main;
}

The grid-area property assigns individual items to those named regions.

Property Comparison

Feature grid-area grid-template-areas
Applied to Grid items Grid container
Primary purpose Positions an item Defines named areas
Numeric grid lines Supported Not used
Named areas References an area Defines an area
Shorthand Yes No

Important Consideration

Using grid-area: main does not automatically create a rectangular area named main in the container's template. Define named areas on the container when that placement method is intended.

Automatic Placement

Grid items without fully specified positions participate in the grid auto-placement algorithm.

Default Placement

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}
.item {
  grid-area: auto;
}

Items are placed into available cells according to the container's grid-auto-flow setting.

Automatic Row Placement

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-flow: row;
}

Automatic Column Placement

.container {
  display: grid;
  grid-template-rows: repeat(3, 100px);
  grid-auto-flow: column;
}

Partially Positioned Item

.item {
  grid-area: auto / 2 / auto / 3;
}

The item is assigned to the second column, while the browser determines its row position.

Dense Packing

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-flow: row dense;
}

Dense packing allows later auto-placed items to fill earlier gaps when their dimensions permit.

Important Consideration

Automatic placement can produce different arrangements when some items span multiple tracks. Test the resulting layout with realistic content.

Overlapping Grid Items

CSS Grid allows multiple items to occupy the same grid area. This can be useful for labels, overlays, and layered interface components.

Shared Grid Area

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 100px);
}
.background-item {
  grid-area: 1 / 1 / 4 / 4;
}
.overlay-item {
  grid-area: 2 / 2 / 3 / 3;
}

Layer Order

.background-item {
  grid-area: 1 / 1 / 4 / 4;
  z-index: 1;
}
.overlay-item {
  grid-area: 2 / 2 / 3 / 3;
  z-index: 2;
}

Named Overlay Area

.container {
  display: grid;
  grid-template-areas: "content";
}
.background-item,
.overlay-item {
  grid-area: content;
}

Both items occupy the same named grid area.

Important Consideration

Overlapping grid items can obscure text or interactive controls. Ensure that important content remains visible and accessible.

Responsive Layouts

The grid-area property is useful in responsive layouts because items can retain their area names while the grid structure changes.

Mobile Layout

.page-layout {
  display: grid;
  grid-template-areas:
    "header"
    "main"
    "sidebar"
    "footer";
  grid-template-columns: 1fr;
  gap: 16px;
}

Desktop Layout

@media (min-width: 900px) {
  .page-layout {
    grid-template-areas:
      "header header"
      "sidebar main"
      "footer footer";
    grid-template-columns: 240px 1fr;
  }
}

Assign Named Areas

.header {
  grid-area: header;
}
.sidebar {
  grid-area: sidebar;
}
.main {
  grid-area: main;
}
.footer {
  grid-area: footer;
}

Responsive Numeric Placement

.featured {
  grid-area: auto;
}
@media (min-width: 768px) {
  .featured {
    grid-area: 1 / 1 / 3 / 3;
  }
}

Important Consideration

Changing visual order does not change the source order. Keep headings, content, and interactive controls in a logical sequence in the HTML document.

grid-area Example

This example demonstrates how grid-area positions a featured item across multiple rows and columns in a three-column grid.

HTML Example

<div class="grid-area-demo">
  <div class="grid-item featured">Featured Item</div>
  <div class="grid-item">Item 2</div>
  <div class="grid-item">Item 3</div>
  <div class="grid-item">Item 4</div>
  <div class="grid-item">Item 5</div>
  <div class="grid-item">Item 6</div>
</div>

CSS Example

.grid-area-demo {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: 80px;
  gap: 12px;
}
.grid-area-demo .grid-item {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  background-color: #2456a6;
  color: #ffffff;
  font-weight: bold;
  border-radius: 4px;
}
.grid-area-demo .featured {
  grid-area: 1 / 1 / 3 / 3;
  background-color: #187a65;
}
Browser Result
Item 2
Item 3
Item 4
Item 5
Item 6

The featured item uses grid-area: 1 / 1 / 3 / 3, placing it across the first two rows and first two columns.

The remaining items are automatically positioned in available grid cells. The container's grid-auto-rows property gives each automatically generated row a height of 80 pixels.

Common Mistakes

Most problems with grid-area involve incorrect value order, misunderstanding grid lines, or applying the property outside a grid layout.

Using grid-area on a Non-Grid Item

.item {
  grid-area: 1 / 1 / 3 / 3;
}

The property requires an appropriate grid formatting context to affect normal grid item placement.

Using the Wrong Value Order

The correct order is row start, column start, row end, and column end.

Confusing Grid Lines with Cells

.item {
  grid-area: 1 / 1 / 2 / 2;
}

This occupies one grid cell, not two rows and two columns.

Using Zero as a Grid Line Number

.item {
  grid-area: 0 / 1 / 2 / 3;
}

Grid line number zero is invalid.

Using Length Values

.item {
  grid-area: 100px / 200px;
}

Grid placement uses line numbers, names, spans, or auto, not pixel dimensions.

Using Invalid Span Values

.item {
  grid-area: 1 / 1 / span 0 / span 2;
}

Numeric spans must be positive integers.

Using an Undefined Named Area

.item {
  grid-area: main;
}

If the container does not define the intended named area, the identifier can still participate in named-line resolution and implicit grid placement rather than simply selecting an existing area.

Assuming Visual Order Changes Document Order

Grid placement changes the visual arrangement but does not change the underlying HTML source order.

Overlapping Important Content

Items assigned to overlapping grid areas can cover one another. Review stacking order and content visibility.

Forgetting Responsive Adjustments

Fixed numeric placements may require changes when the grid has fewer columns on smaller screens.

Important Considerations

Keep the following points in mind when using the grid-area property:

  • Purpose: Positions a grid item using named areas or grid boundaries.
  • Shorthand: Combines four grid placement longhand properties.
  • Grid context: Used for placement in CSS Grid layouts.
  • Inheritance: The property is not inherited.
  • Initial values: All four longhands initially use auto.
  • Value order: Row start, column start, row end, column end.
  • Named areas: Can reference names established by grid-template-areas.
  • Named lines: Can reference explicit or implicitly named grid lines.
  • Numeric lines: Begin at 1, not zero.
  • Negative lines: Count backward from the end of the explicit grid.
  • Spanning: The span keyword defines how many tracks an item occupies.
  • Automatic placement: The auto keyword allows the browser to determine placement.
  • Omitted values: Follow shorthand expansion rules, including special handling for custom identifiers.
  • Track sizing: Controlled by the grid container rather than grid-area.
  • Grid gaps: Controlled separately using gap and related properties.
  • Overlapping: Multiple items can occupy the same grid area.
  • Stacking: The z-index property can control the stacking order of overlapping grid items.
  • Responsive layouts: Named areas can simplify layout changes at different breakpoints.
  • Source order: Visual placement does not change the document order.
  • Accessibility: Keep reading and keyboard navigation order logical.
  • Browser testing: Verify placement, track sizing, overflow, and overlapping content.

The grid-area shorthand provides a compact way to position grid items. Named areas are especially useful for readable page layouts, while numeric lines and spans provide precise control over individual items.

Browser Support

The CSS grid-area property has Widely available support in modern browsers as part of CSS Grid Layout.

Modern versions of Chrome, Edge, Firefox, Safari, and other major browsers support the standardized property, including named areas, numeric grid lines, and track spanning.

Standard Example

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}
.item {
  grid-area: 1 / 1 / 2 / 3;
}

Legacy Browser Considerations

Internet Explorer implemented an older, prefixed version of CSS Grid with different placement properties and syntax. Modern grid-area declarations are not compatible with that legacy implementation.

Browser Compatibility

For current compatibility details, visit Can I Use? and search for grid-area.

Specifications

The grid-area shorthand is defined in the CSS Grid Layout specification.

CSS Grid Layout Module Level 1: grid-area

The specification defines grid line placement, named grid areas, spanning behavior, and shorthand expansion rules.

CSS Grid Layout Module Level 2

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: grid-area