# Card

A surface that groups related content about one object, optionally a link or a button as a whole.

- Family: display
- Import: `import { Card, CardHeader, CardBody, CardFooter, CardMedia } from "@senvenli/react/display";`
- Page: https://design.senvenli.com/docs/components/card
- JSON: https://design.senvenli.com/docs/components/card.json

## Example: Header, body and footer

Content about one object, with its actions on the footer rule.

```tsx
import { Button } from "@senvenli/react/action";
import { Card, CardBody, CardFooter, CardHeader, Text } from "@senvenli/react/display";

export default function Example() {
  return (
    <div className="max-w-sm">
      <Card>
        <CardHeader title="Order #1042" subtitle="Placed March 18, 2026" />
        <CardBody>
          <Text elementType="p">Three items for Ada Lovelace, shipping to London by standard delivery.</Text>
        </CardBody>
        <CardFooter>
          <Button>Print label</Button>
          <Button variant="primary">Mark as shipped</Button>
        </CardFooter>
      </Card>
    </div>
  );
}
```

## Examples

### With a photo

CardMedia sits flush to the edges at 16:9; without a `src` it shows an icon.

```tsx
import { Card, CardBody, CardHeader, CardMedia, Text } from "@senvenli/react/display";

// A flat placeholder photo drawn in the file, so the example needs no network.
const PHOTO = `data:image/svg+xml,${encodeURIComponent(
  `<svg xmlns="http://www.w3.org/2000/svg" width="1600" height="900"><rect width="100%" height="100%" fill="hsl(30 30% 62%)"/><text x="50%" y="50%" fill="hsl(30 30% 20%)" font-family="system-ui" font-size="72" text-anchor="middle" dominant-baseline="middle">Standing desk</text></svg>`,
)}`;

export default function Example() {
  return (
    <div className="grid max-w-2xl gap-ds-200 sm:grid-cols-2">
      <Card>
        <CardMedia src={PHOTO} />
        <CardHeader title="Standing desk" subtitle="Oak, 160 cm" />
        <CardBody>
          <Text tone="subtle">24 in stock</Text>
        </CardBody>
      </Card>
      <Card>
        <CardMedia fallbackIcon="package" />
        <CardHeader title="Monitor arm" subtitle="Dual, clamp mount" />
        <CardBody>
          <Text tone="subtle">No photo yet</Text>
        </CardBody>
      </Card>
    </div>
  );
}
```

### A card that is a link

The whole tile is one link named by its title, so it holds no other controls.

```tsx
import { Card, CardBody, CardHeader, Badge, Text } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";

export default function Example() {
  return (
    <div className="max-w-sm">
      <Card href="#">
        <CardHeader title="Project Atlas" subtitle="Website redesign" />
        <CardBody>
          <Stack direction="horizontal" space="space-100">
            <Badge tone="information">In progress</Badge>
            <Text tone="subtle">12 open tasks</Text>
          </Stack>
        </CardBody>
      </Card>
    </div>
  );
}
```

### Variants

Raised on the page, outline inside another surface, sunken for summaries.

```tsx
import { Card, CardBody, CardHeader, Text } from "@senvenli/react/display";

export default function Example() {
  return (
    <div className="grid gap-ds-200 sm:grid-cols-3">
      <Card density="compact">
        <CardHeader title="Raised" />
        <CardBody>
          <Text tone="subtle">The default, on the page.</Text>
        </CardBody>
      </Card>
      <Card variant="outline" density="compact">
        <CardHeader title="Outline" />
        <CardBody>
          <Text tone="subtle">Inside cards and settings groups.</Text>
        </CardBody>
      </Card>
      <Card variant="sunken" density="compact">
        <CardHeader title="Sunken" />
        <CardBody>
          <Text tone="subtle">For summaries and code.</Text>
        </CardBody>
      </Card>
    </div>
  );
}
```

## Guidelines

### When to use it

- Grouping content about one object on a page.
- A whole tile that opens a page (href) or a panel (onPress).

### Use something else when

- [separator](https://design.senvenli.com/docs/components/separator.md): Only a boundary between groups is needed.

### Do and avoid

- An interactive card holds no controls except the header menu.

## Accessibility

Built in:

- An interactive card is one focusable element named by its header title.

You provide:

- A CardHeader title, or `aria-label` on an interactive card without one.

## API reference

### Card

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| variant | `CardVariant` |  | no | `raised` on the page · `outline` inside cards and settings groups · `sunken` for summaries and code. |
| density | `Density` |  | no | `compact`: 16px padding instead of 24px. |
| radius | `ComponentRadius` |  | no | Corner radius: `none` to `full`; the design's `large` (or the provider's default) otherwise. |
| children | `React.ReactNode` |  | yes | Header, media, body and footer parts. |
| aria-label | `string` |  | no | The card's name when it is interactive and has no CardHeader title. |
| href | `string` |  | no | The whole card is a link (the interactive card): one focusable element named by its title. |
| onPress | `() => void` |  | no | The whole card is a button (opens a panel rather than a page). |

### CardHeader

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| title | `React.ReactNode` |  | yes |  |
| subtitle | `React.ReactNode` |  | no |  |
| headingLevel | `CardHeadingLevel` | `3` | no | Heading level of the title; default 3. |
| actions | `React.ReactNode` |  | no | At the header's end: a subtle menu button (`Button variant="subtle" iconOnly`); stays clickable above an interactive card. |

### CardBody

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| children | `React.ReactNode` |  | yes |  |

### CardFooter

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| children | `React.ReactNode` |  | yes |  |

### CardMedia

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| src | `string` |  | no | The photo, flush to the card edges at 16:9 and covering the frame. |
| alt | `string` | `""` | no | Describes the photo; "" when the title already says what it shows. |
| fallbackIcon | `IconName` | `"image"` | no | Shown on `ds-surface-sunken` when there is no photo. |

### Tokens it reads

`--ds-border`, `--ds-border-focused`, `--ds-border-selected`, `--ds-easing-standard`, `--ds-icon`, `--ds-icon-brand`, `--ds-icon-danger`, `--ds-icon-information`, `--ds-icon-subtle`, `--ds-icon-success`, `--ds-icon-warning`, `--ds-radius-large`, `--ds-shadow-overlay`, `--ds-shadow-raised`, `--ds-size-icon`, `--ds-size-icon-large`, `--ds-size-icon-small`, `--ds-space-025`, `--ds-space-050`, `--ds-space-100`, `--ds-space-150`, `--ds-space-200`, `--ds-space-300`, `--ds-surface-hovered`, `--ds-surface-raised`, `--ds-surface-sunken`, `--ds-text`, `--ds-text-subtlest`

## Related

- [separator](https://design.senvenli.com/docs/components/separator.md)
