Containment · Material 3: Cards
Card
Groups content and actions about one subject. Quiet at rest; separated by surface and shadow, never an outline.
Examples and variants
Variants
Elevated (default) and filled.
function CardVariants() {
return (
<div className="grid w-full gap-4 sm:grid-cols-2">
<Card>
<CardHeader>
<CardTitle>Elevated</CardTitle>
<CardDescription>Default. A soft shadow lifts it.</CardDescription>
</CardHeader>
</Card>
<Card variant="filled">
<CardHeader>
<CardTitle>Filled</CardTitle>
<CardDescription>A tinted surface, no shadow.</CardDescription>
</CardHeader>
</Card>
</div>
)
}Header, content, footer
With spotlight: a soft light follows the pointer.
function CardFull() {
return (
<Card spotlight className="w-full max-w-sm">
<CardHeader>
<CardTitle>Northwind</CardTitle>
<CardDescription>Updated 2 minutes ago</CardDescription>
<CardAction>
<Badge tone="success">Live</Badge>
</CardAction>
</CardHeader>
<CardContent className="text-muted-foreground">With spotlight, a soft light follows the pointer.</CardContent>
<CardFooter>
<Button size="sm" variant="secondary">
Open
</Button>
</CardFooter>
</Card>
)
}Interactive
The whole card is a target and squashes on press.
function CardInteractive() {
return (
<Card interactive role="button" tabIndex={0} className="w-full max-w-sm">
<CardHeader>
<CardTitle>Interactive</CardTitle>
<CardDescription>The whole card is one target. It squashes on press.</CardDescription>
</CardHeader>
</Card>
)
}Spec drawing
Measured from the live component at default density. Each code maps to the token that sets it; change the token and the drawing follows.
Install
With the CLI
The shadcn CLI only delivers files: it copies our code from the Isotopi registry into your project and installs the packages it uses. Add the foundation once, then the component.
npx shadcn@latest add https://isotopi.com/r/minimal.json
npx shadcn@latest add https://isotopi.com/r/card.jsonBy hand
No CLI needed. Add the foundation once (see Getting started), then follow these steps. They include every component this one builds on.
Install the packages it uses.
Terminalnpm install cnCopy this file to the same paths in your project. Imports use the
@/alias for your project root.components/ui/card.tsxcard
components/ui/card.tsx"use client" import * as React from "react" import { cn } from "cn" import { motionLevel } from "@/lib/overlay" /* Card: groups related content. Minimal separates cards with a surface tint and --elevation-1, never an outline. Props: - variant: elevated (default) or filled. - interactive: the whole card is pressable (squash at press). - spotlight: a soft light follows the pointer (opt-in, liquid only). */ function Card({ className, variant = "elevated", interactive = false, spotlight = false, onPointerMove, ...props }: React.ComponentProps<"div"> & { /** elevated (default): soft shadow. filled: tinted surface, no shadow. */ variant?: "elevated" | "filled" interactive?: boolean spotlight?: boolean }) { return ( <div data-slot="card" data-variant={variant} data-interactive={interactive || undefined} data-spotlight={spotlight || undefined} className={cn( "relative flex flex-col gap-(--card-gap) overflow-hidden rounded-(--card-corner) bg-(--card-container) p-(--card-padding) text-foreground shadow-(--card-elevation) border-solid border-(length:--card-stroke-width) border-(--card-stroke-color)", variant === "filled" && "bg-(--card-container-filled) shadow-none", interactive && "liquid-press cursor-pointer outline-none focus-visible:shadow-(--focus-ring)", spotlight && "card-spotlight", className )} onPointerMove={(event) => { onPointerMove?.(event) if (!spotlight) return const node = event.currentTarget if (motionLevel(node) !== "liquid") return const box = node.getBoundingClientRect() node.style.setProperty("--spot-x", `${event.clientX - box.left}px`) node.style.setProperty("--spot-y", `${event.clientY - box.top}px`) }} {...props} /> ) } function CardHeader({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="card-header" className={cn("grid auto-rows-min grid-cols-[1fr_auto] items-start gap-x-inline-md gap-y-1", className)} {...props} /> ) } function CardTitle({ className, ...props }: React.ComponentProps<"div">) { return <div data-slot="card-title" className={cn("col-start-1 text-title", className)} {...props} /> } function CardDescription({ className, ...props }: React.ComponentProps<"div">) { return <div data-slot="card-description" className={cn("col-start-1 text-sm text-muted-foreground", className)} {...props} /> } 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", className)} {...props} /> } function CardContent({ className, ...props }: React.ComponentProps<"div">) { return <div data-slot="card-content" className={cn("text-sm", className)} {...props} /> } function CardFooter({ className, ...props }: React.ComponentProps<"div">) { return <div data-slot="card-footer" className={cn("flex items-center gap-inline-sm", className)} {...props} /> } export { Card, CardHeader, CardTitle, CardDescription, CardAction, CardContent, CardFooter }
Imports
What the examples on this page import:
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"Anatomy
- 1Container · --card-container, --card-corner, --card-padding, --card-elevation.
- 2Header · Title, description and an optional action on the right.
- 3Content · Anything.
- 4Footer · Actions.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "elevated" | "filled" | "elevated" | Shadow or tinted surface. |
interactive | boolean | — | Whole card pressable. |
spotlight | boolean | — | Pointer light (liquid motion only). |
Tokens
Every visual spec is a component token in styles/tokens/components.css, pointing at a semantic token. Change a token to restyle the component; themes change the semantic layer.
| Token | Points to | Light | Dark |
|---|---|---|---|
--card-container | var(--surface-container-low) | oklch(0.985 0.004 95) | oklch(0.17 0 0) |
--card-container-filled | var(--surface-container) | oklch(0.965 0.005 95) | oklch(0.12 0 0) |
--card-corner | var(--shape-lg) | 22px | same |
--card-padding | var(--space-6) | 24px | same |
--card-gap | var(--space-4) | 16px | same |
--card-elevation | var(--elevation-1) | 0 1px 1px -0.5px oklch(0.22 0.01 260 / 7%), 0 2px 3px -1px oklch(0.22 0.01 260 / 10%), 0 4px 8px -4px oklch(0.22 0.01 260 / 6%) | 0 1px 2px oklch(0 0 0 / 35%), 0 2px 10px oklch(0 0 0 / 25%) |
--card-stroke-width | var(--stroke-width-container) | 0px | same |
--card-stroke-color | var(--stroke-color-subtle) | oklch(0.22 0.01 260 / 16%) | oklch(1 0 0 / 8%) |
Motion
| Trigger | What happens | Tokens |
|---|---|---|
| Hover (spotlight) | A soft radial light follows the pointer. | --state-hover-opacity, --duration-medium |
| Press (interactive) | Squashes slightly. | --motion-scale-press |
Calm keeps the motion without overshoot. Still (and reduced motion) keeps a designed frame with no movement.
Accessibility
- If the whole card is a link, keep only one link inside.
- Interactive cards need a role and keyboard focus.
Usage
Do
- One subject per card.
Don’t
- Don't nest cards.
- Don't wrap everything in a card.
Code
"use client"
import * as React from "react"
import { cn } from "cn"
import { motionLevel } from "@/lib/overlay"
/*
Card: groups related content. Minimal separates cards with a surface tint
and --elevation-1, never an outline. Props:
- variant: elevated (default) or filled.
- interactive: the whole card is pressable (squash at press).
- spotlight: a soft light follows the pointer (opt-in, liquid only).
*/
function Card({
className,
variant = "elevated",
interactive = false,
spotlight = false,
onPointerMove,
...props
}: React.ComponentProps<"div"> & {
/** elevated (default): soft shadow. filled: tinted surface, no shadow. */
variant?: "elevated" | "filled"
interactive?: boolean
spotlight?: boolean
}) {
return (
<div
data-slot="card"
data-variant={variant}
data-interactive={interactive || undefined}
data-spotlight={spotlight || undefined}
className={cn(
"relative flex flex-col gap-(--card-gap) overflow-hidden rounded-(--card-corner) bg-(--card-container) p-(--card-padding) text-foreground shadow-(--card-elevation) border-solid border-(length:--card-stroke-width) border-(--card-stroke-color)",
variant === "filled" && "bg-(--card-container-filled) shadow-none",
interactive && "liquid-press cursor-pointer outline-none focus-visible:shadow-(--focus-ring)",
spotlight && "card-spotlight",
className
)}
onPointerMove={(event) => {
onPointerMove?.(event)
if (!spotlight) return
const node = event.currentTarget
if (motionLevel(node) !== "liquid") return
const box = node.getBoundingClientRect()
node.style.setProperty("--spot-x", `${event.clientX - box.left}px`)
node.style.setProperty("--spot-y", `${event.clientY - box.top}px`)
}}
{...props}
/>
)
}
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-header"
className={cn("grid auto-rows-min grid-cols-[1fr_auto] items-start gap-x-inline-md gap-y-1", className)}
{...props}
/>
)
}
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
return <div data-slot="card-title" className={cn("col-start-1 text-title", className)} {...props} />
}
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
return <div data-slot="card-description" className={cn("col-start-1 text-sm text-muted-foreground", className)} {...props} />
}
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", className)} {...props} />
}
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
return <div data-slot="card-content" className={cn("text-sm", className)} {...props} />
}
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
return <div data-slot="card-footer" className={cn("flex items-center gap-inline-sm", className)} {...props} />
}
export { Card, CardHeader, CardTitle, CardDescription, CardAction, CardContent, CardFooter }