When to use
- Group one subject on a dashboard or settings page: a plan with a Manage button, a stat with its period, a short form.
- Link to a page about one thing, such as a project, a document or a person, with the whole card as the target.
- Hold content that changes size in place, such as a list that expands or a form that turns into a confirmation, so the page below glides instead of jumping.
- Replace shadcn's Card without touching the markup: same component names, same slots, same header grid.
When not to use
Installation
pnpm dlx shadcn add https://eased.dev/r/card.jsonnpx shadcn add https://eased.dev/r/card.jsonyarn dlx shadcn add https://eased.dev/r/card.jsonbunx --bun shadcn add https://eased.dev/r/card.jsonThe command adds Card, everything it builds on and Eased’s tokens to your project.
Install the dependencies
pnpm add @base-ui/react motionnpm install @base-ui/react motionyarn add @base-ui/react motionbun add @base-ui/react motionAdd the Eased pieces it builds on
Copy each item’s files the same way, or install them with the CLI:
Copy the source into your project
components/eased/card/card.tsxTSX "use client";import { useRender } from "@base-ui/react/use-render";import type { ComponentProps } from "react";import { AutoHeight } from "../_primitives/auto-height/auto-height";export type CardSize = "default" | "sm";export type CardProps = ComponentProps<"div"> & { /** default: comfortable, 24px padding and a 16px title. sm: dense, 16px padding and a 14px title, for grids of tiles. */ size?: CardSize; /** * Spring the card's height when its content changes (a list expanding, a form turning into * a confirmation), so what sits below glides instead of jumping. Default false. */ autoHeight?: boolean;};// Padding is `--pad` on the root, so the parts and any `radius-nested` child read it (rule 100).// The gap between parts is ⅔ of it (rule 111). Gap and radius go through variables because// Tailwind sorts `gap-(--x)` before `gap-0` and `rounded-(--x)` before `rounded-none`: a// `className="gap-0"` or `rounded-none` from shadcn markup wins without tailwind-merge.const SIZE: Record<CardSize, string> = { default: "[--pad:--spacing(6)] [--card-gap:--spacing(4)]", sm: "[--pad:--spacing(4)] [--card-gap:--spacing(3)]",};// All of it waits on a CardLink inside; a card without one never moves. Written out in full// so Tailwind sees every class.const LINKED = [ // Hover lift (rule 13): shadow-raised on a layer behind the content, cross-faded rather than // animating box-shadow (rule 14). Only while the pointer is over the link's area, not an action. "before:pointer-events-none before:absolute before:-inset-px before:-z-1 before:rounded-[inherit] before:opacity-0 before:shadow-raised before:[transition:opacity_var(--eased-duration-standard)_var(--eased-ease-standard)]", "hover-fine:has-[[data-slot=card-link]:hover]:border-line-strong hover-fine:has-[[data-slot=card-link]:hover]:before:opacity-100", // Press like any control wider than 220px (rule 63): down in 100ms, back on the snappy spring. "[transition:border-color_150ms_var(--eased-ease-standard),scale_var(--eased-duration-spring-snappy)_var(--eased-spring-snappy),box-shadow_var(--eased-duration-focus)_var(--eased-ease-standard)]", "has-[[data-slot=card-link]:active]:scale-(--eased-press-scale-wide) has-[[data-slot=card-link]:active]:duration-(--eased-duration-instant) has-[[data-slot=card-link]:active]:ease-standard reduced:has-[[data-slot=card-link]:active]:scale-none", // Keyboard focus rings the whole card with focus-ring's ring; the outline shows in forced colours. "outline-offset-2 outline-transparent has-[[data-slot=card-link]:focus-visible]:outline-2 has-[[data-slot=card-link]:focus-visible]:shadow-[0_0_0_2px_var(--eased-bg),0_0_0_4px_var(--eased-ring)]",].join(" ");/** * A surface that groups one subject: a title, what it is about and what to do with it. The * parts and their `data-slot`s match shadcn/ui's Card, so it swaps in. A static card holds * still. Put a CardLink in it and the whole card becomes the link: it lifts on hover, presses * to 0.985 and rings on keyboard focus. `autoHeight` springs the height when content changes. */export function Card({ size = "default", autoHeight = false, className = "", children, ...props }: CardProps) { const body = "flex flex-col gap-(--card-gap) py-(--pad)"; return ( <div {...props} data-slot="card" data-size={size} className={`group/card relative isolate rounded-(--radius-outer) border border-line-subtle bg-surface text-ui text-text [--radius-outer:var(--eased-radius-panel)] ${SIZE[size]} ${LINKED} ${autoHeight ? "" : body} ${className}`} > {autoHeight ? ( <AutoHeight> <div className={body}>{children}</div> </AutoHeight> ) : ( children )} </div> );}/** Title and description, with a CardAction beside them when there is one. */export function CardHeader({ className = "", ...props }: ComponentProps<"div">) { return ( <div {...props} data-slot="card-header" className={`@container/card-header grid auto-rows-min items-start gap-(--card-header-gap) px-(--pad) [--card-header-gap:--spacing(1)_--spacing(4)] has-data-[slot=card-action]:grid-cols-[minmax(0,1fr)_auto] [.border-b]:pb-(--pad) ${className}`} /> );}export type CardTitleProps = useRender.ComponentProps<"div">;/** One line in sentence case. A div, as in shadcn; pass `render={<h3 />}` to put it in the outline. */export function CardTitle({ render, className = "", ...props }: CardTitleProps) { return useRender({ defaultTagName: "div", render, props: { ...props, "data-slot": "card-title", className: `min-w-0 text-ui-md font-medium text-text text-balance break-words group-data-[size=sm]/card:text-ui ${className}`, }, });}/** What the card is about, under the title. */export function CardDescription({ className = "", ...props }: ComponentProps<"div">) { return ( <div {...props} data-slot="card-description" className={`text-ui text-text-secondary text-pretty group-data-[size=sm]/card:text-ui-sm ${className}`} /> );}/** * A control or badge at the header's trailing edge, centred on the title's first line (rule * 107). It sits above a CardLink's hit area, so it stays clickable in a linked card. */export function CardAction({ className = "", ...props }: ComponentProps<"div">) { return ( <div {...props} data-slot="card-action" className={`relative z-1 col-start-2 row-span-2 row-start-1 flex h-[1lh] items-center self-start justify-self-end text-ui-md group-data-[size=sm]/card:text-ui ${className}`} /> );}export function CardContent({ className = "", ...props }: ComponentProps<"div">) { return <div {...props} data-slot="card-content" className={`px-(--pad) ${className}`} />;}export function CardFooter({ className = "", ...props }: ComponentProps<"div">) { return <div {...props} data-slot="card-footer" className={`flex items-center px-(--pad) [.border-t]:pt-(--pad) ${className}`} />;}export type CardLinkProps = useRender.ComponentProps<"a">;/** * Makes the whole card the link (rule 59): its hit area stretches over the card, and the card * lifts, presses and rings for it. Wrap the title text in it so the link's name is the title. * An `<a>`; pass `render={<Link href="…" />}` for a router link or `render={<button type="button" />}` * for a card that acts in place. Controls elsewhere in a linked card need `relative z-1`. */export function CardLink({ render, className = "", ...props }: CardLinkProps) { return useRender({ defaultTagName: "a", render, props: { ...props, "data-slot": "card-link", className: `cursor-pointer text-start outline-none after:absolute after:inset-0 after:rounded-(--radius-outer) ${className}`, }, });}Keep the folder layout
The files import each other by relative path (
../lib/motion), so keep each one at the path shown, undercomponents/eased/.
Usage
import { Button } from "@/components/eased/button/button";import { Card, CardAction, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/eased/card/card";import { Progress } from "@/components/eased/progress/progress";export function PlanCard() { return ( <Card> <CardHeader> <CardTitle>Pro plan</CardTitle> <CardDescription>Renews Nov 1 for $249.00</CardDescription> <CardAction> <Button size="sm">Manage</Button> </CardAction> </CardHeader> <CardContent> <Progress label="9 of 12 seats used" value={9} max={12} showValue={false} size="sm" /> </CardContent> </Card> );}Examples
A card that is a link
Wrap the title text in CardLink. Its hit area stretches over the card, so a click anywhere opens it, and the link's accessible name stays the title. A CardAction stays clickable on top; any other control inside needs relative z-1.
<Card size="sm"> <CardHeader> <CardTitle> <CardLink href="/projects/northwind-web">northwind-web</CardLink> </CardTitle> <CardDescription>Deployed 4m ago</CardDescription> <CardAction> <Badge tone="success" dot>Production</Badge> </CardAction> </CardHeader></Card>For a router link, pass it as render: <CardLink render={<Link href="/projects/northwind-web" />}>. For a card that acts in place instead of navigating, render a button: <CardLink render={<button type="button" onClick={select} />}>.
Content that grows
Set autoHeight and change the content; the card springs to its new height.
const [all, setAll] = useState(false);<Card autoHeight> <CardHeader> <CardTitle>Recent activity</CardTitle> </CardHeader> <CardContent> <ActivityList items={all ? activity : activity.slice(0, 3)} /> </CardContent> <CardFooter> <Button size="sm" variant="ghost" edge="start" onClick={() => setAll(!all)}> {all ? "Show fewer" : `Show all ${activity.length}`} </Button> </CardFooter></Card>Dense
size="sm" drops the padding to 16px and the title to 14px, for grids of cards and tiles.
<Card size="sm">…</Card>Coming from shadcn
Change the import path; the parts, slots and className overrides carry over. The card's gap and radius are set through variables (gap-(--card-gap), rounded-(--radius-outer)), so a gap-0 or rounded-none you pass wins without tailwind-merge. CardHeader still turns into a two-column grid when it holds a CardAction, and a border-b header or border-t footer still gets padding on its bordered side. The card sets its padding as --pad (24px, or 16px at sm) and its radius as --radius-outer, so radius-nested children inside line up with its corners.
API reference
Card
| Prop | Type | Default | Description |
|---|---|---|---|
size | "default" | "sm" | "default" | default is comfortable: 24px padding, 16px gaps and a 16px title. sm is dense: 16px padding, 12px gaps and a 14px title. Sets data-size. |
autoHeight | boolean | false | Spring the height when the content changes size, including when text rewraps because the card got narrower. Puts the parts in an inner wrapper, so layout classes such as gap-* in className no longer reach them. |
className | string | "" | Appended to the root's classes. |
Every other div prop passes through to the root, which has data-slot="card".
CardHeader, CardDescription, CardContent, CardFooter
Plain divs with data-slot card-header, card-description, card-content and card-footer. They take every div prop. The header is a grid that makes room for a CardAction; the footer is a row with its items centred.
CardTitle
A div with data-slot="card-title", as in shadcn. Pass render={<h3 />} to put the title in the document outline.
CardAction
A div with data-slot="card-action", at the header's trailing edge and centred on the title's first line. It sits above a CardLink's hit area.
CardLink
| Prop | Type | Default | Description |
|---|---|---|---|
href | string | Where the card goes. Every a prop passes through. | |
render | ReactElement | (props) => ReactElement | <a> | Swap the element: a router Link, or a button for a card that acts in place. |
className | string | "" | Appended to the link's classes. |
It has data-slot="card-link". The card reads that slot to lift, press and ring, so use one CardLink per card.
Keyboard
| Key | Action |
|---|---|
Tab | Moves focus to the CardLink, which rings the whole card, then to any controls inside. |
Enter | Follows the link, or activates a button CardLink. |
Space | Activates a button CardLink. |
Accessibility
- A card is a plain
divwith no role. Give CardTitle a heading element withrenderwhen cards are sections of the page. - A linked card has exactly one link, named by the title it wraps, so a screen reader hears "northwind-web, link" rather than the whole card read out.
- Keyboard focus draws the 2px ring around the whole card, not the title text, and a transparent outline shows it in forced-colours mode. Pointer clicks draw no ring.
- The hit area covers the full card, well over 44×44px. Text inside a linked card can't be selected, as with any link.
- While
autoHeightsprings, content outside the new height is clipped; at rest nothing is clipped, so focus rings and shadows inside the card show in full.
Motion
A card is a container, so by default it holds still: no entrance, no hover, nothing on a re-render. Motion only shows up where it explains something. With a CardLink inside, the card becomes a target. On hover (pointer devices only) the border steps to line-strong over 150ms on the standard curve, and shadow-raised fades in over 200ms on a layer behind the content, so box-shadow itself never animates. It doesn't lift or grow, because a card that moves under the pointer is harder to aim at. Pressing the link scales the card to 0.985, the wide-control press for anything over 220px: down in 100ms, back on the snappy spring. Pressing a button inside the card presses only that button. Keyboard focus fades the ring in like any focus ring. With autoHeight, a size change (new content, or text rewrapping as the viewport narrows) rides the smooth spring (no overshoot) through Auto Height, and a change mid-spring carries on from the current height. Content doesn't fade, because it changed and didn't arrive. Reduced motion: no press scale, and the height snaps; the colour and shadow fades stay because they don't move anything.
Notes for AI
Use Card for anything you would reach for shadcn's Card for; the code is the same apart from the import path. Pick size="sm" in grids and dashboards. To make a card navigate, put CardLink around the title text instead of wrapping the card in an <a>, and give CardLink render={<Link href=… />} in a Next.js app. Set autoHeight only when content changes size while the card is on screen.
Don't wrap Card in <a> or <button>, or put onClick on the root: you lose the hover, press and focus ring, and nested controls become invalid HTML. Don't add hover or entrance animations to a static card, and don't wrap it in your own height animation; autoHeight already does that. Inside a linked card, give controls other than CardAction relative z-1, or the link's hit area covers them. Keep anything positioned out of the path between CardLink and the Card root: relative on CardHeader or CardTitle shrinks the hit area to the title.
Responsive
The card fills its container and never sets a width. The header's title and description wrap in the space beside a CardAction, and the header is a @container/card-header, so its children can adapt with @max-xs/card-header: and friends.
Related components
- KPI Stat Card: one number with its trend and sparkline, already laid out.
- Concentric Border Radius: nested corners that stay concentric as the padding changes.
- Animated Alert: a tinted callout that springs open and closed, for messages rather than subjects.