Skip to content

CSS Grid Items

CSS grid items are the direct children of a grid container. Grid item properties control how each item is placed, aligned, stretched, and resized inside rows and columns.

What Are CSS Grid Items?

A grid item is any direct child of an element with display: grid; or display: inline-grid;. The parent creates the grid structure, and the children occupy the grid cells.

<div class="grid-container">
  <article class="grid-item">Item 1</article>
  <article class="grid-item">Item 2</article>
  <article class="grid-item">Item 3</article>
</div>
.grid-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.grid-item {
  padding: 1rem;
  border: 1px solid #dee2e6;
}

Why Grid Items Are Important

  • They control individual placement inside a grid layout.
  • They allow items to span multiple rows or columns.
  • They help create featured cards, dashboards, galleries, and magazine layouts.
  • They support item-level alignment with justify-self and align-self.
  • They work with named grid areas for readable page layouts.
  • They make responsive layouts easier to organize and maintain.

CSS Grid Items Cheatsheet

Property Example Purpose
grid-column grid-column: span 2; Makes an item span columns.
grid-row grid-row: span 2; Makes an item span rows.
grid-column-start grid-column-start: 1; Defines the starting column line.
grid-column-end grid-column-end: 3; Defines the ending column line.
grid-row-start grid-row-start: 1; Defines the starting row line.
grid-row-end grid-row-end: 3; Defines the ending row line.
grid-area grid-area: main; Places item into a named grid area.
justify-self justify-self: center; Aligns one item horizontally inside its cell.
align-self align-self: start; Aligns one item vertically inside its cell.
place-self place-self: center; Shorthand for align-self and justify-self.

Only Direct Children Become Grid Items

Grid item properties apply only to direct children of a grid container. Nested elements are not grid items unless their own parent also uses Grid.

<div class="grid">
  <article class="card">
    <h2>Card Title</h2>
    <p>Nested content</p>
  </article>
</div>
.grid {
  display: grid;
}

.card {
  grid-column: span 2;
}

grid-column

The grid-column property controls where a grid item starts and ends across columns.

.featured-card {
  grid-column: span 2;
}

This makes the item take two columns instead of one.

.hero-card {
  grid-column: 1 / 4;
}

This places the item from column line 1 to column line 4.

grid-row

The grid-row property controls where a grid item starts and ends across rows.

.tall-card {
  grid-row: span 2;
}

This makes the item take two rows.

grid-column-start, grid-column-end, grid-row-start, grid-row-end

These properties give precise control over where an item begins and ends.

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

The shorthand version is usually easier to read.

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

grid-area

The grid-area property places an item into a named grid area.

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

.header {
  grid-area: header;
}

.sidebar {
  grid-area: sidebar;
}

.main {
  grid-area: main;
}

.footer {
  grid-area: footer;
}

Named areas make large layouts easier to understand and maintain.

justify-self

The justify-self property aligns a single grid item horizontally inside its grid cell.

.item {
  justify-self: center;
}
Value Behavior
stretch Item stretches to fill the cell horizontally.
start Item aligns to the start of the cell.
center Item aligns in the center horizontally.
end Item aligns to the end of the cell.

align-self

The align-self property aligns a single grid item vertically inside its grid cell.

.item {
  align-self: start;
}

place-self

The place-self property is shorthand for align-self and justify-self.

.item {
  place-self: center;
}

This centers the item both vertically and horizontally inside its grid cell.

Dashboard Grid Item Example

Dashboard widgets often span different columns and rows.

.dashboard {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

.widget-large {
  grid-column: span 2;
  grid-row: span 2;
}

.widget-wide {
  grid-column: span 4;
}

CSS Grid Items and Accessibility

Grid item placement can change visual order, but keyboard and screen reader order still follow the HTML source order.

  • Keep HTML source order meaningful.
  • Avoid visual reordering that confuses users.
  • Use semantic HTML elements for page regions and cards.
  • Make sure spanning items remain readable on small screens.
  • Test keyboard navigation through grid-based layouts.

CSS Grid Items and SEO

Grid item properties do not directly affect rankings, but they improve layout quality, mobile usability, readability, accessibility, and content presentation.

  • Responsive grid items improve mobile-friendly design.
  • Featured items improve visual hierarchy.
  • Clean card layouts improve scanability.
  • Logical source order supports content clarity.
  • Semantic HTML with Grid supports better page structure.

Common CSS Grid Item Mistakes

  • Forgetting that only direct children are grid items.
  • Using spans that break on mobile screens.
  • Visually reordering important content without considering accessibility.
  • Using too many manual line numbers in large layouts.
  • Forgetting to reset featured item spans on small screens.
  • Confusing justify-self with justify-content.
  • Confusing align-self with align-content.

CSS Grid Item Best Practices

  • Use grid-column: span 2; for featured cards when space allows.
  • Reset large spans on mobile screens.
  • Use named grid areas for major page sections.
  • Use place-self for simple item-level alignment.
  • Keep source order logical and meaningful.
  • Use semantic HTML inside grid layouts.
  • Test grid items on mobile, desktop, and zoomed screens.
  • Use DevTools Grid inspector to debug placement issues.

Key Takeaways

  • Grid items are direct children of a grid container.
  • grid-column controls column placement and spanning.
  • grid-row controls row placement and spanning.
  • grid-area places items into named layout areas.
  • justify-self aligns one item horizontally.
  • align-self aligns one item vertically.
  • place-self is shorthand for both item alignment directions.
  • Responsive grid items should be tested carefully on small screens.

Pro Tip

For featured cards, use grid-column: span 2; on desktop, but reset to grid-column: span 1; on small screens to avoid broken layouts.