Blur Panel
A React backdrop-blur panel for sticky headers, floating toolbars and sidebars. Built with Motion's useScroll and Tailwind CSS, its blur, saturation and tint fade in as the page scrolls — without re-rendering — and it falls back to a solid fill where backdrop-filter isn't available.
- Scroll-linked blur
- Sticky header
- Intensity presets
- No re-renders
- Any landmark element
Journal
Notes on interface design
Designing with light
As the page scrolls, the header picks up blur, saturation and tint — the colors underneath stay visible without hurting legibility.
Motion that respects users
As the page scrolls, the header picks up blur, saturation and tint — the colors underneath stay visible without hurting legibility.
The case for glass
As the page scrolls, the header picks up blur, saturation and tint — the colors underneath stay visible without hurting legibility.
"use client";
import * as React from "react";
import { BlurPanel } from "@/components/dusk/glass/blur-panel";
const posts = [
{ title: "Designing with light", tone: "from-amber-300 to-rose-400" },
{ title: "Motion that respects users", tone: "from-sky-400 to-indigo-500" },
{ title: "The case for glass", tone: "from-teal-400 to-sky-500" },
];
export default function BlurPanelDemo() {
const scroller = React.useRef<HTMLDivElement>(null);
return (
<div
ref={scroller}
role="region"
tabIndex={0}
aria-label="Scroll the preview to frost the header"
className="relative h-80 w-full max-w-lg overflow-y-auto overscroll-contain rounded-xl border border-white/10 bg-background outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50"
>
<BlurPanel
as="header"
container={scroller}
className="sticky top-0 z-10 flex h-14 items-center justify-between px-4"
>
<span className="font-semibold tracking-tight">
dusk.blog
</span>
<nav aria-label="Demo" className="flex gap-4 text-sm text-white/75">
<a href="#" onClick={(e) => e.preventDefault()} className="rounded-sm hover:text-white focus-visible:outline-2">
Articles
</a>
<a href="#" onClick={(e) => e.preventDefault()} className="rounded-sm hover:text-white focus-visible:outline-2">
About
</a>
</nav>
</BlurPanel>
{/* Pulled up under the header so it starts transparent over the hero. */}
<div className="-mt-14">
<div className="h-44 bg-slate-700 px-5 pt-20">
<p className="text-xs font-medium text-white/70">Journal</p>
<h3 className="mt-1 text-2xl font-semibold tracking-tight">Notes on interface design</h3>
</div>
<div className="space-y-4 p-4">
{posts.map((post) => (
<article key={post.title} className="flex gap-4 rounded-lg border border-white/10 p-3">
<div className={`size-20 shrink-0 rounded-md bg-linear-to-br ${post.tone}`} />
<div>
<h4 className="font-medium">{post.title}</h4>
<p className="mt-1 text-sm leading-relaxed text-white/60">
As the page scrolls, the header picks up blur, saturation and tint — the colors
underneath stay visible without hurting legibility.
</p>
</div>
</article>
))}
</div>
</div>
</div>
);
}Installation
$ npx shadcn@latest add https://duskui.com/r/blur-panel.json1. Install the dependencies.
npm install motion2. Copy the source into
components/dusk/glass/blur-panel.tsx.blur-panel.tsx "use client"; import * as React from "react"; import { motion, useScroll, useTransform } from "motion/react"; import { cn } from "@/lib/utils"; const elements = { div: motion.div, header: motion.header, nav: motion.nav, aside: motion.aside, footer: motion.footer, section: motion.section, }; const intensities = { subtle: 0.35, medium: 0.65, strong: 1 } as const; const edges = { top: "inset-x-0 top-0 h-px bg-linear-to-r", bottom: "inset-x-0 bottom-0 h-px bg-linear-to-r", left: "inset-y-0 left-0 w-px bg-linear-to-b", right: "inset-y-0 right-0 w-px bg-linear-to-b", } as const; export interface BlurPanelProps extends Omit< React.ComponentProps<"div">, "onDrag" | "onDragStart" | "onDragEnd" | "onAnimationStart" > { /** Element to render. Use `header`, `nav` or `aside` to get the right landmark. */ as?: keyof typeof elements; /** How frosted the panel gets: a preset or a number from 0 to 1. */ intensity?: keyof typeof intensities | number; /** * Scroll distance in px over which the glass fades in, as `[start, end]`. * Pass `false` for a panel that is always frosted (e.g. a sidebar). */ scrollRange?: [number, number] | false; /** Scroll container to watch. Defaults to the page. */ container?: React.RefObject<HTMLElement | null>; /** Which side gets the hairline edge as the panel frosts. */ edge?: keyof typeof edges | "none"; } /** * A panel whose backdrop blur, saturation and tint fade in as the page scrolls. * Make it a sticky header, a floating toolbar or a sidebar with `className` * (e.g. `sticky top-0`). * * Scroll is read through motion values and written to CSS variables, so * scrolling never re-renders React. Without `backdrop-filter` support the * panel fades to a near-opaque fill instead, keeping its content readable. */ export function BlurPanel({ as = "div", intensity = "medium", scrollRange = [0, 80], container, edge = "bottom", className, style, children, ...props }: BlurPanelProps) { const level = Math.min( 1, Math.max(0, typeof intensity === "number" ? intensity : intensities[intensity]) ); const maxBlur = 4 + 20 * level; const maxTint = 25 + 50 * level; const maxSaturate = 80 * level; const { scrollY } = useScroll(container ? { container } : undefined); const progress = useTransform(scrollY, (y) => { if (!scrollRange) return 1; const [start, end] = scrollRange; if (end <= start) return y >= start ? 1 : 0; return Math.min(1, Math.max(0, (y - start) / (end - start))); }); const blur = useTransform(progress, (p) => `${(p * maxBlur).toFixed(2)}px`); const saturate = useTransform(progress, (p) => `${(100 + p * maxSaturate).toFixed(1)}%`); const tint = useTransform(progress, (p) => `${(p * maxTint).toFixed(1)}%`); const fallbackTint = useTransform(progress, (p) => `${(p * 94).toFixed(1)}%`); const shadow = useTransform(progress, (p) => (p * 0.45).toFixed(3)); const Comp = elements[as]; return ( <Comp data-slot="blur-panel" className={cn( "relative isolate text-foreground", // Fallback first: no backdrop-filter → fade to a near-opaque fill. "bg-[color-mix(in_oklab,var(--background)_var(--panel-fallback),transparent)]", "supports-[backdrop-filter]:bg-[color-mix(in_oklab,var(--background)_var(--panel-tint),transparent)]", "supports-[backdrop-filter]:backdrop-blur-(--panel-blur) supports-[backdrop-filter]:backdrop-saturate-(--panel-saturate)", "shadow-[0_8px_32px_-12px_rgb(0_0_0/var(--panel-shadow))]", className )} style={ { "--panel-blur": blur, "--panel-saturate": saturate, "--panel-tint": tint, "--panel-fallback": fallbackTint, "--panel-shadow": shadow, ...style, } as React.ComponentProps<typeof motion.div>["style"] } {...props} > {edge !== "none" && ( <motion.span aria-hidden className={cn( "pointer-events-none absolute from-transparent via-white/25 to-transparent", edges[edge] )} style={{ opacity: progress }} /> )} {children} </Comp> ); }
The panel doesn't position itself — add sticky top-0, fixed or whatever your layout needs through className.
Usage
import { BlurPanel } from "@/components/dusk/glass/blur-panel"
export function SiteHeader() {
return (
<BlurPanel as="header" className="sticky top-0 z-40 flex h-16 items-center px-6">
<Logo />
<Nav />
</BlurPanel>
)
}Examples
Floating toolbar
Set scrollRange={false} for a panel that is always frosted, and edge="none" when the shape is rounded. Here a strong, pill-shaped toolbar floats over a scrolling photo grid.
import { Crop, Heart, Share2, SlidersHorizontal, Trash2 } from "lucide-react";
import { Button } from "@/components/ui/button";
import { BlurPanel } from "@/components/dusk/glass/blur-panel";
const tiles = [
"from-amber-300 to-rose-500",
"from-sky-400 to-violet-600",
"from-teal-300 to-teal-600",
"from-fuchsia-500 to-indigo-600",
"from-lime-300 to-emerald-600",
"from-orange-400 to-pink-600",
"from-cyan-300 to-blue-600",
"from-rose-400 to-purple-700",
"from-yellow-300 to-orange-600",
];
const tools = [
{ label: "Adjust", icon: SlidersHorizontal },
{ label: "Crop", icon: Crop },
{ label: "Favorite", icon: Heart },
{ label: "Share", icon: Share2 },
{ label: "Delete", icon: Trash2 },
];
export default function BlurPanelToolbar() {
return (
<div
role="region"
tabIndex={0}
aria-label="Photo grid"
className="relative h-80 w-full max-w-md overflow-y-auto overscroll-contain rounded-xl border border-white/10 bg-background p-2 outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50"
>
<div className="grid grid-cols-3 gap-2 pb-16">
{[...tiles, ...tiles].map((tone, i) => (
<div key={i} className={`aspect-square rounded-md bg-linear-to-br ${tone}`} />
))}
</div>
<BlurPanel
as="nav"
aria-label="Photo tools"
scrollRange={false}
intensity="strong"
edge="none"
className="sticky bottom-2 mx-auto -mt-14 flex w-fit gap-1 rounded-full p-1.5 shadow-[inset_0_1px_0_rgb(255_255_255/0.15)] ring-1 ring-white/15"
>
{tools.map(({ label, icon: Icon }) => (
<Button
key={label}
variant="ghost"
size="icon-sm"
aria-label={label}
className="rounded-full text-white/85 hover:text-white dark:hover:bg-white/15"
>
<Icon />
</Button>
))}
</BlurPanel>
</div>
);
}Intensity
intensity takes a preset — subtle, medium, strong — or a number from 0 to 1. It scales blur (up to 24px), saturation and tint together so the panel stays balanced.
intensity="subtle"
Always frosted — handy for sidebars and docked panels.
intensity="medium"
Always frosted — handy for sidebars and docked panels.
intensity="strong"
Always frosted — handy for sidebars and docked panels.
import { BlurPanel } from "@/components/dusk/glass/blur-panel";
import { GlassBackdrop } from "@/components/demos/glass-card/glass-backdrop";
const levels = ["subtle", "medium", "strong"] as const;
export default function BlurPanelIntensity() {
return (
<>
<GlassBackdrop />
<div className="relative grid w-full max-w-2xl gap-4 sm:grid-cols-3">
{levels.map((level) => (
<BlurPanel
key={level}
intensity={level}
scrollRange={false}
edge="none"
className="rounded-xl p-5 ring-1 ring-white/15"
>
<p className="text-xs text-white/70">intensity="{level}"</p>
<p className="mt-6 text-sm leading-relaxed text-white/85">
Always frosted — handy for sidebars and docked panels.
</p>
</BlurPanel>
))}
</div>
</>
);
}API Reference
Also accepts every <div> prop. Pass container when the panel lives inside its own scroll area instead of the page.
| Prop | Type | Default | Description |
|---|---|---|---|
| as | "div" | "header" | "nav" | "aside" | "footer" | "section" | "div" | Element to render — pick the right landmark. |
| intensity | "subtle" | "medium" | "strong" | number | "medium" | How frosted the panel gets. Numbers go from 0 to 1. |
| scrollRange | [number, number] | false | [0, 80] | Scroll distance in px over which the glass fades in. false = always frosted. |
| container | RefObject<HTMLElement | null> | — | Scroll container to watch. Defaults to the page. |
| edge | "top" | "right" | "bottom" | "left" | "none" | "bottom" | Side that gets a hairline as the panel frosts. |
Accessibility
- Render it as a landmark with
as="header","nav"or"aside", and give navs anaria-label. - The tint scales with the blur, and browsers without backdrop-filter get a near-opaque fill, so content under the panel never makes its text unreadable.
- Nothing moves: only blur, tint and a hairline fade with scroll, so it's comfortable with reduced motion. Scroll is read through motion values and never re-renders React.
- If you put the panel inside its own scroll area, make that area focusable (tabIndex={0}) with a label so keyboard users can scroll it.