- Accordion
- Attachment
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Card
- Checkbox
- Code Block
- Collapsible
- Dialog
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Label
- Marker
- Message
- Number Flow
- Pagination
- Popover
- Progress
- Radio Group
- Select
- Slider
- Sonner
- Spinner
- Switch
- Tooltip
- Separator
- Sheet
- Tabs
- Textarea
- Toggle
- Toggle Group
- Trace
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import {
Card,
CardAction,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card";
export function CardImage() {
return (
<Card className="relative mx-auto w-full max-w-sm pt-0">
<div className="absolute inset-0 z-30 aspect-video bg-black/35" />
<img
alt="Event cover"
className="relative z-20 aspect-video w-full object-cover brightness-60 grayscale dark:brightness-40"
src="https://avatar.vercel.sh/frakment1"
/>
<CardHeader>
<CardAction>
<Badge variant="secondary">Featured</Badge>
</CardAction>
<CardTitle>Design systems meetup</CardTitle>
<CardDescription>
A practical talk on component APIs, accessibility, and shipping
faster.
</CardDescription>
</CardHeader>
<CardFooter>
<Button className="w-full">View Event</Button>
</CardFooter>
</Card>
);
}Card is a flexible surface for content and actions. It supports a size prop (default / sm), an auto-spacing variable --card-spacing (default 16px, sm 12px), and image-friendly slots (pt-0 / rounded-t-xl).
Installation
$ bunx --bun frakment add card$ npx frakment add card$ pnpm dlx frakment add card$ yarn dlx frakment add card
Copy and paste the following code into your project.
import type * as React from "react";
import { cn } from "@/lib/utils";
function Card({
className,
size = "default",
...props
}: React.ComponentProps<"div"> & { size?: "default" | "sm" }) {
return (
<div
className={cn(
"group/card bg-card text-card-foreground ring-foreground/10 flex flex-col gap-(--card-spacing) overflow-hidden rounded-xl py-(--card-spacing) text-sm ring-1 [--card-spacing:--spacing(4)] has-data-[slot=card-footer]:pb-0 has-[>img:first-child]:pt-0 data-[size=sm]:[--card-spacing:--spacing(3)] data-[size=sm]:has-data-[slot=card-footer]:pb-0 *:[img:first-child]:rounded-t-xl *:[img:last-child]:rounded-b-xl",
className
)}
data-size={size}
data-slot="card"
{...props}
/>
);
}
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
className={cn(
"group/card-header @container/card-header grid auto-rows-min items-start gap-1 rounded-t-xl px-(--card-spacing) has-data-[slot=card-action]:grid-cols-[1fr_auto] has-data-[slot=card-description]:grid-rows-[auto_auto] [.border-b]:pb-(--card-spacing)",
className
)}
data-slot="card-header"
{...props}
/>
);
}
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
className={cn(
"text-base leading-snug font-medium group-data-[size=sm]/card:text-sm",
className
)}
data-slot="card-title"
{...props}
/>
);
}
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
className={cn("text-muted-foreground text-sm", className)}
data-slot="card-description"
{...props}
/>
);
}
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
className={cn(
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
className
)}
data-slot="card-action"
{...props}
/>
);
}
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
className={cn("px-(--card-spacing)", className)}
data-slot="card-content"
{...props}
/>
);
}
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
className={cn(
"flex items-center rounded-b-xl p-(--card-spacing)",
className
)}
data-slot="card-footer"
{...props}
/>
);
}
export {
Card,
CardAction,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
};Update the import paths to match your project setup.
Usage
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card";<Card>
<CardHeader>
<CardTitle>Frakment</CardTitle>
<CardDescription>Registry primitives for React.</CardDescription>
</CardHeader>
<CardContent>
<p>Copy-paste, not install.</p>
</CardContent>
<CardFooter>
<Button>Open</Button>
</CardFooter>
</Card>Composition
Card
├── CardHeader
│ ├── CardTitle
│ ├── CardDescription
│ └── CardAction
├── CardContent
└── CardFooterExamples
Small size
Pass size="sm" for tighter padding (12px) and smaller title.
- Choose a schedule (daily, or weekly).
- Send to channels or specific teammates.
- Include charts, tables, and key metrics.
import { ChevronRightIcon } from "lucide-react";
import { Button } from "@/components/ui/button";
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card";
export function CardSmall() {
const featureName = "Scheduled reports";
return (
<Card className="mx-auto w-full max-w-xs" size="sm">
<CardHeader>
<CardTitle>{featureName}</CardTitle>
<CardDescription>
Weekly snapshots. No more manual exports.
</CardDescription>
</CardHeader>
<CardContent>
<ul className="grid gap-2 py-2 text-sm">
<li className="flex gap-2">
<ChevronRightIcon className="text-muted-foreground mt-0.5 size-4 shrink-0" />
<span>Choose a schedule (daily, or weekly).</span>
</li>
<li className="flex gap-2">
<ChevronRightIcon className="text-muted-foreground mt-0.5 size-4 shrink-0" />
<span>Send to channels or specific teammates.</span>
</li>
<li className="flex gap-2">
<ChevronRightIcon className="text-muted-foreground mt-0.5 size-4 shrink-0" />
<span>Include charts, tables, and key metrics.</span>
</li>
</ul>
</CardContent>
<CardFooter className="flex-col gap-2">
<Button className="w-full" size="sm">
Set up scheduled reports
</Button>
<Button className="w-full" size="sm" variant="outline">
See what's new
</Button>
</CardFooter>
</Card>
);
}<Card size="sm" className="mx-auto w-full max-w-xs">
<CardHeader>
<CardTitle>Scheduled reports</CardTitle>
<CardDescription>Weekly snapshots.</CardDescription>
</CardHeader>
<CardContent>...</CardContent>
<CardFooter>...</CardFooter>
</Card>Custom spacing
Override --card-spacing via an inline arbitrary class — the entire card (header, content, footer) adapts.
"use client";
import * as React from "react";
import { Button } from "@/components/ui/button";
import {
Card,
CardAction,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
const spacingOptions = [
{
className: "[--card-spacing:--spacing(4)]",
label: "16px",
value: "4",
},
{
className: "[--card-spacing:--spacing(5)]",
label: "20px",
value: "5",
},
{
className: "[--card-spacing:--spacing(6)]",
label: "24px",
value: "6",
},
{
className: "[--card-spacing:--spacing(8)]",
label: "32px",
value: "8",
},
];
export function CardSpacing() {
const [spacing, setSpacing] = React.useState("4");
const selectedSpacing = spacingOptions.find(
(option) => option.value === spacing
);
return (
<div className="mx-auto grid w-full max-w-sm gap-4">
<ToggleGroup
className="justify-center"
onValueChange={(value) => {
if (value) {
setSpacing(value);
}
}}
size="sm"
type="single"
value={spacing}
variant="outline"
>
{spacingOptions.map((option) => (
<ToggleGroupItem key={option.value} value={option.value}>
{option.label}
</ToggleGroupItem>
))}
</ToggleGroup>
<Card className={selectedSpacing?.className}>
<CardHeader>
<CardTitle>Login to your account</CardTitle>
<CardDescription>
Enter your email below to login to your account
</CardDescription>
<CardAction>
<Button variant="link">Sign Up</Button>
</CardAction>
</CardHeader>
<CardContent>
<form>
<div className="flex flex-col gap-6">
<div className="grid gap-2">
<Label htmlFor="email-spacing">Email</Label>
<Input
id="email-spacing"
placeholder="m@example.com"
required
type="email"
/>
</div>
<div className="grid gap-2">
<div className="flex items-center">
<Label htmlFor="password-spacing">Password</Label>
<a
className="ml-auto inline-block text-sm underline-offset-4 hover:underline"
href="#"
>
Forgot your password?
</a>
</div>
<Input id="password-spacing" required type="password" />
</div>
</div>
</form>
</CardContent>
<CardFooter className="flex-col gap-2">
<Button className="w-full" type="submit">
Login
</Button>
<Button className="w-full" variant="outline">
Login with Google
</Button>
</CardFooter>
</Card>
</div>
);
}<Card className="[--card-spacing:--spacing(6)]">...</Card>Edge to edge
Negate --card-spacing on CardContent (-mb-(--card-spacing), -mx-(--card-spacing)) for full-bleed sections like scrollable terms.
These terms govern your use of the workspace, including access to shared documents, project files, and collaboration tools.
You are responsible for the content you upload and for ensuring that your team has the appropriate permissions to view or edit it.
We may update features or limits as the service evolves. When those changes materially affect your workflow, we will notify your workspace administrators.
By continuing, you agree to keep your account credentials secure and to follow your organization's acceptable use policies.
import { Button } from "@/components/ui/button";
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card";
export function CardEdgeToEdge() {
return (
<Card className="mx-auto w-full max-w-sm">
<CardHeader>
<CardTitle>Terms of Service</CardTitle>
<CardDescription>
Review the terms before accepting the agreement.
</CardDescription>
</CardHeader>
<CardContent className="-mb-(--card-spacing)">
<div className="bg-muted/50 -mx-(--card-spacing) max-h-48 space-y-4 overflow-y-scroll border-t px-(--card-spacing) py-4 text-sm leading-relaxed">
<p>
These terms govern your use of the workspace, including access to
shared documents, project files, and collaboration tools.
</p>
<p>
You are responsible for the content you upload and for ensuring that
your team has the appropriate permissions to view or edit it.
</p>
<p>
We may update features or limits as the service evolves. When those
changes materially affect your workflow, we will notify your
workspace administrators.
</p>
<p>
By continuing, you agree to keep your account credentials secure and
to follow your organization's acceptable use policies.
</p>
</div>
</CardContent>
<CardFooter className="justify-end gap-2">
<Button variant="outline">Decline</Button>
<Button>Accept</Button>
</CardFooter>
</Card>
);
}<CardContent className="-mb-(--card-spacing)">
<div className="-mx-(--card-spacing) px-(--card-spacing) py-4">...</div>
</CardContent>With image
Any <img> as the first child gets pt-0 + rounded top automatically — no extra classes needed on the image itself.
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import {
Card,
CardAction,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card";
export function CardImage() {
return (
<Card className="relative mx-auto w-full max-w-sm pt-0">
<div className="absolute inset-0 z-30 aspect-video bg-black/35" />
<img
alt="Event cover"
className="relative z-20 aspect-video w-full object-cover brightness-60 grayscale dark:brightness-40"
src="https://avatar.vercel.sh/frakment1"
/>
<CardHeader>
<CardAction>
<Badge variant="secondary">Featured</Badge>
</CardAction>
<CardTitle>Design systems meetup</CardTitle>
<CardDescription>
A practical talk on component APIs, accessibility, and shipping
faster.
</CardDescription>
</CardHeader>
<CardFooter>
<Button className="w-full">View Event</Button>
</CardFooter>
</Card>
);
}<Card className="pt-0">
<img alt="..." className="aspect-video w-full object-cover" src="..." />
<CardHeader>...</CardHeader>
</Card>In Context
Project list
42 components. Radix-based. Copy-paste first.
Message, Bubble, Trace, Attachment.
import { Button } from "@/components/ui/button";
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card";
export function CardProjectList() {
return (
<div className="mx-auto w-full max-w-sm space-y-3">
<Card>
<CardHeader>
<CardTitle>frakment/ui</CardTitle>
<CardDescription>Primitives for product surfaces.</CardDescription>
</CardHeader>
<CardContent>
<p className="text-sm">
42 components. Radix-based. Copy-paste first.
</p>
</CardContent>
<CardFooter>
<Button size="sm" variant="outline">
View
</Button>
</CardFooter>
</Card>
<Card>
<CardHeader>
<CardTitle>frakment/ai</CardTitle>
<CardDescription>
Chat, agent, and reasoning primitives.
</CardDescription>
</CardHeader>
<CardContent>
<p className="text-sm">Message, Bubble, Trace, Attachment.</p>
</CardContent>
<CardFooter>
<Button size="sm" variant="outline">
View
</Button>
</CardFooter>
</Card>
</div>
);
}API Reference
Card
| Prop | Type | Default | Description |
|---|---|---|---|
size | defaultsm | — | Root padding via --card-spacing (16px → 12px) and smaller title. |
Other parts
All other parts extend React.ComponentProps<"div"> and set data-slot="card-*" for styling hooks.
CSS Variables
| Variable | Default | Purpose |
|---|---|---|
--card-padding | --spacing(6) | Inner padding |
--card-radius | --radius-xl | Corner radius |
--card-spacing | --spacing(4) | Gap between sections |
Variants
| Variant | Use case |
|---|---|
default | Standard surface |
outline | Bordered, no elevation |
Data Attributes
| Attribute | Values |
|---|---|
data-slot | card, card-header, card-title, card-description, card-action, card-content, card-footer |
Accessibility
Cardrenders a plain<div>withdata-slot="card". It has no role by default; add one when the card represents a distinct region (e.g.role="region"witharia-labelledby).CardTitlerenders anh3. Use oneCardTitleper card so document outline stays flat.- Do not attach
onClickto the card surface. If the whole card is clickable, wrap it in a link and keep the actions as separate focusable elements. - Interactive content inside
CardFooterreceives focus in DOM order; keep destructive actions last.
Best Practices
- One idea per card. Split content into multiple cards rather than stacking everything inside one.
- Do not nest cards. Use
Separatorto divide sections inside a card. - Keep actions in the footer.
CardFooteraligns buttons and metadata to the end. - Use
CardTitleas a heading, not a label. For labels, usetext-sm font-mediumon a span. - Avoid full-surface hover unless the whole card is clickable. Mixed hover states confuse users.