# Card

> A server-component card with header, media, body, actions and separator parts, vertical or horizontal, rendered as a div, an article or a link.

Canonical: https://salmonui.dev/docs/layout/card

`Card` groups content about one subject. It ships as stable CSS classes
plus thin typed parts. None of the parts is a client component, so a card renders in React Server Components with no
JavaScript. It lives in `@salmonui/layout/card` with its own stylesheet.

```tsx
import { Card } from '@salmonui/layout/card';
import { Avatar } from '@salmonui/layout/avatar';
import { Button } from '@salmonui/buttons/button';
import '@salmonui/layout/card/styles.css';
import '@salmonui/layout/avatar/styles.css';
import '@salmonui/buttons/button/styles.css';

export function Profile() {
  return (
    <Card render={(props) => <article {...props} />}>
      <Card.Header media={<Avatar name="Ada Lovelace" shape="circle" />}>
        <Card.Title>Ada Lovelace</Card.Title>
        <Card.Description>Mathematician</Card.Description>
      </Card.Header>
      <Card.Body>Wrote the first algorithm intended for a machine.</Card.Body>
      <Card.Separator />
      <Card.Actions>
        <Button tone="primary">Follow</Button>
      </Card.Actions>
    </Card>
  );
}
```

### Live demo: Card

Live demo: https://salmonui.dev/demos/layout/card

A profile Card with an Avatar header, body, separator and actions, and a horizontal Card with media.

`Demo.tsx`:

```tsx
import { Avatar } from '@salmonui/layout/avatar';
import { Button } from '@salmonui/buttons/button';
import { Card } from '@salmonui/layout/card';

export default function CardDemo() {
  return (
    <div style={{ display: 'grid', gap: 16, maxWidth: 420 }}>
      <Card render={(props) => <article {...props} />}>
        <Card.Header media={<Avatar name="Ada Lovelace" shape="circle" />}>
          <Card.Title>Ada Lovelace</Card.Title>
          <Card.Description>Mathematician</Card.Description>
        </Card.Header>
        <Card.Body>Wrote the first algorithm intended to be carried out by a machine.</Card.Body>
        <Card.Separator />
        <Card.Actions>
          <Button variant="outline">Profile</Button>
          <Button tone="primary">Follow</Button>
        </Card.Actions>
      </Card>
      <Card orientation="horizontal">
        <Card.Media title="1843">
          {/* An inline illustration (no network request); a real app passes an image. */}
          <div style={{ width: 120, height: 96, display: 'grid', placeItems: 'center', color: 'var(--salmon-color-primary)', background: 'linear-gradient(135deg, var(--salmon-color-primary-subtle), var(--salmon-color-info-subtle))' }}>
            <svg viewBox="0 0 32 32" width="40" height="40" aria-hidden="true" fill="none" stroke="currentColor" strokeWidth="2">
              <circle cx="12" cy="14" r="5" />
              <path d="M12 5v3M12 20v3M3 14h3M18 14h3M5.6 7.6l2.1 2.1M16.3 18.3l2.1 2.1M5.6 20.4l2.1-2.1M16.3 9.7l2.1-2.1" />
              <circle cx="23" cy="24" r="3" />
            </svg>
          </div>
        </Card.Media>
        <Card.Body>Notes on the Analytical Engine.</Card.Body>
      </Card>
    </div>
  );
}
```

## Parts

| Part | Element and class |
| --- | --- |
| `Card` | `<div class="salmon-card">`; `render` swaps it (`<article>`, `<a>`) |
| `Card.Header` | `.salmon-card-header` with a `media` slot and a caption |
| `Card.Title` | `<h3 class="salmon-card-title">` (`level` 1 to 6) |
| `Card.Description` | `<p class="salmon-card-description">` |
| `Card.Media` | `.salmon-card-media`, full-bleed `<img>` / `<video>`, optional `title` overlay |
| `Card.Body` | `.salmon-card-body` |
| `Card.Actions` | `.salmon-card-actions`, `orientation: 'horizontal' \| 'vertical'` |
| `Card.Separator` | `<hr class="salmon-card-separator">` |

Every part is also exported flat (`CardHeader`, `CardTitle`, ...) for
server-component trees. The classes are stable styling hooks, so plain
markup with `.salmon-card` classes also works.

- The header `media` slot takes any node; for a round header image use
  `Avatar` with `shape="circle"`.
- `orientation="horizontal"` puts media and content side by side; it
  mirrors in RTL.
- Stacked sections inside a horizontal card have no dedicated class: nest
  `Card.Body` elements in your own grid.
- A whole-card link is `render={(p) => <a {...p} href="/ada" />}`; keep
  buttons out of a linked card.

The stylesheet is 0.70 KB gzip; the JavaScript is 0.62 KB.

API reference: [`@salmonui/layout/card`](https://salmonui.dev/docs/reference/layout/card) and [`@salmonui/layout/avatar`](https://salmonui.dev/docs/reference/layout/avatar).
