Scroll Fade

Utilities for scroll-aware fading at the edges of overflow containers.

Loading preview…

Installation

Usage

These class helpers use the utilities shipped in shadcn-svelte/tailwind.css. The design system Styles already imports them. In other projects, add this once to your global CSS:

1@import "tailwindcss";
2@import "shadcn-svelte/tailwind.css";
1<script lang="ts">
2  import { scrollFadeClass } from "~/lib/scroll-fade";
3</script>
4
5<div class="overflow-hidden rounded-xl border">
6  <div class={`${scrollFadeClass} max-h-48`}>
7    <!-- Scrollable content -->
8  </div>
9</div>

Put borders and backgrounds on an outer wrapper so the mask only fades the content. Class helpers include overflow behavior; direct CSS classes can also be used in markup.

ClassEffect
scroll-fade / scroll-fade-yFade vertical edges
scroll-fade-xFade horizontal edges
scroll-fade-t, -b, -l, -rFade a physical edge
scroll-fade-s, -eFade logical inline edges, including RTL
scroll-fade-<n>Set fade depth using the spacing scale
scroll-fade-noneDisable fading

Exports include scrollFadeClass, scrollFadeYClass, scrollFadeXClass, scrollFadeEdgeClasses, scrollFadeSizeClasses, and scrollFadeNoneClass. Helpers contain complete literal class names that Tailwind can detect. Browsers with scroll timelines reveal fades as content scrolls; browsers without them use static edge masks.

Upstream Scroll Fade documentation.