CSS Image Scrim Gradient

An eased dark gradient over a photo so white caption text stays readable without a hard edge.

  • overlay
  • text on image
  • readable
  • caption
  • eased
HTML
<figure class="scrim-card">
  <img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 300'%3E%3Cdefs%3E%3ClinearGradient id='g' x2='0' y2='1'%3E%3Cstop stop-color='%23fb923c'/%3E%3Cstop offset='1' stop-color='%23fde68a'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect width='400' height='300' fill='url(%23g)'/%3E%3Ccircle cx='290' cy='110' r='36' fill='%23fff7ed'/%3E%3Cpath d='M0 200 110 110l80 70 70-50 140 100v170H0z' fill='%237c3aed'/%3E%3Cpath d='M0 240 90 180l120 80 70-40 120 70v110H0z' fill='%233b0764'/%3E%3C/svg%3E" alt="Purple mountains at sunset">
  <figcaption>
    <strong>Sunset ridge trail</strong>
    <span>12 km · Moderate</span>
  </figcaption>
</figure>
CSS
.scrim-card {
  position: relative;
  width: min(100%, 280px);
  margin: 0;
  overflow: hidden;
  border-radius: 16px;
  font: 14px/1.3 system-ui, sans-serif;
}

.scrim-card img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
}

/* Many stops ease the fade, so there is no visible line where it starts */
.scrim-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to top,
    #000000b3 0%,
    #000000a1 14%,
    #00000080 28%,
    #00000059 42%,
    #00000033 56%,
    #00000014 70%,
    #0000 85%
  );
}

.scrim-card figcaption {
  position: absolute;
  inset: auto 0 0;
  z-index: 1;
  display: grid;
  gap: 2px;
  padding: 16px;
  color: #fff;
}

.scrim-card strong {
  font-size: 18px;
}

.scrim-card span {
  color: #e5e7eb;
}

About this CSS Image Scrim Gradient

This CSS Image Scrim Gradient is 50 lines of pure CSS (0.8 KB) with no JavaScript and no dependencies. It uses linear gradients, CSS Grid and aspect-ratio. 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:

  • #000000b3
  • #000000a1
  • #00000080
  • #00000059
  • #00000033
  • #00000014
  • #0000
  • #fff
  • #e5e7eb

How to use this image scrim gradient

  1. Copy the HTML and paste it where you want the element to appear.
  2. Copy the CSS into your stylesheet, or inside a <style> tag.
  3. Keep the .scrim-card class name, or rename it in both places. Then tweak colors, sizes and timing to match your design.
  4. Using React or Next.js? Change class to className in 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.

Feedback