Glass Card
A glassmorphism card for React built with Tailwind CSS and Motion: real backdrop blur and saturation, a 1px hairline border and faint film grain, with optional 3D tilt and a readable fallback where backdrop-filter isn't supported.
- Backdrop blur
- Hairline border
- 3D tilt
- No re-renders
- prefers-reduced-motion
Dusk Pass
Business
4291 •••• •••• 0618
Card holder
Ava Lindqvist
Valid thru
12/29
import { Nfc } from "lucide-react";
import { GlassCard } from "@/components/dusk/glass/glass-card";
import { GlassBackdrop } from "@/components/demos/glass-card/glass-backdrop";
export default function GlassCardDemo() {
return (
<>
<GlassBackdrop />
<GlassCard tilt className="flex aspect-[1.6] w-full max-w-sm flex-col justify-between">
<div className="flex items-start justify-between">
<div>
<p className="text-xs font-medium text-white/70">Dusk Pass</p>
<p className="mt-1 text-lg font-semibold">Business</p>
</div>
<Nfc className="size-6 text-white/80" aria-hidden />
</div>
<p className="text-lg tabular-nums tracking-wider text-white/90 sm:text-xl">
4291 •••• •••• 0618
</p>
<div className="flex items-end justify-between text-sm">
<div>
<p className="text-xs text-white/60">Card holder</p>
<p className="font-medium">Ava Lindqvist</p>
</div>
<div className="text-right">
<p className="text-xs text-white/60">Valid thru</p>
<p className="font-medium">12/29</p>
</div>
</div>
</GlassCard>
</>
);
}Installation
$ npx shadcn@latest add https://duskui.com/r/glass-card.json1. Install the dependencies.
npm install motion2. Copy the source into
components/dusk/glass/glass-card.tsx.glass-card.tsx "use client"; import * as React from "react"; import { motion, useMotionValue, useReducedMotion, useSpring, useTransform } from "motion/react"; import { cn } from "@/lib/utils"; /** Tiny SVG film grain. Breaks up banding in the blur and sells the "frosted" look. */ const NOISE = "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E\")"; /** A 1px ring: the background is masked down to the padding box edge. */ const RING = "p-px [mask-image:linear-gradient(#000_0_0),linear-gradient(#000_0_0)] [mask-clip:content-box,border-box] [mask-composite:exclude]"; const tiltSpring = { stiffness: 220, damping: 22, mass: 0.6 }; export interface GlassCardProps extends Omit< React.ComponentProps<"div">, "onDrag" | "onDragStart" | "onDragEnd" | "onAnimationStart" > { /** Backdrop blur in px. */ blur?: number; /** Backdrop saturation in percent. Values above 100 make the colors behind the glass richer. */ saturation?: number; /** * Glass fill — any translucent CSS color. The default is a smoky tint of the * page background, which keeps white text readable over bright backdrops. */ tint?: string; /** 3D tilt towards the pointer. `true` = 8°, or pass the max angle in degrees. */ tilt?: boolean | number; /** Subtle film-grain texture on the glass. */ noise?: boolean; } /** * A frosted-glass surface: backdrop blur + saturation, a 1px hairline border * and a faint film grain. * * - Optional tilt runs on motion values, so moving the mouse never re-renders. * - Without `backdrop-filter` support the card falls back to an almost opaque * fill so text stays readable. * - Tilt is skipped for touch input and when the user prefers reduced motion. */ export function GlassCard({ blur = 16, saturation = 140, tint = "color-mix(in oklab, var(--background) 35%, transparent)", tilt = false, noise = true, className, style, children, onPointerMove, onPointerLeave, ...props }: GlassCardProps) { const reduceMotion = useReducedMotion(); const maxTilt = reduceMotion ? 0 : tilt === true ? 8 : tilt || 0; // Pointer position, normalised to 0–1 across the card. const px = useMotionValue(0.5); const py = useMotionValue(0.5); const rotateX = useSpring(useTransform(py, [0, 1], [maxTilt, -maxTilt]), tiltSpring); const rotateY = useSpring(useTransform(px, [0, 1], [-maxTilt, maxTilt]), tiltSpring); const handleMove = (event: React.PointerEvent<HTMLDivElement>) => { onPointerMove?.(event); // Tilting under a finger fights with scrolling, so only a mouse or pen tilts. if (!maxTilt || event.pointerType === "touch") return; const rect = event.currentTarget.getBoundingClientRect(); px.set((event.clientX - rect.left) / rect.width); py.set((event.clientY - rect.top) / rect.height); }; const handleLeave = (event: React.PointerEvent<HTMLDivElement>) => { onPointerLeave?.(event); px.set(0.5); py.set(0.5); }; const layer = "pointer-events-none absolute inset-0 -z-10 rounded-[inherit]"; return ( <motion.div data-slot="glass-card" className={cn( "group/glass relative isolate overflow-hidden rounded-xl p-6 text-foreground", // Fallback first: nearly opaque so text stays readable without blur. "bg-[color-mix(in_oklab,var(--background)_88%,transparent)]", "supports-[backdrop-filter]:bg-(color:--glass-tint) supports-[backdrop-filter]:backdrop-blur-(--glass-blur) supports-[backdrop-filter]:backdrop-saturate-(--glass-saturate)", "shadow-[inset_0_1px_0_rgb(255_255_255/0.06),0_12px_32px_-16px_rgb(0_0_0/0.5)]", className )} style={ { "--glass-blur": `${blur}px`, "--glass-saturate": `${saturation}%`, "--glass-tint": tint, ...(maxTilt ? { rotateX, rotateY, transformPerspective: 900 } : null), ...style, } as React.ComponentProps<typeof motion.div>["style"] } onPointerMove={handleMove} onPointerLeave={handleLeave} {...props} > {noise && ( <span aria-hidden className={cn(layer, "opacity-[0.05] mix-blend-overlay")} style={{ backgroundImage: NOISE }} /> )} {/* 1px hairline border. */} <span aria-hidden className={cn( layer, RING, "bg-white/12 transition-opacity duration-200 group-has-focus-visible/glass:opacity-0" )} /> {/* Keyboard users get a visible edge when something inside the card has focus. */} <span aria-hidden className={cn( layer, RING, "bg-ring/70 opacity-0 transition-opacity duration-200 group-has-focus-visible/glass:opacity-100" )} /> {children} </motion.div> ); }
Glass only looks like glass over something colorful. Put the card above an image, gradient or moving shapes — the demos use a small GlassBackdrop of drifting gradient orbs.
Usage
import { GlassCard } from "@/components/dusk/glass/glass-card"
export function PlanCard() {
return (
<GlassCard tilt className="max-w-sm">
<h3 className="font-semibold">Pro plan</h3>
<p className="text-sm text-white/70">Everything you need to ship.</p>
</GlassCard>
)
}Examples
Profile card
Interactive content works as usual. When something inside the card receives keyboard focus, the hairline border switches to the focus color so the card's edge stays visible.
Noor Khalil(verified)
Motion designer · Lisbon
- Components
- 128
- Stars
- 9.4k
- Followers
- 2.1k
import { BadgeCheck } from "lucide-react";
import { GlassCard } from "@/components/dusk/glass/glass-card";
import { FrostButton } from "@/components/dusk/glass/frost-button";
import { GlassBackdrop } from "@/components/demos/glass-card/glass-backdrop";
const stats = [
{ label: "Components", value: "128" },
{ label: "Stars", value: "9.4k" },
{ label: "Followers", value: "2.1k" },
];
export default function GlassCardProfile() {
return (
<>
<GlassBackdrop />
<GlassCard className="w-full max-w-xs text-center">
<div className="mx-auto grid size-16 place-items-center rounded-full border border-white/15 bg-background/60 text-lg font-semibold">
NK
</div>
<h3 className="mt-3 inline-flex items-center gap-1.5 font-semibold">
Noor Khalil
<BadgeCheck className="size-4 text-white/70" aria-hidden />
<span className="sr-only">(verified)</span>
</h3>
<p className="text-sm text-white/70">Motion designer · Lisbon</p>
<dl className="mt-5 grid grid-cols-3 gap-2 rounded-lg bg-white/5 p-3">
{stats.map((s) => (
<div key={s.label} className="flex flex-col-reverse">
<dt className="text-[0.7rem] text-white/60">{s.label}</dt>
<dd className="font-semibold">{s.value}</dd>
</div>
))}
</dl>
<FrostButton tone="primary" className="mt-5 w-full">
Follow
</FrostButton>
</GlassCard>
</>
);
}Blur & tint
blur sets the backdrop blur in px and tint takes any translucent CSS color. The default tint is a smoky mix of the page background, which keeps white text readable over bright colors.
Light
blur=4
Higher blur hides more of what sits behind the card.
Frosted
blur=14
Higher blur hides more of what sits behind the card.
Milky
blur=28
Higher blur hides more of what sits behind the card.
import { GlassCard } from "@/components/dusk/glass/glass-card";
import { GlassBackdrop } from "@/components/demos/glass-card/glass-backdrop";
const levels = [
{ blur: 4, label: "Light", tint: undefined },
{ blur: 14, label: "Frosted", tint: undefined },
{ blur: 28, label: "Milky", tint: "rgb(255 255 255 / 0.1)" },
];
export default function GlassCardBlur() {
return (
<>
<GlassBackdrop />
<div className="relative grid w-full max-w-2xl gap-4 sm:grid-cols-3">
{levels.map((level) => (
<GlassCard key={level.blur} blur={level.blur} tint={level.tint} className="p-5">
<p className="text-sm font-semibold">{level.label}</p>
<p className="mt-1 text-xs text-white/70">blur={level.blur}</p>
<p className="mt-6 text-sm leading-relaxed text-white/80">
Higher blur hides more of what sits behind the card.
</p>
</GlassCard>
))}
</div>
</>
);
}API Reference
Also accepts every <div> prop. Padding defaults to p-6; override it with className.
| Prop | Type | Default | Description |
|---|---|---|---|
| blur | number | 16 | Backdrop blur in px. |
| saturation | number | 140 | Backdrop saturation in percent. Above 100 makes colors behind the glass richer. |
| tint | string | "color-mix(in oklab, var(--background) 35%, transparent)" | Glass fill. Any translucent CSS color. |
| tilt | boolean | number | false | 3D tilt towards the pointer. true = 8°, or pass the max angle. |
| noise | boolean | true | Subtle film-grain texture on the glass. |
Accessibility
- Decorative layers (grain, border) are aria-hidden and ignore the pointer, so the card's content is exactly what assistive tech reads.
- Where backdrop-filter isn't supported the card falls back to an almost opaque fill, so text contrast never depends on the blur.
- A visible focus-colored edge appears when anything inside the card has keyboard focus.
- Tilt is disabled for touch input and when the user prefers reduced motion; it runs on motion values and never re-renders.