# Card

A compound surface for grouped content and actions.

A compound surface for grouped content and actions.

```tsx
import { Card, Stack } from "@zentara-co/zenos-ui";

function CardPreviewExample() {
  return (
    <Stack direction="row" gap="4" wrap="wrap" className="w-full justify-center">
      <Card className="w-full max-w-64">
        <Card.Header>
          <Card.Title>Workspace</Card.Title>
          <Card.Description>12 active members</Card.Description>
        </Card.Header>
      </Card>
      <Card variant="grey" className="w-full max-w-64">
        <Card.Header>
          <Card.Title>Security score</Card.Title>
          <Card.Description>94 of 100</Card.Description>
        </Card.Header>
      </Card>
    </Stack>
  );
}
```

## Import

```tsx
import { Card } from "@zentara-co/zenos-ui";
```

## Anatomy

Use the parts only when the layout needs them. `Card.Header` groups title and description; `Card.Action` aligns trailing controls in the header row.

```tsx
<Card>
  <Card.Media>{/* photo or video */}</Card.Media>
  <Card.Header>
    <Card.Title tooltip="Optional context">Workspace</Card.Title>
    <Card.Description>12 active members</Card.Description>
    <Card.Action>{/* optional */}</Card.Action>
  </Card.Header>
  <Card.Content>{/* body */}</Card.Content>
  <Card.Footer>{/* actions */}</Card.Footer>
</Card>
```

## Variants

The default surface uses the neutral card fill (`background-neutral-card`), default border, and `rounded-lg` corners. Title and description use `type-body-l` medium and `type-body-s` regular text.

`variant="grey"` applies accent gray subtlest fill and a muted border—use it for secondary metrics, nested groups, or quieter dashboards without changing the internal spacing.

Use `variant="white"` for a white surface in light mode that matches the default card background in dark mode. It uses `background-default` in light mode and `background-neutral-card` in dark mode, with text and icons following the active theme. ClickableCard and SelectableCard share this variant; their hover, pressed, selected, and disabled treatments still apply.

```tsx
import { Card, Stack } from "@zentara-co/zenos-ui";

type CatalogVariantProps = { limit?: number };

const limited = <T,>(items: readonly T[], limit?: number) =>
  limit === undefined ? items : items.slice(0, limit);

function CardVariantsExample({ limit }: CatalogVariantProps = {}) {
  return (
    <Stack direction="row" gap="4" wrap="wrap" align="stretch" className="w-full max-w-3xl">
      {limited(["default", "grey", "white"] as const, limit).map((variant) => (
        <Card key={variant} variant={variant} className="min-w-56 flex-1">
          <Card.Header>
            <Card.Title className="capitalize">{variant}</Card.Title>
            <Card.Description>
              {variant === "default"
                ? "Neutral card fill with default border."
                : variant === "white"
                  ? "White in light mode; dark in dark mode."
                  : "Subtle gray fill for quieter grouped surfaces."}
            </Card.Description>
          </Card.Header>
        </Card>
      ))}
    </Stack>
  );
}
```

## Composition

Compose headers, supporting text, content, and actions only when the card needs them. Comfortable density uses spacing 4 on every outer edge (`px-4`, `pt-4`, and `pb-4`), while adjacent regions meet without duplicate padding. A header followed by content keeps `pb-4` (`pb-3` at compact density). A header-only card keeps the same balanced inset.

```tsx
import { Button, Card, Text } from "@zentara-co/zenos-ui";

function CardCompositionExample() {
  return (
    <Card className="w-full max-w-md">
      <Card.Header>
        <Card.Title tooltip="Scores reflect the last completed scan.">Security posture</Card.Title>
        <Card.Description>Last evaluated 8 minutes ago</Card.Description>
      </Card.Header>
      <Card.Content>
        <Text>18 controls passed and two need review.</Text>
      </Card.Content>
      <Card.Footer className="gap-3">
        <Button size="sm" variant="primary">
          Review findings
        </Button>
        <Button size="sm" variant="ghost">
          Dismiss
        </Button>
      </Card.Footer>
    </Card>
  );
}
```

## Media

`Card.Media` frames a photo or video inside the card. A 4px inset on the sides, and on the edge that meets the card, is tighter than the copy padding, so the picture reads as framed. The frame radius is the card radius minus that inset and the card border, which keeps the corners concentric. Put overlay badges inside the frame so they anchor to the picture. The frame is `aspect-video`. Pass another ratio with `className`. The image or video is a direct child and fills the frame.

```tsx
import { Badge, Button, Card, Stack } from "@zentara-co/zenos-ui";

function CardMediaExample() {
  return (
    <Stack direction="row" gap="4" wrap="wrap" align="start" className="w-full justify-center">
      <Card className="w-full max-w-72">
        <Card.Media>
          <img
            src="https://images.unsplash.com/photo-1616486338812-3dadae4b4ace?auto=format&fit=crop&w=800&q=80"
            alt="Living room with plants and a rust-colored chair"
          />
          <Badge variant="solid" color="neutral" rounded className="absolute start-2 top-2">
            Best seller
          </Badge>
        </Card.Media>
        <Card.Header>
          <Card.Title>Interior kit</Card.Title>
          <Card.Description>48 rooms, 6 moods, every one editable.</Card.Description>
        </Card.Header>
        <Card.Content>
          <Button variant="primary" className="w-full">
            View kit
          </Button>
        </Card.Content>
      </Card>
      <Card className="w-full max-w-72">
        <Card.Header>
          <Card.Title>Mountain retreat</Card.Title>
          <Card.Description>Media can close the card too.</Card.Description>
        </Card.Header>
        <Card.Media>
          <img
            src="https://images.unsplash.com/photo-1469474968028-56623f02e42e?auto=format&fit=crop&w=800&q=80"
            alt="Sunlit mountain valley above a green cliff"
          />
        </Card.Media>
      </Card>
    </Stack>
  );
}
```

## Density

Card supports `density="comfortable | compact"` and inherits the nearest `DensityProvider` when the prop is omitted. Compact density reduces region padding and title scale without changing the selected surface or radius. Buttons and inputs nested in the card inherit the same preset unless they set an explicit `size`.

See the [Density foundation](/foundations/density/) for comparison and provider examples.

## Custom styling

Pass `className` on `Card` (or `Card.Root`) to replace the surface, border, or layout. Prefer semantic tokens so light and dark themes stay coherent. Override title or description color on `Card.Title` and `Card.Description` when the root uses a tinted fill.

Layout-only utilities such as `max-w-md` or `w-full` leave the built-in variant untouched. Custom classes merge last on the root.

```tsx
import { Card, Text } from "@zentara-co/zenos-ui";

function CardCustomExample() {
  return (
    <Card className="w-full max-w-md border-border-accent-purple-default bg-background-accent-purple-subtlest-default">
      <Card.Header>
        <Card.Title className="text-text-accent-purple-bolder">Quarterly campaign</Card.Title>
        <Card.Description className="text-text-accent-purple-bolder/80">
          Three audiences and 24 published assets.
        </Card.Description>
      </Card.Header>
      <Card.Content>
        <Text size="s" className="text-text-accent-purple-bolder/90">
          Override the root surface with semantic tokens; header spacing and title scales stay the
          same.
        </Text>
      </Card.Content>
    </Card>
  );
}
```

## Card or another component

Use [ClickableCard](/components/clickable-card/) when the whole surface should activate one action or link. Use [SelectableCard](/components/selectable-card/) for checkbox or radio selection inside forms. Keep static summaries and read-only metrics on `Card`.

## Anatomy

```text
Card.Root
Card.Header
Card.Title
Card.Description
Card.Action
Card.Content
Card.Media
Card.Footer
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| variant | default \| grey \| white | default | Default uses neutral card fill; grey uses accent gray subtlest fill; white uses background-default and follows the active theme. |
| density | comfortable \| compact | comfortable | Controls Card spacing and title scale. Inherits from the nearest DensityProvider when omitted. |
| tooltip | ReactNode | — | Optional information tooltip on Card.Title. |
| Media className | string | — | Merged last on Card.Media. The frame is aspect-video; pass another ratio here. |
| className | string | — | Merged last on the root. Use semantic tokens to replace surface and border while keeping internal spacing. |
| native props | React.HTMLAttributes<HTMLDivElement> | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

`Card` is a structural `div` and does not add interaction semantics. Use headings in a logical order, keep action labels meaningful, and use `ClickableCard` or `SelectableCard` when the whole surface needs to be interactive.

Source: https://zenos-ui.pages.dev/components/card/