Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

Card for Astro

Astro card sections with shared spacing, framed layouts, and optional actions.

Client site handoff
Review the content and access details before the site handoff.

The page copy is approved. Two image descriptions still need review.

Installation

bunx --bun shadcn@latest add @gnostic/card

Usage

import {
    Card,
    CardAction,
    CardContent,
    CardDescription,
    CardFooter,
    CardFrame,
    CardHeader,
    CardTitle,
} from "@/components/ui/card"
<Card>
  <CardHeader>
    <CardTitle>Card Title</CardTitle>
    <CardDescription>Card Description</CardDescription>
    <CardAction>Card Action</CardAction>
  </CardHeader>
  <CardContent>
    <p>Card Content</p>
  </CardContent>
  <CardFooter>
    <p>Card Footer</p>
  </CardFooter>
</Card>

Polymorphic props

<Card as="article">
  <CardHeader>
    <CardTitle>Project summary</CardTitle>
  </CardHeader>
  <CardContent>
    <p>Review the project scope and schedule.</p>
  </CardContent>
</Card>

<CardFrame as="a" href="/projects" class="focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-ring">
  <Card>
    <CardContent>View projects</CardContent>
  </Card>
</CardFrame>

Spacing

--card-spacing controls the section insets in a Card. Use size="sm" for less spacing, or set the variable on the card:

<Card style="--card-spacing: 1rem;">
  <CardContent>Card content</CardContent>
</Card>

CardFrame uses the same variable for the horizontal padding in its header and footer. Their vertical padding stays at 1rem. The frame and its inner card each have their own spacing value.

Composition

Arrange the parts as shown for a Card:

Card
├── CardHeader
│   ├── CardTitle
│   ├── CardDescription
│   └── CardAction
├── CardContent
└── CardFooter

CardFrame
├── CardFrameHeader
│   ├── CardFrameTitle
│   ├── CardFrameDescription
│   └── CardFrameAction
├── Card
│   ├── CardContent
│   └── CardFooter (inside frame)
└── CardFrameFooter (outside frame)

Examples

Card frame

CardFrame keeps its Gnostic frame styling with every preset. Its colors follow the selected theme. The inner Card uses the selected preset’s Card styles.

CardFrame is the framed card shell. Put the title and the description in CardFrameHeader. The inner Card is the body.

Create project
Check the page content and image notes before handoff.

Card content goes here.

Put the title and the description in CardFrameHeader. Put the buttons in CardFooter.

Create project
Check the page content and image notes before handoff.

Put the CardFrameFooter outside the Card to create a framed footer.

Create project
Check the page content and image notes before handoff.

Image Card

Add an image before the card header to create a card with an image.

Card image
Image Card
Card with media in the top slot.

The first child image automatically gets top rounding behavior.

Sizes and states

Review details
A card with default spacing.

Keep the project files, content notes, and next action together.

Review summary
A card with sm spacing.

Keep the project files, content notes, and next action together.

API Reference

CardProps

PropType
as?HTMLTag

The HTML tag for the card root.

TypeHTMLTag
Default'div'
size?'default' | 'sm'

Section inset scale through `--card-spacing`.

Type'default' | 'sm'
Default'default'

CardFrameProps

PropType
as?HTMLTag

The HTML tag for the frame root.

TypeHTMLTag
Default'div'

Read the installed source for the complete prop types.

When to use Card

Use Card for one related unit of content, such as a project summary or account setting. Compose a header, content, and footer through Astro slots. CardContent is the body part. A CardAction belongs in the header when it acts on the whole card.

Keyboard and behavior

Card adds no custom click or keyboard behavior. With as="a" and href, the root uses native link behavior. Give card links a visible keyboard focus style, as in the example above. For a card with several actions, keep the default container and use links and buttons inside it. A title does not make the entire surface interactive. Check the title element in your page heading order, and give each action a label that identifies its purpose.

Theme and layout

The default surface uses shared card colors, a border, and a small shadow. Section parts own their padding. Use size="sm" or --card-spacing for a denser composition. A CardFrame adds a surrounding surface; its spacing is independent of the inner card. Long titles and footers with several buttons need a narrow-screen check.