Skip to main content

Scroll Fade

Edge-fade utilities for scroll containers. An edge with more content past it fades out. At the end of the scroll, or when nothing overflows, the edge stays fully opaque.

The fade is CSS only: a scroll-driven animation runs it.

note

A browser without animation-timeline: scroll() support (Firefox before 159) shows no fade. It never clips the content.

Both edges

Vertical (scroll-fade-y)

Fades the top and bottom edges of a vertically scrolling container. Scroll the list to see each edge fade in and out.

Horizontal (scroll-fade-x)

Fades the left and right edges of a horizontally scrolling container.

Single edge

To fade only one edge, use a single-edge utility. A sidebar, for example, can fade content under a sticky header and stay flush at the bottom. The opposite edge always stays fully opaque.

UtilityAxisFades
scroll-fade-tverticaltop edge
scroll-fade-bverticalbottom edge
scroll-fade-lhorizontalleft edge
scroll-fade-rhorizontalright edge

Use them exactly like the axis utilities: put the edge class on the scroll container. The sidebar example above becomes:

<nav className="scroll-fade-t h-full overflow-y-auto">{/* tall content */}</nav>

Each box below is pre-scrolled to its midpoint so the single faded edge stands out against the flush opposite edge.

Requirements

  • Apply the utility to the scroll container itself: the element that has overflow-x-auto or overflow-y-auto. The fade follows that element's own scroll position.
  • The utility sets mask-image, so don't put another mask-image on the same element.
  • The mask fades everything the element paints, border and background included. To fade the content of a visible card, put the border, the background, rounded-*, and overflow-hidden on a wrapper. Then put the fade utility on the inner scroll container, as the examples on this page do:
<div className="overflow-hidden rounded-lg border border-card bg-card">	<div className="scroll-fade-y h-56 overflow-y-auto">{/* tall content */}</div></div>