Blur Fade
A blur fade-in animation for React and Tailwind CSS: content eases in from a soft blur and a small offset as it scrolls into view, with a group helper that staggers lists and grids. The server renders everything visible, so it stays SEO-friendly and never flashes content that is already on screen.
- Scroll-triggered
- Stagger groups
- SSR-safe, no flash
- Four directions
- prefers-reduced-motion
Release notes your team will read
Draft updates from merged pull requests, review them together and publish to your site in one step.
import { ArrowRight } from "lucide-react";
import { BlurFade, BlurFadeGroup } from "@/components/dusk/blur-fade/blur-fade";
export default function BlurFadeDemo() {
return (
<div className="w-full max-w-lg text-center">
<BlurFadeGroup stagger={0.1} className="flex flex-col items-center gap-4">
<span className="rounded-full border border-white/10 px-3 py-1 text-xs text-white/70">
Changelog
</span>
<h3 className="text-balance text-3xl font-semibold tracking-tight text-white sm:text-4xl">
Release notes your team will read
</h3>
<p className="max-w-sm text-balance text-sm leading-relaxed text-white/60">
Draft updates from merged pull requests, review them together and publish to your site in one
step.
</p>
<div className="flex gap-3">
<button
type="button"
className="inline-flex items-center gap-1.5 rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground"
>
Get started <ArrowRight className="size-4" aria-hidden />
</button>
<button type="button" className="rounded-md border border-white/15 px-4 py-2 text-sm font-medium text-white/80">
Docs
</button>
</div>
</BlurFadeGroup>
<BlurFade delay={0.55} className="mt-8 text-xs text-white/55">
Press replay to watch it again
</BlurFade>
</div>
);
}Installation
$ npx shadcn@latest add https://duskui.com/r/blur-fade.json1. Install the dependencies.
npm install motion2. Copy the source into
components/dusk/blur-fade/blur-fade.tsx.blur-fade.tsx "use client"; import * as React from "react"; import { animate, useReducedMotion, type DOMKeyframesDefinition } from "motion/react"; type BlurFadeTag = "div" | "span" | "section" | "article" | "li" | "p" | "figure" | "header" | "footer"; type Direction = "up" | "down" | "left" | "right" | "none"; export interface BlurFadeProps extends React.HTMLAttributes<HTMLElement> { /** Element to render. */ as?: BlurFadeTag; /** Where the content travels to: `up` starts below and rises into place. */ direction?: Direction; /** Travel distance in px. */ offset?: number; /** Starting blur in px. */ blur?: number; /** Seconds before the entrance starts. */ delay?: number; /** Seconds the entrance takes. */ duration?: number; /** `inView` plays when the element scrolls into view; `mount` plays as soon as it mounts. */ trigger?: "inView" | "mount"; /** IntersectionObserver root margin. Negative values wait until the element is further inside the viewport. */ inViewMargin?: string; /** How much of the element must be visible to start (0–1). */ amount?: number; /** Play only the first time. When `false` it hides again on leaving the viewport and replays on every entry. */ once?: boolean; } const EASE = [0.21, 0.47, 0.32, 0.98] as const; function hiddenFrame(direction: Direction, offset: number, blur: number): DOMKeyframesDefinition { const x = direction === "left" ? offset : direction === "right" ? -offset : 0; const y = direction === "up" ? offset : direction === "down" ? -offset : 0; return { opacity: 0, filter: `blur(${blur}px)`, transform: `translate3d(${x}px, ${y}px, 0)` }; } const SHOWN: DOMKeyframesDefinition = { opacity: 1, filter: "blur(0px)", transform: "translate3d(0px, 0px, 0)", }; /** `false` while React hydrates server HTML, `true` for any render that happens purely on the client. */ const noopSubscribe = () => () => {}; function useIsClientRender() { return React.useSyncExternalStore( noopSubscribe, () => true, () => false ); } /** Whether any part of the element is actually painted on screen, accounting for clipping scroll containers. */ function isOnScreen(el: Element) { const r = el.getBoundingClientRect(); let top = Math.max(r.top, 0); let left = Math.max(r.left, 0); let bottom = Math.min(r.bottom, window.innerHeight); let right = Math.min(r.right, window.innerWidth); for (let node = el.parentElement; node && node !== document.body; node = node.parentElement) { const style = getComputedStyle(node); if (style.overflowX !== "visible" || style.overflowY !== "visible") { const c = node.getBoundingClientRect(); top = Math.max(top, c.top); left = Math.max(left, c.left); bottom = Math.min(bottom, c.bottom); right = Math.min(right, c.right); } if (bottom <= top || right <= left || style.position === "fixed") break; } return bottom > top && right > left; } type GroupContextValue = { /** `null` until the group has been measured, so items never hide on a guess. */ inView: boolean | null; once: boolean; }; const BlurFadeGroupContext = React.createContext<GroupContextValue | null>(null); /** * Content fades in from a blur and a small offset when it enters the viewport * (or as soon as it mounts). * * The server renders the content fully visible, so crawlers and no-JS visitors * always get it. While hydrating, anything already on screen is left exactly as * painted (no flash of disappearing content); only content below the fold is * hidden, before it is ever seen, and animated in as it scrolls into view. * Client-side mounts (route changes, conditional renders) always animate, hidden * before the first paint. Animation runs through Motion on the element itself, * with no React state, and the blur is removed afterwards so it never traps * `position: fixed` or `backdrop-filter` children. Reduced motion shows * everything immediately. */ export function BlurFade({ as = "div", direction = "up", offset = 8, blur = 6, delay = 0, duration = 0.5, trigger = "inView", inViewMargin = "-40px", amount = 0, once = true, children, ...props }: BlurFadeProps) { const Comp = as as React.ElementType; const ref = React.useRef<HTMLElement>(null); const reduceMotion = useReducedMotion(); const clientRender = useIsClientRender(); const group = React.useContext(BlurFadeGroupContext); const groupInView = group?.inView; const replay = group ? !group.once : !once; // "init" until the first layout effect decides; then "hidden" (waiting) or "shown". const phase = React.useRef<"init" | "hidden" | "shown">("init"); // Runs before the browser paints this commit: hide what nobody has seen yet. React.useLayoutEffect(() => { const el = ref.current; if (!el || phase.current !== "init") return; if (reduceMotion || (!clientRender && isOnScreen(el))) { phase.current = "shown"; return; } phase.current = "hidden"; animate(el, hiddenFrame(direction, offset, blur), { duration: 0 }); }, [reduceMotion, clientRender, direction, offset, blur]); React.useEffect(() => { const el = ref.current; if (!el) return; let controls: ReturnType<typeof animate> | undefined; let running = false; const show = (instant: boolean) => { if (phase.current !== "hidden") return; phase.current = "shown"; running = true; el.style.willChange = "opacity, transform, filter"; controls = animate(el, SHOWN, instant ? { duration: 0 } : { duration, delay, ease: EASE }); controls.then(() => { running = false; if (phase.current !== "shown") return; // Remove the containing block that `filter`/`transform` create. el.style.filter = ""; el.style.transform = ""; el.style.willChange = ""; }); }; const hide = () => { if (phase.current !== "shown") return; stop(); phase.current = "hidden"; animate(el, hiddenFrame(direction, offset, blur), { duration: 0 }); }; // An interrupted entrance (prop change, Strict Mode re-run) goes back to // "hidden" so the next run picks it up from wherever it stopped. function stop() { if (!running) return; running = false; controls?.stop(); phase.current = "hidden"; } if (reduceMotion) { show(true); return stop; } if (group) { if (groupInView === true) show(false); else if (groupInView === false && replay) hide(); return stop; } if (trigger === "mount") { show(false); return stop; } const observer = new IntersectionObserver( ([entry]) => { if (entry.isIntersecting) { show(false); if (!replay) observer.disconnect(); } else if (replay) { hide(); } }, { rootMargin: inViewMargin, threshold: amount } ); observer.observe(el); return () => { observer.disconnect(); stop(); }; }, [reduceMotion, group, groupInView, replay, trigger, inViewMargin, amount, direction, offset, blur, delay, duration]); return ( <Comp ref={ref} data-slot="blur-fade" {...props}> {children} </Comp> ); } type GroupTag = "div" | "ul" | "ol" | "section"; export interface BlurFadeGroupProps extends Omit<React.HTMLAttributes<HTMLElement>, "children">, Pick<BlurFadeProps, "direction" | "offset" | "blur" | "duration" | "inViewMargin" | "amount" | "once"> { /** Container element. `ul`/`ol` wrap each child in an `li`. */ as?: GroupTag; /** Element wrapped around each child. Defaults to `li` inside lists, otherwise `div`. */ itemAs?: BlurFadeTag; /** Class name for every item wrapper (e.g. grid cell styles). */ itemClassName?: string; /** Seconds between consecutive children. */ stagger?: number; /** Seconds before the first child starts. */ delay?: number; /** `inView` waits for the group to scroll into view; `mount` plays immediately. */ trigger?: "inView" | "mount"; children: React.ReactNode; } /** * Staggers its children in with `BlurFade`. The group watches the viewport once * for all of them, so items in the same row never wait on each other and the * stagger always starts from the first child. Each child is wrapped in an item * element (`li` inside lists) that you can style with `itemClassName`. */ export function BlurFadeGroup({ as = "div", itemAs, itemClassName, stagger = 0.08, delay = 0, trigger = "inView", inViewMargin = "-40px", amount = 0, once = true, direction, offset, blur, duration, children, ...props }: BlurFadeGroupProps) { const Comp = as as React.ElementType; const ref = React.useRef<HTMLElement>(null); const [inView, setInView] = React.useState<boolean | null>(trigger === "mount" ? true : null); React.useEffect(() => { const el = ref.current; if (!el || trigger === "mount") return; const observer = new IntersectionObserver( ([entry]) => { setInView(entry.isIntersecting); if (entry.isIntersecting && once) observer.disconnect(); }, { rootMargin: inViewMargin, threshold: amount } ); observer.observe(el); return () => observer.disconnect(); }, [trigger, inViewMargin, amount, once]); const context = React.useMemo(() => ({ inView, once }), [inView, once]); const Item = itemAs ?? (as === "ul" || as === "ol" ? "li" : "div"); return ( <BlurFadeGroupContext.Provider value={context}> <Comp ref={ref} data-slot="blur-fade-group" {...props}> {React.Children.toArray(children).map((child, index) => ( <BlurFade key={React.isValidElement(child) && child.key != null ? child.key : index} as={Item} className={itemClassName} delay={delay + index * stagger} direction={direction} offset={offset} blur={blur} duration={duration} > {child} </BlurFade> ))} </Comp> </BlurFadeGroupContext.Provider> ); }
Usage
import { BlurFade, BlurFadeGroup } from "@/components/dusk/blur-fade/blur-fade"
export function Features() {
return (
<section>
<BlurFade as="h2" className="text-3xl font-semibold">
Built for speed
</BlurFade>
<BlurFadeGroup as="ul" stagger={0.08} className="grid gap-4 sm:grid-cols-3">
<FeatureCard title="Edge rendering" />
<FeatureCard title="Instant previews" />
<FeatureCard title="Zero config" />
</BlurFadeGroup>
</section>
)
}Examples
Directions
direction is where the content travels to: up rises into place, none only fades and un-blurs. Tune the distance with offset and the softness with blur.
"up""down""left""right""none"import { ArrowDown, ArrowLeft, ArrowRight, ArrowUp, Circle } from "lucide-react";
import { BlurFade } from "@/components/dusk/blur-fade/blur-fade";
const directions = [
{ direction: "up", Icon: ArrowUp },
{ direction: "down", Icon: ArrowDown },
{ direction: "left", Icon: ArrowLeft },
{ direction: "right", Icon: ArrowRight },
{ direction: "none", Icon: Circle },
] as const;
export default function BlurFadeDirections() {
return (
<div className="grid w-full max-w-2xl grid-cols-2 gap-3 sm:grid-cols-5">
{directions.map(({ direction, Icon }, i) => (
<BlurFade
key={direction}
direction={direction}
delay={i * 0.1}
className="flex flex-col items-center gap-3 rounded-xl border border-white/10 bg-white/[0.03] p-5"
>
<Icon className="size-5 text-white/60" aria-hidden />
<code className="font-mono text-xs text-white/70">"{direction}"</code>
</BlurFade>
))}
</div>
);
}Scroll gallery
Each tile animates as it enters its scroll container. With once={false} tiles hide again when they leave and replay on the way back.
Scroll down. Tiles replay every time they enter.
import { BlurFade } from "@/components/dusk/blur-fade/blur-fade";
const tones = ["bg-zinc-800", "bg-zinc-700/60", "bg-stone-800", "bg-neutral-800/80", "bg-zinc-800/70", "bg-stone-700/50"];
const shots = Array.from({ length: 18 }, (_, i) => ({
id: i + 1,
tone: tones[i % tones.length],
tall: i % 5 === 1 || i % 5 === 3,
}));
export default function BlurFadeScroll() {
return (
<div
role="region"
tabIndex={0}
aria-label="Scrollable gallery"
className="h-96 w-full max-w-xl overflow-y-auto overscroll-contain rounded-xl border border-white/10 bg-background p-4 outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50"
>
<p className="mb-4 text-center text-xs text-white/55">Scroll down. Tiles replay every time they enter.</p>
<div className="columns-2 gap-3 sm:columns-3">
{shots.map((shot, i) => (
<BlurFade
key={shot.id}
once={false}
delay={(i % 3) * 0.06}
inViewMargin="-24px"
className="mb-3 break-inside-avoid"
>
<div
className={`flex items-end rounded-lg border border-white/5 ${shot.tone} p-3 ${shot.tall ? "h-44" : "h-28"}`}
>
<span className="font-mono text-xs text-white/60">#{String(shot.id).padStart(2, "0")}</span>
</div>
</BlurFade>
))}
</div>
</div>
);
}Staggered group
BlurFadeGroup watches the viewport once for all its children and offsets each by stagger seconds. With as="ul" every child is wrapped in an li; style the wrappers with itemClassName.
- Server-rendered and visible without JavaScript
- No flash for content already on screen at load
- One observer for the whole group
- Blur removed when done, so fixed children still work
- Instant under prefers-reduced-motion
import { Check } from "lucide-react";
import { BlurFadeGroup } from "@/components/dusk/blur-fade/blur-fade";
const features = [
"Server-rendered and visible without JavaScript",
"No flash for content already on screen at load",
"One observer for the whole group",
"Blur removed when done, so fixed children still work",
"Instant under prefers-reduced-motion",
];
export default function BlurFadeList() {
return (
<BlurFadeGroup
as="ul"
stagger={0.07}
direction="right"
className="w-full max-w-md space-y-2"
itemClassName="flex items-center gap-3 rounded-lg border border-white/10 bg-white/[0.03] px-4 py-3 text-sm text-white/80"
>
{features.map((feature) => (
<span key={feature} className="contents">
<Check className="size-4 shrink-0 text-muted-foreground" aria-hidden />
{feature}
</span>
))}
</BlurFadeGroup>
);
}API Reference
BlurFade also accepts any HTML attribute for the rendered element. BlurFadeGroup takes direction, offset, blur, duration, trigger, inViewMargin, amount and once for all its children, plus the props marked “Group”.
| Prop | Type | Default | Description |
|---|---|---|---|
| as | "div" | "span" | "section" | "article" | "li" | "p" | … | "div" | Element to render. Group: "div" | "ul" | "ol" | "section". |
| direction | "up" | "down" | "left" | "right" | "none" | "up" | Where the content travels to as it appears. |
| offset | number | 8 | Travel distance in px. |
| blur | number | 6 | Starting blur in px. |
| delay | number | 0 | Seconds before the entrance (group: before the first child). |
| duration | number | 0.5 | Seconds the entrance takes. |
| trigger | "inView" | "mount" | "inView" | Play when scrolled into view, or as soon as it mounts. |
| inViewMargin | string | "-40px" | IntersectionObserver root margin. Negative values wait until the element is further inside. |
| amount | number | 0 | Share of the element (0–1) that must be visible to start. |
| once | boolean | true | Play only the first time; false hides on leave and replays on every entry. |
| stagger | number | 0.08 | Group: seconds between consecutive children. |
| itemAs | BlurFade as | "li" in lists, else "div" | Group: element wrapped around each child. |
| itemClassName | string | — | Group: class name for every item wrapper. |
Accessibility
- Content is rendered visible in the server HTML, so crawlers, no-JS visitors and assistive technology always get it.
- While hydrating, anything already on screen keeps its painted state; only content below the fold (or mounted later on the client) is hidden, before it is ever seen.
- Only opacity, transform and filter change, so layout never shifts. The blur and transform are removed afterwards and never trap position: fixed children.
- With prefers-reduced-motion the content appears immediately.
- Use
asto keep correct semantics, e.g.as="ul"on a group renders a real list.