---
title: Card for Astro
description: "Astro card sections with shared spacing, framed layouts, and optional actions."
seo:
    title: Card for Astro | Shadcn & Tailwind CSS
related:
    - /components/frame
    - /components/item
    - /components/empty
sidebar:
    label: "Card"
---

```astro
---
import { Button } from "@/components/ui/button"
import {
  Card,
  CardAction,
  CardContent,
  CardDescription,
  CardFooter,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
---

<Card class="@container/card w-full max-w-md">
  <CardHeader class="@max-sm/card:flex @max-sm/card:flex-col">
    <CardTitle>Client site handoff</CardTitle>
    <CardDescription>
      Review the content and access details before the site handoff.
    </CardDescription>
    <CardAction>
      <Button size="sm" variant="outline">
        View checklist
      </Button>
    </CardAction>
  </CardHeader>
  <CardContent>
    <p>The page copy is approved. Two image descriptions still need review.</p>
  </CardContent>
  <CardFooter>
    <Button class="w-full">Review files</Button>
  </CardFooter>
</Card>
```

## Installation

### Command

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

### Manual

Complete the [Installation guide](/docs/installation) first. Then copy the component files below.

No extra packages are required.

#### src/components/ui/card/card-action.astro

```astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div">

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

<div data-slot="card-action" class={cn("col-start-2 row-span-2 row-start-1 inline-flex self-start justify-self-end", className)} {...props}>
  <slot />
</div>
```

#### src/components/ui/card/card-content.astro

```astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div">

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

<div
  data-slot="card-content"
  class={cn("flex flex-1 flex-col gap-3 p-(--card-spacing) in-[[data-slot=card]:has(>[data-slot=card-footer]:not(.border-t))]:pb-0 in-[[data-slot=card]:has(>[data-slot=card-header]:not(.border-b))]:pt-0", className)}
  {...props}
>
  <slot />
</div>
```

#### src/components/ui/card/card-description.astro

```astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div">

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

<div
  data-slot="card-description"
  class={cn("text-muted-foreground text-sm", className)}
  {...props}
>
  <slot />
</div>
```

#### src/components/ui/card/card-footer.astro

```astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div">

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

<div data-slot="card-footer" class={cn("flex items-center p-(--card-spacing) in-[[data-slot=card]:has(>[data-slot=card-content])]:pt-[calc(var(--card-spacing)*2/3)]", className)} {...props}>
  <slot />
</div>
```

#### src/components/ui/card/card-frame-action.astro

```astro
---
/**
 * Header action for a framed card. Place it after the title and description.
 */
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div">

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

<div
  data-slot="card-frame-action"
  class={cn(
    "col-start-2 inline-flex self-center justify-self-end nth-3:row-span-2 nth-3:row-start-1",
    className,
  )}
  {...props}
>
  <slot />
</div>
```

#### src/components/ui/card/card-frame-description.astro

```astro
---
/**
 * Supporting text under a framed card title.
 */
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div">

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

<div
  data-slot="card-frame-description"
  class={cn("text-muted-foreground self-center text-sm", className)}
  {...props}
>
  <slot />
</div>
```

#### src/components/ui/card/card-frame-footer.astro

```astro
---
/**
 * Footer band for a framed card. Body actions stay in CardFooter.
 */
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div">

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

<div
  data-slot="card-frame-footer"
  class={cn("px-(--card-spacing) py-4", className)}
  {...props}
>
  <slot />
</div>
```

#### src/components/ui/card/card-frame-header.astro

```astro
---
/**
 * Header grid for a framed card.
 * An action in the third slot sits on the right.
 */
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div">

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

<div
  data-slot="card-frame-header"
  class={cn(
    "relative grid auto-rows-min grid-rows-[auto_auto] items-start gap-x-4 px-(--card-spacing) py-4 has-data-[slot=card-frame-action]:grid-cols-[1fr_auto]",
    className,
  )}
  {...props}
>
  <slot />
</div>
```

#### src/components/ui/card/card-frame-title.astro

```astro
---
/**
 * Title for a framed card header. Size matches the Coss frame title.
 */
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div">

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

<div
  data-slot="card-frame-title"
  class={cn("self-center text-sm font-semibold", className)}
  {...props}
>
  <slot />
</div>
```

#### src/components/ui/card/card-frame.astro

```astro
---
/**
 * Framed card shell from Coss UI.
 * The muted fill sits on a pseudo-element so the inner card can clip into the border.
 */
import type { HTMLTag, Polymorphic } from "astro/types"

import { cn } from "cn"

import type { CardFrameProps } from "./types.ts"

type Props<Tag extends HTMLTag = "div"> = Polymorphic<{ as: Tag }> &
  CardFrameProps

const { as: Tag = "div", class: className, ...props } = Astro.props
---

<Tag
  data-slot="card-frame"
  class={cn(
    "text-card-foreground bg-card before:bg-muted/72 relative flex flex-col rounded-2xl border shadow-xs/5 [--card-spacing:--spacing(6)] [--clip-bottom:-1rem] [--clip-top:-1rem] not-dark:bg-clip-padding before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-2xl)-1px)] before:shadow-[0_1px_--theme(--color-black/4%)] has-data-[slot=table-container]:overflow-hidden *:data-[slot=card]:-m-px *:data-[slot=card]:bg-clip-padding *:data-[slot=card]:shadow-none *:data-[slot=card]:[clip-path:inset(var(--clip-top)_1px_var(--clip-bottom)_1px_round_calc(var(--radius-2xl)-1px))] *:not-first:data-[slot=card]:rounded-t-xl *:not-last:data-[slot=card]:rounded-b-xl *:data-[slot=card]:before:hidden *:not-first:data-[slot=card]:before:rounded-t-[calc(var(--radius-xl)-1px)] *:not-last:data-[slot=card]:before:rounded-b-[calc(var(--radius-xl)-1px)] *:data-[slot=card]:first:[--clip-top:1px] *:data-[slot=card]:last:[--clip-bottom:1px] *:data-[slot=table-container]:-m-px *:data-[slot=table-container]:w-[calc(100%+2px)] dark:before:shadow-[0_-1px_--theme(--color-white/6%)]",
    className,
  )}
  {...props}
>
  <slot />
</Tag>
```

#### src/components/ui/card/card-header.astro

```astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div">

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

<div
  data-slot="card-header"
  class={cn("grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 p-(--card-spacing) in-[[data-slot=card]:has(>[data-slot=card-content])]:pb-[calc(var(--card-spacing)*2/3)] has-data-[slot=card-action]:grid-cols-[1fr_auto] group/card-header", className)}
  {...props}
>
  <slot />
</div>
```

#### src/components/ui/card/card-title.astro

```astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div">

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

<div data-slot="card-title" class={cn("font-heading text-lg leading-none font-semibold group-data-[size=sm]/card:text-base", className)} {...props}>
  <slot />
</div>
```

#### src/components/ui/card/card.astro

```astro
---
import type { HTMLTag, Polymorphic } from "astro/types"

import { cn } from "cn"

import type { CardProps } from "./types.ts"

type Props<Tag extends HTMLTag = "div"> = Polymorphic<{ as: Tag }> & CardProps

const {
  as: Tag = "div",
  class: className,
  size = "default",
  ...props
} = Astro.props
---

<Tag
  data-slot="card"
  data-size={size}
  class={cn("font-sans bg-card text-card-foreground relative flex flex-col overflow-hidden rounded-2xl border shadow-xs/5 [--card-spacing:--spacing(6)] not-dark:bg-clip-padding before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-2xl)-1px)] before:shadow-[0_1px_--theme(--color-black/4%)] has-[>img:first-child]:pt-0 data-[size=sm]:[--card-spacing:--spacing(4)] dark:before:shadow-[0_-1px_--theme(--color-white/6%)] *:[img:first-child]:rounded-t-2xl *:[img:last-child]:rounded-b-2xl group/card", className)}
  {...props}
>
  <slot />
</Tag>
```

#### src/components/ui/card/index.ts

```ts
export { default as Card } from './card.astro'
export type { CardFrameProps, CardProps } from './types.ts'
export { default as CardAction } from './card-action.astro'
export { default as CardContent } from './card-content.astro'
export { default as CardDescription } from './card-description.astro'
export { default as CardFooter } from './card-footer.astro'
export { default as CardFrame } from './card-frame.astro'
export { default as CardFrameAction } from './card-frame-action.astro'
export { default as CardFrameDescription } from './card-frame-description.astro'
export { default as CardFrameFooter } from './card-frame-footer.astro'
export { default as CardFrameHeader } from './card-frame-header.astro'
export { default as CardFrameTitle } from './card-frame-title.astro'
export { default as CardHeader } from './card-header.astro'
export { default as CardTitle } from './card-title.astro'
```

#### src/components/ui/card/types.ts

```ts
import type { HTMLTag } from 'astro/types'

/** Root card container spacing and polymorphic element. */
export interface CardProps {
    /**
     * The HTML tag for the card root.
     *
     * @default 'div'
     */
    as?: HTMLTag
    /**
     * Section inset scale through `--card-spacing`.
     *
     * @default 'default'
     */
    size?: 'default' | 'sm'
}

/** Framed card shell with optional polymorphic root. */
export interface CardFrameProps {
    /**
     * The HTML tag for the frame root.
     *
     * @default 'div'
     */
    as?: HTMLTag
}
```

Component classes use the preset configured during project setup. Select the same preset in the docs before copying Manual source. To change installed component classes, edit or reinstall their source. See [Theming](/docs/theming) for details.


## Usage

```ts
import {
    Card,
    CardAction,
    CardContent,
    CardDescription,
    CardFooter,
    CardFrame,
    CardHeader,
    CardTitle,
} from "@/components/ui/card"
```

```astro
<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

:::note
`Card` and `CardFrame` accept an `as` prop to change their root HTML element.
Both use `div` by default. Use `as="article"` for an article or `as="a"` with
`href` to make the whole card a link without an extra wrapper.

These roots supply layout and styling, so they can use different tags. Their
inner parts keep their existing tags. See the [polymorphic props rule](/docs#polymorphic-props)
for components that require a specific element.

Pass the selected element's attributes directly to the component. `as` takes a
tag name, with no callback or child cloning. A card link must not contain other
links, buttons, or other interactive controls. Keep a container root when the
card has several actions.
:::

```astro
<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:

```astro
<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`:

```text
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.

```astro
---
import {
  Card,
  CardContent,
  CardFrame,
  CardFrameDescription,
  CardFrameHeader,
  CardFrameTitle,
} from "@/components/ui/card"
---

<CardFrame class="w-full max-w-md">
  <CardFrameHeader>
    <CardFrameTitle>Create project</CardFrameTitle>
    <CardFrameDescription>
      Check the page content and image notes before handoff.
    </CardFrameDescription>
  </CardFrameHeader>
  <Card>
    <CardContent>
      <p>Card content goes here.</p>
    </CardContent>
  </Card>
</CardFrame>
```

### Card frame with footer

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

```astro
---
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Textarea } from "@/components/ui/textarea"
import {
  Field,
  FieldLabel,
  FieldContent,
  FieldGroup,
} from "@/components/ui/field"
import {
  Card,
  CardContent,
  CardFooter,
  CardFrame,
  CardFrameDescription,
  CardFrameHeader,
  CardFrameTitle,
} from "@/components/ui/card"
---

<CardFrame class="w-full max-w-sm">
  <CardFrameHeader>
    <CardFrameTitle>Create project</CardFrameTitle>
    <CardFrameDescription>
      Check the page content and image notes before handoff.
    </CardFrameDescription>
  </CardFrameHeader>
  <Card>
    <CardContent>
      <FieldGroup>
        <Field>
          <FieldLabel>Project name</FieldLabel>
          <FieldContent>
            <Input type="text" />
          </FieldContent>
        </Field>
        <Field>
          <FieldLabel>Project description</FieldLabel>
          <FieldContent>
            <Textarea />
          </FieldContent>
        </Field>
      </FieldGroup>
    </CardContent>
    <CardFooter class="justify-end gap-2">
      <Button size="sm" variant="outline">
        Cancel
      </Button>
      <Button size="sm">Continue</Button>
    </CardFooter>
  </Card>
</CardFrame>
```

### Card frame with framed footer

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

```astro
---
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Textarea } from "@/components/ui/textarea"
import {
  Field,
  FieldLabel,
  FieldContent,
  FieldGroup,
} from "@/components/ui/field"
import {
  Card,
  CardContent,
  CardFooter,
  CardFrame,
  CardFrameDescription,
  CardFrameHeader,
  CardFrameTitle,
  CardFrameFooter,
} from "@/components/ui/card"
---

<CardFrame class="w-full max-w-sm">
  <CardFrameHeader>
    <CardFrameTitle>Create project</CardFrameTitle>
    <CardFrameDescription>
      Check the page content and image notes before handoff.
    </CardFrameDescription>
  </CardFrameHeader>
  <Card>
    <CardContent>
      <FieldGroup>
        <Field>
          <FieldLabel>Project name</FieldLabel>
          <FieldContent>
            <Input type="text" />
          </FieldContent>
        </Field>
        <Field>
          <FieldLabel>Project description</FieldLabel>
          <FieldContent>
            <Textarea rows={4} />
          </FieldContent>
        </Field>
      </FieldGroup>
    </CardContent>
  </Card>
  <CardFrameFooter class="justify-end gap-2 flex items-center">
    <Button size="sm" variant="outline">
      Cancel
    </Button>
    <Button size="sm">Continue</Button>
  </CardFrameFooter>
</CardFrame>
```

### Image Card

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

```astro
---
import { Image } from "astro:assets"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import image from "@/assets/placeholder.webp"
---

<Card class="max-w-md">
  <Image
    src={image}
    alt="Card image"
    class="aspect-video w-full object-cover"
  />
  <CardHeader>
    <CardTitle>Image Card</CardTitle>
    <CardDescription>Card with media in the top slot.</CardDescription>
  </CardHeader>
  <CardContent>
    <p>The first child image automatically gets top rounding behavior.</p>
  </CardContent>
</Card>
```

## Sizes and states

```astro
---
import {
  Card,
  CardHeader,
  CardTitle,
  CardDescription,
  CardContent,
  CardFooter,
} from "@/components/ui/card"
import { Button } from "@/components/ui/button"
---

<div class="grid w-full gap-6 md:grid-cols-2 items-start">
  {(["default", "sm"] as const).map((size) => (
    <Card size={size}>
      <CardHeader>
        <CardTitle>Review {size === "sm" ? "summary" : "details"}</CardTitle>
        <CardDescription>A card with {size} spacing.</CardDescription>
      </CardHeader>
      <CardContent>
        <p>Keep the project files, content notes, and next action together.</p>
      </CardContent>
      <CardFooter>
        <Button variant="outline">Open review</Button>
      </CardFooter>
    </Card>
  ))}
</div>
```

## API Reference

### CardProps

<AutoTypeTable path="../../packages/ui/src/components/ui/card/types.ts" name="CardProps" />

### CardFrameProps

<AutoTypeTable path="../../packages/ui/src/components/ui/card/types.ts" name="CardFrameProps" />

Read the [installed source](/r/card.json) 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.
