Overlapping Grid Items
You'll learn how to create layered designs by placing multiple grid items in the same grid cells, making them stack on top of each other.
The Core Idea
Unlike traditional layouts where elements push each other around, CSS Grid allows multiple items to occupy the same grid cells simultaneously. When items share the same space, they naturally stack in layers, just like sheets of paper placed on top of each other. The item that appears later in your HTML sits on top, though you can control this with other CSS properties.
Think of it like a bulletin board: you can pin multiple photos or notes in overlapping positions to create an interesting visual composition.
Creating Overlaps
You create overlapping items by using grid-column and grid-row to place different items at the same coordinates:
.grid-container {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-template-rows: repeat(3, 100px);
}
.image {
grid-column: 1 / 4;
grid-row: 1 / 3;
}
.caption {
grid-column: 2 / 5;
grid-row: 2 / 4;
}
In this example, both items share cells in columns 2-3 and row 2. The .caption will appear on top of .image because it comes later in the HTML.
Common Use Cases
This technique shines for hero sections with overlaid text, image galleries with captions, decorative elements that peek behind content, or any design where layering creates visual interest. It's perfect for magazine-style layouts where text wraps over imagery.
Key Takeaway: You can intentionally place multiple grid items in the same cells to create overlapping, layered designs—later HTML elements stack on top of earlier ones.