<!-- index: /slotted/llms.txt -->
# card

`data-ui="card"` · Bordered surface that groups related content.

## Minimal example

Example

```tsx
import { Button } from '@slotted/react/button';
import { Card, CardBody, CardFooter, CardHeader } from '@slotted/react/card';
import { Heading, Text } from '@slotted/react/typography';

export default function CardBasic() {
  return (
    <Card>
      <CardHeader>
        <Heading level={2} size="md">
          Meridian Packaging
        </Heading>
        <Text size="sm" tone="muted">
          Supplier since 2019
        </Text>
      </CardHeader>
      <CardBody>
        <Text>Delivers pallets of cartons to Rotterdam every Tuesday and Friday.</Text>
      </CardBody>
      <CardFooter>
        <Button variant="outline">View orders</Button>
      </CardFooter>
    </Card>
  );
}
```

## Props

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `bleed` | `boolean` | false | CardBody | Runs the children of the body from one edge of the card to the other. The body gives up its padding and is clipped to the corners of the card it touches. Use it for a list whose rules and row grounds reach the edge. |
| `orientation` | `'vertical' \| 'horizontal'` | vertical | Card | Puts the media beside the regions, and returns it to the top in a narrow container. |
| `fill` | `'outline' \| 'elevated' \| 'subtle'` | outline | Card | Sets how the surface is bounded: a hairline edge, the edge plus a lift, or a filled ground. |
| `size` | `'sm' \| 'md' \| 'lg'` | md | Card | Sets the inset of the card itself. Density is the application's choice; this inset is the card's. |
| `selected` | `boolean` | false | Card | Mirrors a selection that your page owns. The control inside the card is what announces it. |
| `disabled` | `boolean` | false | Card | Mirrors a control that your page has disabled. The card disables nothing itself. |
| `render` | `(props) => ReactNode` | — | Card, CardMedia, CardHeader, CardActions, CardSelection, CardBody, CardFooter, CardLink | Renders the part into another element from the props it receives. |
| `ref` | `Ref<HTMLElement>` | — | every part | Reaches the native element. Each part extends the props of its own element. |
| `href` | `string` | — | CardLink | Sets the destination of the card, on the anchor whose hit area covers the surface. |
| `CardDefaultsProvider` | `{ fill, orientation, size }` | — | a subtree | Sets the defaults once for every card under it. An explicit prop still wins. |

## Axes and defaults

| Axis | Values | Default |
| --- | --- | --- |
| `orientation` | `vertical`, `horizontal` | `vertical` |
| `fill` | `outline`, `elevated`, `subtle` | `outline` |
| `size` | `sm`, `md`, `lg` | `md` |

## Rules

- There is no card pattern in the WAI-ARIA Authoring Practices, and a card is structure rather than a widget. The applicable guidance is Structural Roles: use the HTML element that already carries the meaning.
- The root is a div with no role. Use render to make it an article with its own heading, a section, the li of a list of results, or the label of a chooser — whichever the page actually means.
- The card contributes no keyboard behavior. CardLink is an anchor, so Enter, the context menu and middle-click are the platform’s.
- CardLink is named by its own text. A card whose root were the link would take every string inside it into that name, which is the reason the hit area is stretched from the link instead.
- A card carries at most one CardLink, and it navigates. A whole surface that fires a command on any click, with no visible control boundary, is a misclick nobody can undo; put a button in CardActions or the footer instead.
- CardActions and CardFooter both sit above the stretched hit area, so a control in either stays operable. An interactive element anywhere else needs position: relative of its own.
- Text over the stretched area cannot be selected with the pointer. That is the cost of the whole-card target, and the reason a card with no CardLink stretches nothing.
- selected and disabled are painted, never announced. The radio, checkbox or button inside the card is what carries the state for assistive technology.
- selected is the accent surface under a hairline accent edge, the pair a selected row paints. In high contrast and forced colors both flatten, and the checked control inside is what carries the state. elevated keeps its hairline because a shadow is removed there outright.
- The focus ring is drawn on the card while the link has focus. In a browser without :has() the link keeps its own native outline instead.
- A rule between two regions is a Divider written between them. It is announced as a separator unless it is marked decorative, which is usually what a rule inside one card is.

## Tokens

`--slotted-action-gap`, `--slotted-border-strong`, `--slotted-border-subtle`, `--slotted-border-width-thin`, `--slotted-card-actions-gap`, `--slotted-card-background`, `--slotted-card-background-disabled`, `--slotted-card-background-selected`, `--slotted-card-background-selected-active`, `--slotted-card-background-selected-hover`, `--slotted-card-background-subtle`, `--slotted-card-border-color`, `--slotted-card-border-color-disabled`, `--slotted-card-border-color-hover`, `--slotted-card-border-width`, `--slotted-card-color`, `--slotted-card-color-disabled`, `--slotted-card-edge-color-selected`, `--slotted-card-edge-width-selected`, `--slotted-card-footer-gap`, `--slotted-card-header-column-gap`, `--slotted-card-header-gap`, `--slotted-card-media-size`, `--slotted-card-padding-block`, `--slotted-card-padding-block-lg`, `--slotted-card-padding-block-sm`, `--slotted-card-padding-inline`, `--slotted-card-padding-inline-lg`, `--slotted-card-padding-inline-sm`, `--slotted-card-radius`, `--slotted-card-region-gap`, `--slotted-card-region-gap-lg`, `--slotted-card-region-gap-sm`, `--slotted-card-selection-line`, `--slotted-card-selection-size`, `--slotted-card-shadow`, `--slotted-card-shadow-hover`, `--slotted-disabled-background`, `--slotted-disabled-border`, `--slotted-disabled-foreground`, `--slotted-duration-short`, `--slotted-easing-standard`, `--slotted-focus-ring-color`, `--slotted-focus-ring-offset`, `--slotted-focus-ring-width`, `--slotted-font-size-lg`, `--slotted-line-height-lg`, `--slotted-radius-lg`, `--slotted-selection-size-md`, `--slotted-shadow-lg`, `--slotted-shadow-md`, `--slotted-shadow-sm`, `--slotted-shadow-xs`, `--slotted-space-2`, `--slotted-space-3`, `--slotted-space-4`, `--slotted-space-5`, `--slotted-space-6`, `--slotted-space-8`, `--slotted-surface-raised`, `--slotted-surface-sunken`, `--slotted-text`, `--slotted-tone-accent-border`, `--slotted-tone-accent-subtle-active`, `--slotted-tone-accent-subtle-hover`, `--slotted-tone-accent-surface`, `--slotted-tone-secondary-subtle-active`

## Examples

### The regions, and the corner of the header

Excerpt — not a complete module

```tsx
<Card>
  <CardHeader>
    <Heading level={3}>Northwind billing</Heading>
    <Text size="sm" tone="muted">
      Invoices and payment methods
    </Text>
    <CardActions>
      <Badge tone="warning">Overdue</Badge>
    </CardActions>
  </CardHeader>
  <CardBody>The next invoice settles on 1 October.</CardBody>
  <CardFooter>
    <button type="button">Pay now</button>
  </CardFooter>
</Card>;
```

### A rule between two regions

Excerpt — not a complete module

```tsx
<Card>
  <CardHeader>
    <Heading level={3}>Review pictures</Heading>
  </CardHeader>
  <Divider decorative />
  <CardBody>Two hundred images since the last visit.</CardBody>
  <Divider decorative inset />
  <CardFooter>
    <Text size="xs" tone="muted">
      The inset rule lines up with the text
    </Text>
  </CardFooter>
</Card>;
```

### One destination, named by the title

Excerpt — not a complete module

```tsx
<Card>
  <CardHeader>
    <CardLink href="/accounts/northwind">
      <Heading level={3}>Northwind Traders</Heading>
    </CardLink>
  </CardHeader>
  <CardBody>Twelve open invoices</CardBody>
  <CardFooter>
    <a href="/accounts/northwind/settings">Billing settings</a>
  </CardFooter>
</Card>;
```

### A chooser, where the radio owns the state

Excerpt — not a complete module

```tsx
<Card render={(props) => <label {...props} />} selected={plan === 'team'}>
  <CardHeader>
    <CardSelection>
      <input
        checked={plan === 'team'}
        name="plan"
        onChange={() => setPlan('team')}
        type="radio"
        value="team"
      />
    </CardSelection>
    <Heading level={3}>Team</Heading>
    <Text size="sm" tone="muted">
      Twenty seats and shared billing
    </Text>
  </CardHeader>
</Card>;
```

### Media beside the content, until the card is narrow

Excerpt — not a complete module

```tsx
<Card orientation="horizontal">
  <CardMedia>
    <img alt="" src={report.cover} />
  </CardMedia>
  <CardHeader>
    <Heading level={3}>Quarterly report</Heading>
  </CardHeader>
  <CardBody>Revenue, retention and the accounts that moved them.</CardBody>
</Card>;
```

### One decision for every card in the application

Excerpt — not a complete module

```tsx
<CardDefaultsProvider fill="elevated" size="lg">
  <Dashboard />
</CardDefaultsProvider>;
```

### bleed.tsx

Example

```tsx
import { Card, CardBody, CardHeader } from '@slotted/react/card';
import { List } from '@slotted/react/list';
import {
  ListItem,
  ListItemBody,
  ListItemContent,
  ListItemEnd,
  ListItemLabel,
} from '@slotted/react/list-item';
import { Heading, Text } from '@slotted/react/typography';

const INVOICES = [
  { id: '20418', supplier: 'Meridian Packaging', amount: '$4,820.00' },
  { id: '20431', supplier: 'Alder Freight', amount: '$12,115.50' },
  { id: '20437', supplier: 'Kestrel Pallets', amount: '$1,340.00' },
];

export default function CardBleed() {
  return (
    <Card>
      <CardHeader>
        <Heading level={2} size="md">
          Open invoices
        </Heading>
        <Text size="sm" tone="muted">
          Due before 31 December
        </Text>
      </CardHeader>
      <CardBody bleed>
        <List aria-label="Open invoices" variant="ruled">
          {INVOICES.map((invoice) => (
            <ListItem key={invoice.id}>
              <ListItemContent>
                <ListItemBody>
                  <ListItemLabel>{invoice.supplier}</ListItemLabel>
                </ListItemBody>
                <ListItemEnd>{invoice.amount}</ListItemEnd>
              </ListItemContent>
            </ListItem>
          ))}
        </List>
      </CardBody>
    </Card>
  );
}
```

### choice.tsx

Example

```tsx
import { useState } from 'react';
import { Card, CardHeader, CardSelection } from '@slotted/react/card';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

const METHODS = [
  { id: 'standard', name: 'Standard', note: '5 to 7 days, free', available: true },
  { id: 'express', name: 'Express', note: '2 days, $12.00', available: true },
  { id: 'same-day', name: 'Same day', note: 'Not offered for this address', available: false },
];

export default function CardChoice() {
  const [method, setMethod] = useState('standard');

  return (
    <Stack aria-label="Delivery method" gap={3} role="radiogroup">
      {METHODS.map((option) => (
        <Card
          disabled={!option.available}
          key={option.id}
          render={(props) => <label {...props} />}
          selected={method === option.id}
        >
          <CardHeader>
            <CardSelection>
              <input
                checked={method === option.id}
                disabled={!option.available}
                name="delivery"
                onChange={() => {
                  setMethod(option.id);
                }}
                type="radio"
                value={option.id}
              />
            </CardSelection>
            <Text size="lg" weight="semibold">
              {option.name}
            </Text>
            <Text size="sm" tone="muted">
              {option.note}
            </Text>
          </CardHeader>
        </Card>
      ))}
    </Stack>
  );
}
```

### defaults.tsx

Example

```tsx
import { Card, CardBody, CardDefaultsProvider, CardHeader } from '@slotted/react/card';
import { Grid } from '@slotted/react/grid';
import { Heading, Text } from '@slotted/react/typography';

export default function CardDefaults() {
  return (
    <CardDefaultsProvider fill="elevated" size="lg">
      <Grid columns={2} gap={4} minItemWidth="xs">
        <Card>
          <CardHeader>
            <Heading level={2} size="md">
              Orders shipped
            </Heading>
            <Text size="sm" tone="muted">
              elevated, lg
            </Text>
          </CardHeader>
          <CardBody>
            <Text>312 orders left the Reno warehouse today.</Text>
          </CardBody>
        </Card>

        <Card fill="outline" size="sm">
          <CardHeader>
            <Heading level={2} size="md">
              Returns received
            </Heading>
            <Text size="sm" tone="muted">
              outline, sm
            </Text>
          </CardHeader>
          <CardBody>
            <Text>18 returns arrived and 11 are restocked.</Text>
          </CardBody>
        </Card>
      </Grid>
    </CardDefaultsProvider>
  );
}
```

### dividers.tsx

Example

```tsx
import { Card, CardBody, CardFooter, CardHeader } from '@slotted/react/card';
import { Divider } from '@slotted/react/divider';
import { Heading, Text } from '@slotted/react/typography';

export default function CardDividers() {
  return (
    <Card>
      <CardHeader>
        <Heading level={2} size="md">
          Rotterdam warehouse
        </Heading>
        <Text size="sm" tone="muted">
          Pallet capacity
        </Text>
      </CardHeader>
      <Divider decorative />
      <CardBody>
        <Text>8,420 of 10,000 pallet positions are in use.</Text>
      </CardBody>
      <Divider decorative inset />
      <CardFooter>
        <Text size="sm" tone="muted">
          Counted on 24 November at 06:00.
        </Text>
      </CardFooter>
    </Card>
  );
}
```

### fills.tsx

Example

```tsx
import { Card, CardBody, CardHeader } from '@slotted/react/card';
import type { CardFill } from '@slotted/react/card';
import { Grid } from '@slotted/react/grid';
import { Heading, Text } from '@slotted/react/typography';

const SUMMARIES: { fill: CardFill; title: string; body: string }[] = [
  { fill: 'outline', title: 'Open purchase orders', body: '14 orders, 3 awaiting approval.' },
  { fill: 'elevated', title: 'Invoices due this week', body: '6 invoices totaling $18,240.' },
  { fill: 'subtle', title: 'Reorder alerts', body: '9 products below their reorder point.' },
];

export default function CardFills() {
  return (
    <Grid columns={3} gap={4} minItemWidth="xs">
      {SUMMARIES.map((summary) => (
        <Card fill={summary.fill} key={summary.fill}>
          <CardHeader>
            <Heading level={2} size="md">
              {summary.title}
            </Heading>
            <Text size="sm" tone="muted">{`fill: ${summary.fill}`}</Text>
          </CardHeader>
          <CardBody>
            <Text>{summary.body}</Text>
          </CardBody>
        </Card>
      ))}
    </Grid>
  );
}
```

### horizontal.tsx

Example

```tsx
import { Button } from '@slotted/react/button';
import { Card, CardBody, CardFooter, CardHeader, CardMedia } from '@slotted/react/card';
import { Heading, Text } from '@slotted/react/typography';

const COVER =
  "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 320 160'%3E%3Crect width='320' height='160' fill='%23c7d2fe'/%3E%3Crect x='40' y='70' width='80' height='90' fill='%234338ca'/%3E%3Crect x='130' y='40' width='70' height='120' fill='%236366f1'/%3E%3Crect x='210' y='85' width='70' height='75' fill='%234338ca'/%3E%3C/svg%3E";

export default function CardHorizontal() {
  return (
    <Card orientation="horizontal">
      <CardMedia>
        <img alt="" src={COVER} />
      </CardMedia>
      <CardHeader>
        <Heading level={2} size="md">
          Rotterdam warehouse
        </Heading>
        <Text size="sm" tone="muted">
          Capacity report, Q4
        </Text>
      </CardHeader>
      <CardBody>
        <Text>Pallet positions in use rose from 71% to 84% between October and November.</Text>
      </CardBody>
      <CardFooter>
        <Button variant="outline">Open report</Button>
      </CardFooter>
    </Card>
  );
}
```

### link.tsx

Example

```tsx
import { Card, CardBody, CardFooter, CardHeader, CardLink } from '@slotted/react/card';
import { Link } from '@slotted/react/link';
import { Heading, Text } from '@slotted/react/typography';

export default function CardLinkExample() {
  return (
    <Card>
      <CardHeader>
        <CardLink href="#meridian">
          <Heading level={2} size="md">
            Meridian Packaging
          </Heading>
        </CardLink>
        <Text size="sm" tone="muted">
          Supplier since 2019
        </Text>
      </CardHeader>
      <CardBody>
        <Text>12 open invoices totaling $31,460.00.</Text>
      </CardBody>
      <CardFooter>
        <Link href="#meridian-terms">Payment terms</Link>
      </CardFooter>
    </Card>
  );
}
```

### media.tsx

Example

```tsx
import { Button } from '@slotted/react/button';
import { Card, CardBody, CardFooter, CardHeader, CardMedia } from '@slotted/react/card';
import { Heading, Text } from '@slotted/react/typography';

const COVER =
  "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 320 160'%3E%3Crect width='320' height='160' fill='%23c7d2fe'/%3E%3Crect x='40' y='70' width='80' height='90' fill='%234338ca'/%3E%3Crect x='130' y='40' width='70' height='120' fill='%236366f1'/%3E%3Crect x='210' y='85' width='70' height='75' fill='%234338ca'/%3E%3C/svg%3E";

export default function CardMediaExample() {
  return (
    <Card>
      <CardMedia>
        <img alt="" src={COVER} />
      </CardMedia>
      <CardHeader>
        <Heading level={2} size="md">
          Meridian Packaging
        </Heading>
        <Text size="sm" tone="muted">
          Rotterdam, 3 warehouses
        </Text>
      </CardHeader>
      <CardBody>
        <Text>14 purchase orders are open, and the next delivery arrives on Tuesday.</Text>
      </CardBody>
      <CardFooter>
        <Button variant="outline">View supplier</Button>
      </CardFooter>
    </Card>
  );
}
```

### regions.tsx

Example

```tsx
import { Badge } from '@slotted/react/badge';
import { Button } from '@slotted/react/button';
import { Card, CardActions, CardBody, CardFooter, CardHeader } from '@slotted/react/card';
import { Inline } from '@slotted/react/inline';
import { Heading, Text } from '@slotted/react/typography';

export default function CardRegions() {
  return (
    <Card>
      <CardHeader>
        <Heading level={2} size="md">
          Invoice 20418
        </Heading>
        <Text size="sm" tone="muted">
          Meridian Packaging
        </Text>
        <CardActions>
          <Badge tone="warning">Overdue</Badge>
        </CardActions>
      </CardHeader>
      <CardBody>
        <Text>$4,820.00 was due on 15 November. A late fee of 1.5% applies from 1 December.</Text>
      </CardBody>
      <CardFooter>
        <Inline>
          <Button>Pay invoice</Button>
          <Button tone="secondary" variant="outline">
            Download PDF
          </Button>
        </Inline>
      </CardFooter>
    </Card>
  );
}
```

### sizes.tsx

Example

```tsx
import { Card, CardBody, CardFooter, CardHeader } from '@slotted/react/card';
import type { CardSize } from '@slotted/react/card';
import { Grid } from '@slotted/react/grid';
import { Heading, Text } from '@slotted/react/typography';

const SIZES: CardSize[] = ['sm', 'md', 'lg'];

export default function CardSizes() {
  return (
    <Grid columns={3} gap={4} minItemWidth="xs">
      {SIZES.map((size) => (
        <Card key={size} size={size}>
          <CardHeader>
            <Heading level={2} size="md">
              Invoice 20418
            </Heading>
            <Text size="sm" tone="muted">{`size: ${size}`}</Text>
          </CardHeader>
          <CardBody>
            <Text>$4,820.00, due 15 December.</Text>
          </CardBody>
          <CardFooter>
            <Text size="sm" tone="muted">
              Meridian Packaging
            </Text>
          </CardFooter>
        </Card>
      ))}
    </Grid>
  );
}
```
