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.
pnpm dlx shadcn@latest add @haze/card---
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>When to use
- 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
When not to use
- Wrapping a whole page section; use a plain section with a heading
- Cards nested inside cards; use a separator inside one card
Installation
Add the Haze registry to components.json once, then install Card with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/cardnpx shadcn@latest add @haze/cardyarn dlx shadcn@latest add @haze/cardbunx --bun shadcn@latest add @haze/cardFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| title | string | – | Card heading. The header is drawn when a title, a description or the action slot exists. |
| description | string | – | One muted line under the title. |
| headingLevel | 2 | 3 | 4 | 3 | Tag used for the title, so the card fits the heading outline of the page. |
| padding | "sm" | "md" | "md" | Inner spacing: 16 px for sm, 24 px for md. |
| interactive | boolean | false | 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 | – | Extra classes on the outer box. |
| default slot | slot | – | Card body. |
| action slot | slot | – | Top-right of the header, for a badge or a button. |
| footer slot | slot | – | 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.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
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": "http://localhost:4329/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: http://localhost:4329/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.
Dependencies
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.