Skip to main content
astrocraft-ui/ components · 101

Card

Free · MIT

Headless, accessible, and styled entirely through the attribute surface below — bring your own CSS system, or start from the reference theme.

Install

Without a flag you get no styling at all — plain HTML carrying the attribute surface below. --theme copies the same theme in two dialects;--bridge lumos re-points either one onto Lumos for Astro's tokens (it needs a theme to re-point, and Lumos itself, already in your project).

Unstyled — behavior only, you write the CSS

Install command
npx astrocraft-ui add display/card

Plain-CSS theme — no build step

Install command
npx astrocraft-ui add display/card --theme css

Tailwind theme — needs Tailwind v4

Install command
npx astrocraft-ui add display/card --theme tailwind

Plain-CSS theme, re-pointed onto Lumos tokens

Install command
npx astrocraft-ui add display/card --theme css --bridge lumos

Tailwind theme, re-pointed onto Lumos tokens

Install command
npx astrocraft-ui add display/card --theme tailwind --bridge lumos

Live demo

Card

Card title

A compound card: header, content, footer.

Body content sits in CardContent. Tokens flip with the theme.

default

variant="default"

Same markup, different elevation.

elevated

variant="elevated"

Same markup, different elevation.

outline

variant="outline"

Same markup, different elevation.

interactive

variant="interactive"

Same markup, different elevation.

Size sm

size="sm"

Retunes header / content / footer padding at once.

Size md

size="md"

Retunes header / content / footer padding at once.

Size lg

size="lg"

Retunes header / content / footer padding at once.

Media card

overflow-hidden on the root rounds the image corners.

Top, bottom, or full-bleed — all just work.

Shipping a token-driven UI

How the palette → semantic → utility bridge keeps dark mode free.

Post author

Jane Doe

Jul 1, 2026 · 4 min read

Horizontal layout

Image beside content on ≥sm.

The image stretches to the card's height.

Top-bordered accent

A status stripe is one class (border-t-4 border-t-primary).

No primitive change needed for a one-off.

Attribute surface

With no class-merging machinery, these attributes are the whole extension point. State is a data-attribute or a native attribute; visibility is the hiddenattribute. Generated from source by pnpm slots.

ComponentSlotsVariantsRuntime stateNative state
`Card.astro``card``data-variant`: `default` · `elevated` · `outline` · `interactive`
`data-size`: `sm` · `md` · `lg`
——
`CardAction.astro``card-action`———
`CardContent.astro``card-content`———
`CardDescription.astro``card-description`———
`CardFooter.astro``card-footer`———
`CardHeader.astro``card-header`———
`CardImage.astro``card-image`———
`CardTitle.astro``card-title`———

Source

What the command copies — 9 files, alias-free so the copy lands standing alone. This is the whole component; there is nothing else.

src/components/ui/display/card/Card.astro
---
// src/components/ui/display/card/Card.astro — headless primitive (see ../../README.md).
// Compound root; pair with CardImage / CardHeader (Title/Description/Action) / CardContent /
// CardFooter. `variant` sets elevation, `size` is the one knob a theme reads to repad every part at
// once (the reference theme maps `data-size` to a `--card-p` custom property the parts inherit).
import type { HTMLAttributes } from "astro/types";

type Props = HTMLAttributes<"div"> & {
  variant?: "default" | "elevated" | "outline" | "interactive";
  size?: "sm" | "md" | "lg";
};

const { variant = "default", size = "md", class: className, ...rest } = Astro.props;
---

<div class={className} data-slot="card" data-variant={variant} data-size={size} {...rest}>
  <slot />
</div>
src/components/ui/display/card/CardAction.astro
---
// src/components/ui/display/card/CardAction.astro — Card compound part (see ../../README.md).
// Drop inside CardHeader for a top-right action (button, dropdown, close). Its grid placement pins it
// to the reserved second column; CardHeader opens that column via `has-[card-action]`.
import type { HTMLAttributes } from "astro/types";

type Props = HTMLAttributes<"div">;

const { class: className, ...rest } = Astro.props;
---

<div class={className} data-slot="card-action" {...rest}><slot /></div>
src/components/ui/display/card/CardContent.astro
---
// src/components/ui/display/card/CardContent.astro — Card compound part (see ../../README.md).
import type { HTMLAttributes } from "astro/types";

type Props = HTMLAttributes<"div">;

const { class: className, ...rest } = Astro.props;
---

<div class={className} data-slot="card-content" {...rest}><slot /></div>
src/components/ui/display/card/CardDescription.astro
---
// src/components/ui/display/card/CardDescription.astro — Card compound part (see ../../README.md).
import type { HTMLAttributes } from "astro/types";

type Props = HTMLAttributes<"p">;

const { class: className, ...rest } = Astro.props;
---

<p class={className} data-slot="card-description" {...rest}><slot /></p>
src/components/ui/display/card/CardFooter.astro
---
// src/components/ui/display/card/CardFooter.astro — Card compound part (see ../../README.md).
import type { HTMLAttributes } from "astro/types";

type Props = HTMLAttributes<"div">;

const { class: className, ...rest } = Astro.props;
---

<div class={className} data-slot="card-footer" {...rest}><slot /></div>
src/components/ui/display/card/CardHeader.astro
---
// src/components/ui/display/card/CardHeader.astro — Card compound part (see ../../README.md).
// Grid so a CardAction can pin to the top-right: `has-[card-action]` opens a second column and the
// action places itself there (col-start-2, row-span-2), leaving title/description to flow down col 1.
// Rows are implicit (auto-rows-min) so a title-only header has no phantom trailing gutter; the action's
// row-span mints the second row only when present. With no action it's a plain single-column stack.
import type { HTMLAttributes } from "astro/types";

type Props = HTMLAttributes<"div">;

const { class: className, ...rest } = Astro.props;
---

<div class={className} data-slot="card-header" {...rest}><slot /></div>
src/components/ui/display/card/CardImage.astro
---
// src/components/ui/display/card/CardImage.astro — Card compound part (see ../../README.md).
// A plain <img>. Takes a raw/remote src string — for an optimized asset, skip this part and drop an
// astro:assets <Image data-slot="card-image" /> in its place; the theme keys on the attribute, so an
// <Image> styles identically.
import type { HTMLAttributes } from "astro/types";

type Props = HTMLAttributes<"img">;

const { alt = "", class: className, ...rest } = Astro.props;
---

<img alt={alt} class={className} data-slot="card-image" {...rest} />
src/components/ui/display/card/CardTitle.astro
---
// src/components/ui/display/card/CardTitle.astro — Card compound part (see ../../README.md).
// <h3>: a card sits below a page's h2 sections. Change the level with a wrapping heading if needed.
import type { HTMLAttributes } from "astro/types";

type Props = HTMLAttributes<"h3">;

const { class: className, ...rest } = Astro.props;
---

<h3 class={className} data-slot="card-title" {...rest}><slot /></h3>
src/components/ui/display/card/index.ts
import Card from "./Card.astro";
import CardAction from "./CardAction.astro";
import CardContent from "./CardContent.astro";
import CardDescription from "./CardDescription.astro";
import CardFooter from "./CardFooter.astro";
import CardHeader from "./CardHeader.astro";
import CardImage from "./CardImage.astro";
import CardTitle from "./CardTitle.astro";

export {
  Card,
  CardAction,
  CardContent,
  CardDescription,
  CardFooter,
  CardHeader,
  CardImage,
  CardTitle,
};
export default Card;

What you get

The component source, copied into your project by npx astrocraft-ui add display/card — no package dependency, no CSS to fight. Whatever the paid blocks compose, this is it.