CSS Caption Overlay Card
An image card with a dark gradient overlay that keeps the caption readable.
HTML
<a class="overlay-card" href="#">
<div class="overlay-media"></div>
<div class="overlay-text">
<small>Travel</small>
<strong>Morning in the hills</strong>
</div>
</a>
CSS
.overlay-card {
position: relative;
display: block;
overflow: hidden;
width: 220px;
height: 160px;
border-radius: 16px;
color: #fff;
text-decoration: none;
font-family: system-ui, sans-serif;
}
/* Swap the background for your own image */
.overlay-media {
position: absolute;
inset: 0;
background: #94a3b8 center / cover;
transition: transform 0.4s ease;
}
.overlay-card::after {
content: "";
position: absolute;
inset: 0;
background: linear-gradient(to top, rgba(0, 0, 0, 0.7), transparent 60%);
}
.overlay-card:hover .overlay-media {
transform: scale(1.06);
}
.overlay-text {
position: absolute;
z-index: 1;
left: 16px;
right: 16px;
bottom: 14px;
display: grid;
gap: 2px;
}
.overlay-text small {
opacity: 0.8;
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.overlay-text strong {
font-size: 16px;
}
About this CSS Caption Overlay Card
This CSS Caption Overlay Card is 51 lines of pure CSS (0.9 KB) with no JavaScript and no dependencies. It uses transitions, transforms, linear gradients 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
Customize it
The colors in this snippet. Search and replace them to match your brand:
#fff#94a3b8
How to use this caption overlay card
- 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
.overlay-cardclass 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.