# Card

A container for grouping related content and actions.

> For the complete documentation index, see [llms.txt](/llms.txt). Markdown variants are available by appending `.md` to any URL or sending an `Accept: text/markdown` header. An agent skill is available at [/.well-known/agent-skills/site-skill.md](/.well-known/agent-skills/site-skill.md).

<DocsBaseSwitcher base="web" component="card" />

<ComponentPreview name="card-image" title="card-image.tsx" src="examples/card-image.tsx" previewClassName="h-auto py-8">
<o />
</ComponentPreview>

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 [#installation]

<CodeTabs>
<TabsList>
<TabsTrigger value="cli">
Command
</TabsTrigger>

<TabsTrigger value="manual">
Manual
</TabsTrigger>
</TabsList>

<TabsContent value="cli">
```bash
npx frakment add card
```
</TabsContent>

<TabsContent value="manual">
<Steps>
<Step>
Copy and paste the following code into your project.
</Step>

<ComponentSource name="card" title="components/ui/card.tsx" />

<Step>
Update the import paths to match your project setup.
</Step>
</Steps>
</TabsContent>
</CodeTabs>

## Usage [#usage]

```tsx title="card.tsx"
import {
  Card,
  CardContent,
  CardDescription,
  CardFooter,
  CardHeader,
  CardTitle,
} from "@/components/ui/card";
```

```tsx
<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 [#composition]

```text
Card
├── CardHeader
│   ├── CardTitle
│   ├── CardDescription
│   └── CardAction
├── CardContent
└── CardFooter
```

## Examples [#examples]

### Small size [#small-size]

Pass `size="sm"` for tighter padding (12px) and smaller title.

<ComponentPreview name="card-small" title="card-small.tsx" src="examples/card-small.tsx" previewClassName="h-auto py-8">
<r />
</ComponentPreview>

```tsx
<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 [#custom-spacing]

Override `--card-spacing` via an inline arbitrary class — the entire card (header, content, footer) adapts.

<ComponentPreview name="card-spacing" title="card-spacing.tsx" src="examples/card-spacing.tsx" previewClassName="h-auto py-8">
<CardSpacing />
</ComponentPreview>

```tsx
<Card className="[--card-spacing:--spacing(6)]">...</Card>
```

### Edge to edge [#edge-to-edge]

Negate `--card-spacing` on `CardContent` (`-mb-(--card-spacing)`, `-mx-(--card-spacing)`) for full-bleed sections like scrollable terms.

<ComponentPreview name="card-edge-to-edge" title="card-edge-to-edge.tsx" src="examples/card-edge-to-edge.tsx" previewClassName="h-auto py-8">
<h />
</ComponentPreview>

```tsx
<CardContent className="-mb-(--card-spacing)">
  <div className="-mx-(--card-spacing) px-(--card-spacing) py-4">...</div>
</CardContent>
```

### With image [#with-image]

Any `<img>` as the first child gets `pt-0` + rounded top automatically — no extra classes needed on the image itself.

<ComponentPreview name="card-image" title="card-image.tsx" src="examples/card-image.tsx" previewClassName="h-auto py-8">
<o />
</ComponentPreview>

```tsx
<Card className="pt-0">
  <img alt="..." className="aspect-video w-full object-cover" src="..." />
  <CardHeader>...</CardHeader>
</Card>
```

## In Context [#in-context]

### Project list [#project-list]

<ComponentPreview name="card-project-list" title="card-project-list.tsx" src="examples/card-project-list.tsx" previewClassName="h-auto py-8">
<c />
</ComponentPreview>

## API Reference [#api-reference]

### Card [#card]

<PropsTable rows={[{"name":"size","type":"default | sm","defaultValue":"default","description":"Root padding via --card-spacing (16px → 12px) and smaller title."}]} />

### Other parts [#other-parts]

All other parts extend `React.ComponentProps<"div">` and set `data-slot="card-*"` for styling hooks.

## CSS Variables [#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 [#variants]

| Variant | Use case |
| :-- | :-- |
| `default` | Standard surface |
| `outline` | Bordered, no elevation |

## Data Attributes [#data-attributes]

| Attribute | Values |
| :-- | :-- |
| `data-slot` | `card`, `card-header`, `card-title`, `card-description`, `card-action`, `card-content`, `card-footer` |

## Accessibility [#accessibility]

- `Card` renders a plain `<div>` with `data-slot="card"`. It has no role by default; add one when the card represents a distinct region (e.g. `role="region"` with `aria-labelledby`).
- `CardTitle` renders an `h3`. Use one `CardTitle` per card so document outline stays flat.
- Do not attach `onClick` to 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 `CardFooter` receives focus in DOM order; keep destructive actions last.

## Best Practices [#best-practices]

- **One idea per card.** Split content into multiple cards rather than stacking everything inside one.
- **Do not nest cards.** Use `Separator` to divide sections inside a card.
- **Keep actions in the footer.** `CardFooter` aligns buttons and metadata to the end.
- **Use `CardTitle` as a heading, not a label.** For labels, use `text-sm font-medium` on a span.
- **Avoid full-surface hover unless the whole card is clickable.** Mixed hover states confuse users.

## Related Components [#related-components]

- [Item](/docs/components/web/item) — row-level container
- [Accordion](/docs/components/web/accordion) — collapsible content
- [Tabs](/docs/components/web/tabs) — switch content panes