Course contentsShow
← Web Development
Lesson 356 of 2,9826. CSS GridFree lesson

Overlapping Grid Items

Intentionally placing items in overlapping cells and controlling z-index stacking.

Overlapping Grid Items

What you'll learn: How to intentionally place grid items in the same cells so they overlap, and control which item appears on top.

The Core Idea

Unlike traditional layouts where elements sit neatly beside each other, CSS Grid lets you place multiple items in the same grid cells. When you do this, they stack on top of each other like layers of paper. By default, items later in the HTML source appear on top, but you control the stacking order using the z-index property.

Think of it like arranging photos on a desk—you can place one partially over another, and decide which should be on top of the pile.

How It Works

You create overlaps by using line-based placement to position different items in the same grid space:

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

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

.item-two {
  grid-column: 2 / 4;
  grid-row: 2 / 4;
  z-index: 2; /* This item appears on top */
}

Here, both items occupy column 2 and row 2—they overlap. The z-index determines which is visible on top (higher numbers = closer to you).

Common Use Cases

Overlapping is perfect for image captions over photos, decorative elements layered behind content, or hero sections with text overlaying background images—all without needing absolute positioning.

Key Takeaway: Grid items can occupy the same cells and stack like layers; use z-index to control which item appears on top, enabling sophisticated overlapping layouts.