CSS Fade Edge Mask

A horizontal scroller whose edges fade out with a mask gradient, hinting that there is more to scroll.

  • mask-image
  • scroll
  • overflow
  • carousel
  • fade out
HTML
<ul class="fade-edges" tabindex="0" aria-label="Topics">
  <li>Design</li>
  <li>Development</li>
  <li>Marketing</li>
  <li>Product</li>
  <li>Research</li>
  <li>Writing</li>
  <li>Sales</li>
  <li>Support</li>
</ul>
CSS
.fade-edges {
  --fade: 40px;
  display: flex;
  gap: 8px;
  width: min(100%, 300px);
  margin: 0;
  padding: 4px 0;
  overflow-x: auto;
  list-style: none;
  scrollbar-width: none;
  -webkit-mask: linear-gradient(90deg, #0000, #000 var(--fade), #000 calc(100% - var(--fade)), #0000);
  mask: linear-gradient(90deg, #0000, #000 var(--fade), #000 calc(100% - var(--fade)), #0000);
}

.fade-edges::-webkit-scrollbar {
  display: none;
}

.fade-edges li {
  flex: none;
  padding: 8px 14px;
  border-radius: 999px;
  background: #eef2ff;
  color: #3730a3;
  font: 600 14px/1 system-ui, sans-serif;
}

/* Drawn inside the box so the mask does not hide it */
.fade-edges:focus-visible {
  border-radius: 8px;
  outline: 2px solid #4f46e5;
  outline-offset: -2px;
}

About this CSS Fade Edge Mask

This CSS Fade Edge Mask is 33 lines of pure CSS (0.7 KB) with no JavaScript and no dependencies. It uses linear gradients, masks, Flexbox and keyboard focus styles. 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

Change these custom properties to restyle the fade edge mask without touching the rest of the CSS:

PropertyDefault
--fade40px

How to use this fade edge mask

  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 .fade-edges 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