A fade-based alternative to scroll shadows

Scroll shadows have long been a reliable way to signal that a container holds more content than it shows. The classic implementation layers background gradients with different attachments so the shadow disappears once you reach an edge. A newer approach ties CSS animation to scroll position through animation-timeline, rendering the shadows in pseudo-elements and animating their opacity with animation-range.

This technique takes a different route: rather than drawing shadows, a CSS mask fades the edges of the scrollable element itself. The visual metaphor differs, and it suits horizontally scrollable elements that have no border of their own — think the familiar table that can't be made responsive and must scroll sideways on mobile. Because the effect is a fade rather than an overlay, it reads correctly on both dark and light backgrounds.

Starting from the mask

Begin with the scrollable element and give it a mask that fades out the container's start and end. The shorthand takes a linear gradient that disappears at either end; the table then fades into the background instead of sitting under a shadow. The same technique transfers directly to shadows if that's the look you want.

.scrollable {
  mask: linear-gradient(to right, #0000, #ffff 3rem calc(100% - 3rem), #0000);
}

Custom properties and the animation

Next, declare two custom properties, --left-fade and --right-fade, with @property. Registration matters here: browsers can only interpolate a property when its syntax is specified.

@property --left-fade {
  syntax: "<length>";
  inherits: false;
  initial-value: 0;
}

@property --right-fade {
  syntax: "<length>";
  inherits: false;
  initial-value: 0;
}

@keyframes scrollfade {
  0% {
    --left-fade: 0;
  }
  10%, 100% {
    --left-fade: 3rem;
  }
  0%, 90% {
    --right-fade: 3rem;
  }
  100% {
    --right-fade: 0;
  }
}

A single animation is enough — no multiple animations, no animation-range. Between 0-10% of the timeline, --left-fade moves from 0 to 3rem; between 90-100%, --right-fade moves from 3rem to 0. The mask is then updated to consume both custom properties, and the element's own scroll-timeline is bound to its animation-timeline.

Behavior and browser support

With those pieces combined, the effect is complete.

Safari has yet to support animation-timeline. In browsers without it, the fallback is graceful: the element simply doesn't fade. The approach also transfers to scroll-snap carousels and card rows, requires no JavaScript, and is independent of both content and background.