# Card

> Bordered surface with an optional header, a body slot and a footer band; it can lift on hover when the whole card is a link.

- Kind: ui · Category: Data display · Interactivity: none
- Install: `npx shadcn@latest add @haze/card`
- File: `src/components/haze/ui/card.astro`
- npm dependencies: none
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/ui/card

## Use when
- Grouping a settings section, a form or a summary on a darker page background
- A header with a title and one action, such as a badge or a small button, next to it
- A footer row of buttons that belongs to the card's content

## Avoid when
- Wrapping a whole page section; use a plain section with a heading
- Cards nested inside cards; use a separator inside one card

## Alternatives
- [item](https://hazeui.com/ui/item.md)
- [stat](https://hazeui.com/ui/stat.md)
- [separator](https://hazeui.com/ui/separator.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| title | `string` |  | no | Card heading. The header is drawn when a title, a description or the action slot exists. |
| description | `string` |  | no | One muted line under the title. |
| headingLevel | `2 \| 3 \| 4` | 3 | no | Tag used for the title, so the card fits the heading outline of the page. |
| padding | `"sm" \| "md"` | "md" | no | Inner spacing: 16 px for sm, 24 px for md. |
| interactive | `boolean` | false | no | Lifts the card 2 px on hover and strengthens its border. Use it only when the whole card leads somewhere, for example with a stretched link inside. |
| class | `string` |  | no | Extra classes on the outer box. |
| default slot | `slot` |  | no | Card body. |
| action slot | `slot` |  | no | Top-right of the header, for a badge or a button. |
| footer slot | `slot` |  | no | Footer band with a top border and a darker fill, for buttons or a note. |

## Accessibility
- The title is a real heading whose level you choose with headingLevel, so a card list does not skip levels.
- The card itself has no role and is not focusable; put links and buttons inside it and let each one carry its own focus ring.
- Do not wrap the card in an anchor. For a card that is one link, set interactive, add class="relative" and give one link inside it an after:absolute after:inset-0 overlay, so there is one focusable element with a clear name. The card shows its stronger border while that link has focus.
- The hover lift is a translate and a shadow, switched off under prefers-reduced-motion. For a list row that is one link, the item component with href is the alternative.

## Agent prompts

### Install and use

Install the Haze UI component "Card" with `npx shadcn@latest add @haze/card`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import Card from "@/components/haze/ui/card.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/ui/card.md

### Customize with real content

Adapt the Haze card ui for our product. Replace the demo values of these props with our real content: title, description, headingLevel, padding, interactive, class, default slot, action slot, footer slot. Keep the layout, the heading level rules and these accessibility details: The title is a real heading whose level you choose with headingLevel, so a card list does not skip levels. The card itself has no role and is not focusable; put links and buttons inside it and let each one carry its own focus ring. Do not wrap the card in an anchor. For a card that is one link, set interactive, add class="relative" and give one link inside it an after:absolute after:inset-0 overlay, so there is one focusable element with a clear name. The card shows its stronger border while that link has focus. The hover lift is a translate and a shadow, switched off under prefers-reduced-motion. For a list row that is one link, the item component with href is the alternative. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using card, check it fits: use it when grouping a settings section, a form or a summary on a darker page background; a header with a title and one action, such as a badge or a small button, next to it; a footer row of buttons that belongs to the card's content. Avoid it when wrapping a whole page section; use a plain section with a heading; cards nested inside cards; use a separator inside one card. Alternatives: @haze/item, @haze/stat, @haze/separator.

## Example requests that should lead here
- Add a card with a title, a description and a Save button in the footer
- Show a card with a status tag in the top-right corner

## Source

```astro
---
import { cn } from "../../../lib/haze/utils";

interface Props {
  title?: string;
  description?: string;
  /** Heading level of the title. Pick the level that fits the page outline. */
  headingLevel?: 2 | 3 | 4;
  padding?: "sm" | "md";
  /** Lifts the card on hover. Use it when the whole card leads somewhere. */
  interactive?: boolean;
  class?: string;
}

const { title, description, headingLevel = 3, padding = "md", interactive = false, class: className } = Astro.props;
const Heading = ({ 2: "h2", 3: "h3", 4: "h4" } as const)[headingLevel];
const hasAction = Astro.slots.has("action");
const hasFooter = Astro.slots.has("footer");
const hasHeader = Boolean(title || description || hasAction);
const pad = { sm: "p-4", md: "p-4.5" };
const gap = { sm: "gap-3", md: "gap-4" };
const footerPad = { sm: "px-4 py-3", md: "px-4.5 py-3.5" };
---

<div
  class={cn(
    "flex flex-col rounded-xl border border-border bg-card text-card-foreground",
    interactive &&
      "transition-[border-color,translate,box-shadow] duration-200 ease-snappy motion-reduce:transition-none hover:-translate-y-0.5 motion-reduce:hover:translate-y-0 hover:border-border-strong hover:shadow-lift has-focus-visible:border-border-strong",
    className,
  )}
>
  <div class={cn("flex flex-1 flex-col", pad[padding], gap[padding])}>
    {
      hasHeader && (
        <div class="flex items-start justify-between gap-4">
          <div class="grid min-w-0 gap-1">
            {title && <Heading class="text-[1.0625rem] leading-[1.4] font-medium tracking-[-0.01em]">{title}</Heading>}
            {description && <p class="text-[0.8125rem] leading-[1.4] text-muted-foreground">{description}</p>}
          </div>
          {hasAction && (
            <div class="shrink-0">
              <slot name="action" />
            </div>
          )}
        </div>
      )
    }
    <div class="text-[0.8125rem] leading-[1.4]"><slot /></div>
  </div>
  {
    hasFooter && (
      <div class={cn("rounded-b-[inherit] border-t border-border bg-muted/50 text-[0.8125rem]", footerPad[padding])}>
        <slot name="footer" />
      </div>
    )
  }
</div>
```
