Card
The shadcn/ui Card with smooth border and shadow transitions and an interactive mode for clickable cards — plus three animated React card blocks built with Motion: a subtle cursor-aware border highlight, a gentle 3D tilt card, and a loading card that crossfades from a shimmer skeleton.
- Drop-in shadcn API
- Server Component friendly
- Motion blocks
- prefers-reduced-motion
import { Cpu, Zap } from "lucide-react";
import { Button } from "@/components/ui/button";
import { CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
import { GlowCard } from "@/components/dusk/card/glow-card";
export default function GlowCardDemo() {
return (
<div className="grid w-full max-w-xl gap-4 sm:grid-cols-2">
<GlowCard>
<CardHeader>
<Zap className="mb-2 size-5 text-muted-foreground" aria-hidden />
<CardTitle>Edge functions</CardTitle>
<CardDescription>Run code in the region closest to each request.</CardDescription>
</CardHeader>
<CardFooter>
<Button variant="outline" size="sm">Learn more</Button>
</CardFooter>
</GlowCard>
<GlowCard radius={120}>
<CardHeader>
<Cpu className="mb-2 size-5 text-muted-foreground" aria-hidden />
<CardTitle>GPU instances</CardTitle>
<CardDescription>Spin up an H100 in seconds. Pay by the minute.</CardDescription>
</CardHeader>
<CardContent className="text-sm text-muted-foreground">A smaller radius keeps the highlight tight.</CardContent>
</GlowCard>
</div>
);
}Installation
$ npx shadcn@latest add https://duskui.com/r/card.json1. Install the dependencies.
npm install @radix-ui/react-slot2. Copy the source into
components/ui/card.tsx.card.tsx import * as React from "react"; import { Slot } from "@radix-ui/react-slot"; import { cn } from "@/lib/utils"; export interface CardProps extends React.ComponentProps<"div"> { /** Render the child element instead of a `<div>` (Radix Slot), e.g. a link. */ asChild?: boolean; /** Brighten the border and background on hover and show a focus ring. Use for clickable cards. */ interactive?: boolean; } /** * DuskUI Card — a drop-in upgrade of the shadcn/ui Card. * * Same parts and data-slot attributes as shadcn (Card, CardHeader, CardTitle, * CardDescription, CardAction, CardContent, CardFooter) plus: * - A quiet neutral shadow and smooth border / background transitions. * - `interactive`: a subtle hover border and background and a focus-visible * ring for cards that are links or buttons (combine with `asChild`). * - `isolate`, so decorative layers placed at `-z-10` sit above the surface * but below the content. * CSS only, so it works in Server Components. */ function Card({ className, asChild = false, interactive = false, ...props }: CardProps) { const Comp = asChild ? Slot : "div"; return ( <Comp data-slot="card" data-interactive={interactive || undefined} className={cn( "relative isolate flex flex-col gap-6 rounded-xl border bg-card py-6 text-card-foreground", "shadow-sm", "transition-[border-color,box-shadow,background-color] duration-150 ease-out motion-reduce:transition-none", interactive && [ "outline-none hover:border-white/20 hover:bg-accent/40", "focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50", ], className )} {...props} /> ); } /** Top section. Lays out title, description and an optional CardAction in a grid. */ function CardHeader({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="card-header" className={cn( "@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6", className )} {...props} /> ); } /** The card's title. A `<div>` like shadcn — nest an `<h2>`/`<h3>` inside when it belongs in the page outline. */ function CardTitle({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="card-title" className={cn("leading-none font-semibold tracking-tight", className)} {...props} /> ); } /** Muted supporting text under the title. */ function CardDescription({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="card-description" className={cn("text-sm text-muted-foreground", className)} {...props} /> ); } /** Top-right slot in the header for a button, menu or badge. */ function CardAction({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="card-action" className={cn("col-start-2 row-span-2 row-start-1 self-start justify-self-end", className)} {...props} /> ); } /** Main body. */ function CardContent({ className, ...props }: React.ComponentProps<"div">) { return <div data-slot="card-content" className={cn("px-6", className)} {...props} />; } /** Bottom row, usually for actions. */ function CardFooter({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="card-footer" className={cn("flex items-center px-6 [.border-t]:pt-6", className)} {...props} /> ); } export { Card, CardHeader, CardFooter, CardTitle, CardAction, CardDescription, CardContent };
Replaces components/ui/card.tsx with the same parts and data-slot attributes, so existing cards keep working. The base Card is CSS-only — no "use client" needed.
Usage
import { Button } from "@/components/ui/button"
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card"
export function PlanCard() {
return (
<Card>
<CardHeader>
<CardTitle>Pro plan</CardTitle>
<CardDescription>For teams shipping every day.</CardDescription>
</CardHeader>
<CardContent>$24 / month</CardContent>
<CardFooter>
<Button>Upgrade</Button>
</CardFooter>
</Card>
)
}Examples
Default
Header, title, description, an optional CardAction slot in the top-right, content and footer — the exact shadcn/ui structure.
$24 / month
- Unlimited projects
- Preview deployments
- Priority support
import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge";
import {
Card,
CardAction,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card";
export default function CardBasicDemo() {
return (
<Card className="w-full max-w-sm">
<CardHeader>
<CardTitle>Pro plan</CardTitle>
<CardDescription>For teams shipping every day.</CardDescription>
<CardAction>
<Badge variant="soft">Popular</Badge>
</CardAction>
</CardHeader>
<CardContent>
<p className="text-3xl font-semibold tracking-tight">
$24<span className="text-sm font-normal text-muted-foreground"> / month</span>
</p>
<ul className="mt-4 space-y-2 text-sm text-muted-foreground">
<li>Unlimited projects</li>
<li>Preview deployments</li>
<li>Priority support</li>
</ul>
</CardContent>
<CardFooter>
<Button className="w-full">Upgrade</Button>
</CardFooter>
</Card>
);
}Interactive link cards
Add interactive for clickable cards: a subtle border and background change on hover and a focus-visible ring. Combine it with asChild to render a real link, so the whole card is one keyboard stop.
import Link from "next/link";
import { ArrowUpRight, Layers, MousePointerClick } from "lucide-react";
import { Card, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
const links = [
{ href: "/components/button", title: "Button", text: "Loading states and Motion blocks.", Icon: MousePointerClick },
{ href: "/components/input", title: "Input", text: "Floating labels, OTP and more.", Icon: Layers },
];
export default function CardInteractiveDemo() {
return (
<div className="grid w-full max-w-xl gap-4 sm:grid-cols-2">
{links.map(({ href, title, text, Icon }) => (
<Card key={href} asChild interactive className="group">
<Link href={href}>
<CardHeader>
<Icon className="mb-2 size-5 text-muted-foreground" aria-hidden />
<CardTitle className="flex items-center gap-1">
{title}
<ArrowUpRight
className="size-4 text-muted-foreground transition-transform duration-200 group-hover:translate-x-0.5 group-hover:-translate-y-0.5"
aria-hidden
/>
</CardTitle>
<CardDescription>{text}</CardDescription>
</CardHeader>
</Link>
</Card>
))}
</div>
);
}Blocks
Ready-made variations composed from the base component with Motion. Each installs on its own and pulls in its dependencies automatically.
Glow Card
The 1px border catches a faint highlight where the cursor is, with a barely visible tint on the surface. The highlight follows the pointer through motion values, so it never re-renders React, and it also shows when a child receives keyboard focus.
import { Cpu, Zap } from "lucide-react";
import { Button } from "@/components/ui/button";
import { CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
import { GlowCard } from "@/components/dusk/card/glow-card";
export default function GlowCardDemo() {
return (
<div className="grid w-full max-w-xl gap-4 sm:grid-cols-2">
<GlowCard>
<CardHeader>
<Zap className="mb-2 size-5 text-muted-foreground" aria-hidden />
<CardTitle>Edge functions</CardTitle>
<CardDescription>Run code in the region closest to each request.</CardDescription>
</CardHeader>
<CardFooter>
<Button variant="outline" size="sm">Learn more</Button>
</CardFooter>
</GlowCard>
<GlowCard radius={120}>
<CardHeader>
<Cpu className="mb-2 size-5 text-muted-foreground" aria-hidden />
<CardTitle>GPU instances</CardTitle>
<CardDescription>Spin up an H100 in seconds. Pay by the minute.</CardDescription>
</CardHeader>
<CardContent className="text-sm text-muted-foreground">A smaller radius keeps the highlight tight.</CardContent>
</GlowCard>
</div>
);
}$ npx shadcn@latest add https://duskui.com/r/glow-card.json1. Install the dependencies.
npm install motion2. Copy the source into
components/dusk/card/glow-card.tsx.glow-card.tsx "use client"; import * as React from "react"; import { motion, useMotionTemplate, useMotionValue } from "motion/react"; import { Card, type CardProps } from "@/components/ui/card"; import { cn } from "@/lib/utils"; export interface GlowCardProps extends Omit<CardProps, "asChild"> { /** Radius of the highlight in px. */ radius?: number; /** Any CSS color. Mixed in at low opacity; defaults to white. */ color?: string; } /** * A card whose 1px border catches a faint highlight where the cursor is, with * a barely visible tint on the surface. The highlight follows the pointer * through motion values, so moving the mouse never re-renders React. It also * shows while a child has keyboard focus, so the effect isn't mouse-only. */ export function GlowCard({ radius = 160, color = "#ffffff", className, children, onPointerMove, onFocus, ...props }: GlowCardProps) { // Start far outside so nothing shows before the first move. const x = useMotionValue(-radius * 2); const y = useMotionValue(-radius * 2); const border = useMotionTemplate`radial-gradient(${radius}px circle at ${x}px ${y}px, color-mix(in oklab, ${color} 35%, transparent), transparent 70%)`; const fill = useMotionTemplate`radial-gradient(${radius}px circle at ${x}px ${y}px, color-mix(in oklab, ${color} 4%, transparent), transparent 70%)`; const handleMove = (event: React.PointerEvent<HTMLDivElement>) => { onPointerMove?.(event); const rect = event.currentTarget.getBoundingClientRect(); // +1 because the light layers sit on the 1px border (-inset-px). x.set(event.clientX - rect.left + 1); y.set(event.clientY - rect.top + 1); }; const handleFocus = (event: React.FocusEvent<HTMLDivElement>) => { onFocus?.(event); // Keyboard focus without a prior hover: light the top edge. if (x.get() < 0) { x.set(event.currentTarget.offsetWidth / 2); y.set(0); } }; // -z-10 + the Card's `isolate`: above the surface, below the content. const layer = "pointer-events-none absolute -inset-px -z-10 rounded-[inherit] opacity-0 transition-opacity duration-200 group-hover/glow:opacity-100 group-focus-within/glow:opacity-100"; // The gradient is masked down to a 1px ring. const ring = "absolute inset-0 rounded-[inherit] p-px [mask-image:linear-gradient(#000_0_0),linear-gradient(#000_0_0)] [mask-clip:content-box,border-box] [mask-composite:exclude]"; return ( <Card className={cn("group/glow", className)} onPointerMove={handleMove} onFocus={handleFocus} {...props} > <motion.div aria-hidden className={layer} style={{ background: fill }} /> <div aria-hidden className={layer}> <motion.div className={ring} style={{ background: border }} /> </div> {children} </Card> ); }
| Prop | Type | Default | Description |
|---|---|---|---|
| radius | number | 160 | Radius of the highlight in px. |
| color | string | "#ffffff" | Any CSS color, mixed in at low opacity. |
Tilt Card
A gentle 3D tilt toward the cursor on damped springs, with an optional, barely visible glare. Give elements inside the card parts [transform:translateZ(24px)] to lift them off the surface. Mouse only (never hijacks touch scrolling) and completely still under reduced motion.
import { Layers } from "lucide-react";
import { CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { TiltCard } from "@/components/dusk/card/tilt-card";
export default function TiltCardDemo() {
return (
<TiltCard className="w-72">
<CardHeader className="gap-3">
{/* translateZ lifts the icon off the card while it tilts. */}
<div className="mb-6 grid size-12 place-items-center rounded-xl border border-white/10 bg-white/[0.04] text-white/80 [transform:translateZ(24px)]">
<Layers className="size-6" aria-hidden />
</div>
<CardTitle className="text-xl [transform:translateZ(16px)]">Design system audit</CardTitle>
<CardDescription className="[transform:translateZ(8px)]">
Move a mouse over the card and it tilts gently toward the cursor.
</CardDescription>
</CardHeader>
</TiltCard>
);
}$ npx shadcn@latest add https://duskui.com/r/tilt-card.json1. Install the dependencies.
npm install motion2. Copy the source into
components/dusk/card/tilt-card.tsx.tilt-card.tsx "use client"; import * as React from "react"; import { motion, useMotionTemplate, useMotionValue, useReducedMotion, useSpring, useTransform, } from "motion/react"; import { Card } from "@/components/ui/card"; import { cn } from "@/lib/utils"; const MotionCard = motion.create(Card); type MotionCardProps = Omit<React.ComponentProps<typeof MotionCard>, "children" | "asChild"> & { children?: React.ReactNode; }; export interface TiltCardProps extends MotionCardProps { /** Maximum rotation in degrees at the card's edges. */ maxTilt?: number; /** Scale while hovered. 1 to disable. */ hoverScale?: number; /** Show a faint light reflection that follows the cursor. */ glare?: boolean; /** CSS perspective in px. Lower = more dramatic. */ perspective?: number; /** Classes for the outer wrapper that receives the pointer events. */ containerClassName?: string; } const spring = { stiffness: 260, damping: 30, mass: 0.6 }; /** * A card that tilts gently in 3D toward the cursor and eases back on leave, * with an optional, barely visible glare. Elements inside the Card parts * (CardHeader, CardContent…) can pop out with `[transform:translateZ(24px)]`; * add `transform-3d` to any extra wrapper in between. Reacts to a mouse only * (never touch), and stays flat when the user prefers reduced motion. */ export function TiltCard({ maxTilt = 6, hoverScale = 1, glare = false, perspective = 900, className, containerClassName, style, children, ...props }: TiltCardProps) { const reduceMotion = useReducedMotion(); // Pointer position in the card, 0–1 on each axis. 0.5 = center. const px = useMotionValue(0.5); const py = useMotionValue(0.5); const hover = useMotionValue(0); const rotateX = useSpring(useTransform(py, [0, 1], [maxTilt, -maxTilt]), spring); const rotateY = useSpring(useTransform(px, [0, 1], [-maxTilt, maxTilt]), spring); const scale = useSpring(useTransform(hover, [0, 1], [1, hoverScale]), spring); const glareOpacity = useSpring(hover, { stiffness: 200, damping: 30 }); const glareX = useTransform(px, (v) => `${v * 100}%`); const glareY = useTransform(py, (v) => `${v * 100}%`); const glareBackground = useMotionTemplate`radial-gradient(farthest-corner circle at ${glareX} ${glareY}, rgb(255 255 255 / 0.04), transparent 50%)`; const handleMove = (event: React.PointerEvent<HTMLDivElement>) => { if (reduceMotion || event.pointerType !== "mouse") return; const rect = event.currentTarget.getBoundingClientRect(); px.set((event.clientX - rect.left) / rect.width); py.set((event.clientY - rect.top) / rect.height); hover.set(1); }; const handleLeave = () => { px.set(0.5); py.set(0.5); hover.set(0); }; return ( // The wrapper never moves, so its rect is stable while the card rotates. <div className={cn("group/tilt", containerClassName)} style={{ perspective }} onPointerMove={handleMove} onPointerLeave={handleLeave} > <MotionCard className={cn( // isolation-auto: `isolate` would flatten the 3D scene. Card parts // (header, content, footer) keep it 3D so their children can use translateZ. "isolation-auto transform-3d will-change-transform [&>[data-slot]]:transform-3d", className )} style={{ ...style, rotateX, rotateY, scale }} {...props} > {children} {glare && ( <motion.div aria-hidden className="pointer-events-none absolute inset-0 rounded-[inherit]" style={{ background: glareBackground, opacity: glareOpacity }} /> )} </MotionCard> </div> ); }
| Prop | Type | Default | Description |
|---|---|---|---|
| maxTilt | number | 6 | Maximum rotation in degrees. |
| hoverScale | number | 1 | Scale while hovered; 1 disables it. |
| glare | boolean | false | Show a faint light reflection that follows the cursor. |
| perspective | number | 900 | CSS perspective in px. Lower is more dramatic. |
| containerClassName | string | — | Classes for the wrapper that receives pointer events. |
Loading Card
Shows a shimmering skeleton while loading, then crossfades the real content in while the height springs to fit — nothing below the card jumps. Build custom placeholders with the exported Shimmer block. Press Reload to replay.
"use client";
import * as React from "react";
import { RotateCw } from "lucide-react";
import { Button } from "@/components/ui/button";
import { CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
import { LoadingCard } from "@/components/dusk/card/loading-card";
export default function LoadingCardDemo() {
const [loading, setLoading] = React.useState(true);
const timer = React.useRef<ReturnType<typeof setTimeout>>(undefined);
const load = React.useCallback(() => {
setLoading(true);
clearTimeout(timer.current);
timer.current = setTimeout(() => setLoading(false), 1600);
}, []);
React.useEffect(() => {
timer.current = setTimeout(() => setLoading(false), 1600);
return () => clearTimeout(timer.current);
}, []);
return (
<div className="flex w-full max-w-sm flex-col items-center gap-4">
<LoadingCard loading={loading} loadingLabel="Loading profile" className="w-full">
<CardHeader className="flex items-center gap-3">
<div className="grid size-10 shrink-0 place-items-center rounded-full bg-white/10 font-semibold text-foreground">
AK
</div>
<div className="grid gap-1">
<CardTitle>Ada Kim</CardTitle>
<CardDescription>Design engineer · Berlin</CardDescription>
</div>
</CardHeader>
<CardContent className="text-sm leading-relaxed text-muted-foreground">
Builds motion systems and design tooling. Currently obsessed with spring physics and
variable fonts.
</CardContent>
<CardFooter className="gap-2">
<Button size="sm">Follow</Button>
<Button size="sm" variant="outline">Message</Button>
</CardFooter>
</LoadingCard>
<Button variant="ghost" size="sm" onClick={load} disabled={loading}>
<RotateCw />
Reload
</Button>
</div>
);
}$ npx shadcn@latest add https://duskui.com/r/loading-card.json1. Install the dependencies.
npm install motion2. Copy the source into
components/dusk/card/loading-card.tsx.loading-card.tsx "use client"; import * as React from "react"; import { AnimatePresence, motion, useReducedMotion } from "motion/react"; import { Card, type CardProps } from "@/components/ui/card"; import { cn } from "@/lib/utils"; /** * A skeleton block with a light sweeping across it. Size it with classes * (`h-4 w-2/3`, `size-10 rounded-full`…). Static with reduced motion. */ export function Shimmer({ className, ...props }: React.ComponentProps<"div">) { const reduceMotion = useReducedMotion(); return ( <div aria-hidden data-slot="shimmer" className={cn("relative overflow-hidden rounded-md bg-white/[0.06]", className)} {...props} > {!reduceMotion && ( <motion.div className="absolute inset-0 bg-[linear-gradient(90deg,transparent,rgb(255_255_255/0.08),transparent)]" initial={{ x: "-100%" }} animate={{ x: "100%" }} transition={{ duration: 1.4, ease: "easeInOut", repeat: Infinity, repeatDelay: 0.3 }} /> )} </div> ); } /** The default placeholder: avatar, title, subtitle and three text lines. */ export function CardSkeleton() { return ( <> <div className="flex items-center gap-3 px-6"> <Shimmer className="size-10 shrink-0 rounded-full" /> <div className="grid flex-1 gap-2"> <Shimmer className="h-4 w-1/2" /> <Shimmer className="h-3 w-1/3" /> </div> </div> <div className="grid gap-2 px-6"> <Shimmer className="h-3" /> <Shimmer className="h-3" /> <Shimmer className="h-3 w-4/5" /> </div> </> ); } /** Measures an element's height so the card can spring between skeleton and content sizes. */ function useHeight<T extends HTMLElement>() { const ref = React.useRef<T>(null); const [height, setHeight] = React.useState<number>(); React.useLayoutEffect(() => { const el = ref.current; if (!el) return; const observer = new ResizeObserver(([entry]) => setHeight(entry.borderBoxSize?.[0]?.blockSize ?? el.offsetHeight) ); observer.observe(el); return () => observer.disconnect(); }, []); return [ref, height] as const; } export interface LoadingCardProps extends Omit<CardProps, "asChild"> { /** Show the skeleton instead of `children`. */ loading?: boolean; /** Custom placeholder. Defaults to `<CardSkeleton />`. Build your own with `<Shimmer />`. */ skeleton?: React.ReactNode; /** Text announced to screen readers while loading. */ loadingLabel?: string; } const swap = { type: "spring", duration: 0.3, bounce: 0 } as const; /** * A Card that shows a shimmering skeleton while `loading`, then crossfades the * real content in. The height springs between the two, so nothing below the * card jumps. Lay out children exactly like a normal Card (CardHeader, * CardContent, CardFooter…). */ export function LoadingCard({ loading = false, skeleton = <CardSkeleton />, loadingLabel = "Loading", className, children, ...props }: LoadingCardProps) { const [measureRef, height] = useHeight<HTMLDivElement>(); return ( <Card aria-busy={loading || undefined} className={cn("gap-0 py-0", className)} {...props}> <span className="sr-only" aria-live="polite"> {loading ? loadingLabel : ""} </span> <motion.div className="overflow-hidden" initial={false} animate={{ height: height ?? "auto" }} transition={swap} > <div ref={measureRef} className="relative"> <AnimatePresence mode="popLayout" initial={false}> <motion.div key={loading ? "skeleton" : "content"} className="flex flex-col gap-6 py-6" aria-hidden={loading || undefined} initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} transition={{ duration: 0.2, ease: "easeOut" }} > {loading ? skeleton : children} </motion.div> </AnimatePresence> </div> </motion.div> </Card> ); }
| Prop | Type | Default | Description |
|---|---|---|---|
| loading | boolean | false | Show the skeleton instead of children. |
| skeleton | ReactNode | <CardSkeleton /> | Custom placeholder built from <Shimmer />. |
| loadingLabel | string | "Loading" | Announced to screen readers while loading. |
API Reference
Card accepts every <div> prop plus the two below. The other parts (CardHeader, CardTitle, CardDescription, CardAction, CardContent, CardFooter) are styled <div>s, identical to shadcn/ui.
| Prop | Type | Default | Description |
|---|---|---|---|
| interactive | boolean | false | Subtle hover border and background, plus a focus ring, for clickable cards. |
| asChild | boolean | false | Render the child element instead (Radix Slot), e.g. a Link. |
| className | string | — | Merged with tailwind-merge, so overrides win. |
Accessibility
- Interactive cards should be a single link or button (
asChild) so the whole card is one focus stop with a visible focus ring. - Highlight and glare layers are aria-hidden and pointer-events-none; they never intercept clicks or reach screen readers.
- Loading Card sets
aria-busy, hides the skeleton from assistive tech and announces the loading label politely. - Tilt Card ignores touch and stays still with prefers-reduced-motion; the skeleton shimmer stops too.