CSS Grid Stack Overlay
Layer badges and captions over an image by placing everything in one grid cell. No absolute positioning.
HTML
<figure class="stack">
<div class="stack-media"></div>
<span class="stack-badge">New</span>
<figcaption>Golden hour</figcaption>
</figure>
CSS
.stack {
display: grid;
margin: 0;
}
/* Every child shares the same cell */
.stack > * {
grid-area: 1 / 1;
}
/* Use an <img> here in real projects */
.stack-media {
min-height: 140px;
border-radius: 14px;
background: #d4d4d8;
object-fit: cover;
}
.stack-badge {
align-self: start;
justify-self: end;
margin: 10px;
padding: 4px 10px;
border-radius: 999px;
background: #18181b;
color: #fff;
font: 700 11px system-ui, sans-serif;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.stack figcaption {
align-self: end;
justify-self: start;
margin: 10px;
padding: 6px 12px;
border-radius: 999px;
background: rgba(255, 255, 255, 0.85);
-webkit-backdrop-filter: blur(6px);
backdrop-filter: blur(6px);
color: #18181b;
font: 600 13px system-ui, sans-serif;
}
About this CSS Grid Stack Overlay
This CSS Grid Stack Overlay is 43 lines of pure CSS (0.8 KB) with no JavaScript and no dependencies. It uses backdrop filters and CSS Grid. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.
CSS features used
- backdrop filtersIncludes the -webkit- prefix for older Safari.
- CSS Grid
Customize it
The colors in this snippet. Search and replace them to match your brand:
#d4d4d8#18181b#fff
How to use this grid stack overlay
- Copy the HTML and paste it where you want the element to appear.
- Copy the CSS into your stylesheet, or inside a
<style>tag. - Keep the
.stackclass name, or rename it in both places. Then tweak colors, sizes and timing to match your design. - Using React or Next.js? Change
classtoclassNamein the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).
Building with an AI tool?
“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.