Card for Astro
Astro card sections with shared spacing, framed layouts, and optional actions.
Installation
bunx --bun shadcn@latest add @gnostic/cardnpx shadcn@latest add @gnostic/cardpnpm dlx shadcn@latest add @gnostic/cardCopy the files
src/components/ui/card/card-action.astrosrc/components/ui/card/card-content.astrosrc/components/ui/card/card-description.astrosrc/components/ui/card/card-footer.astrosrc/components/ui/card/card-frame-action.astrosrc/components/ui/card/card-frame-description.astrosrc/components/ui/card/card-frame-footer.astrosrc/components/ui/card/card-frame-header.astrosrc/components/ui/card/card-frame-title.astrosrc/components/ui/card/card-frame.astrosrc/components/ui/card/card-header.astrosrc/components/ui/card/card-title.astrosrc/components/ui/card/card.astrosrc/components/ui/card/index.tssrc/components/ui/card/types.ts
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.
Card frame with footer
Put the title and the description in CardFrameHeader. Put the buttons in CardFooter.
Card frame with framed footer
Put the CardFrameFooter outside the Card to create a framed footer.
Image Card
Add an image before the card header to create a card with an image.
Sizes and states
API Reference
CardProps
as?HTMLTag
The HTML tag for the card root.
HTMLTag'div'size?'default' | 'sm'
Section inset scale through `--card-spacing`.
'default' | 'sm''default'CardFrameProps
as?HTMLTag
The HTML tag for the frame root.
HTMLTag'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.
