Card
A Card shows users related content on one surface, such as the lines and the actions of an invoice.
When to Use
- for one record and its actions, such as an invoice with its lines and “Mark as paid”
- for one figure on a dashboard, like “Outstanding” over its total
- to place a Chart, a Table, or a list under one title
- to frame a short form on a page of its own, such as “Sign in”
When Not to Use
- for one row of a list, with media, text, and actions (use the Item component)
- for a status message (use an Alert)
- for content that floats over the page (use a Popover or a Dialog)
- for a section that opens and closes (use a Collapsible)
Anatomy
| Element | Usage |
|---|---|
| Title | Optional |
| Action | Optional |
| Description | Optional |
| Container | Required |
| Content | Optional |
| Footer | Optional |
CardHeader stacks the title and the description, and it places CardAction in a second column at its end.
Sizes
| Size | Placement |
|---|---|
default | Everywhere else |
sm | A Card in a narrow column or a dense grid |
Behavior
A Card is as wide as its container and has no width of its own. Set the width on the column or the grid that contains it.
A Card clips content that runs past its edge.
Header
To show a line under the header, add the class border-b to it.
Footer
The content of the footer is placed in a row from the start edge. To move its Buttons to the end, add justify-end, as the preview does.
Image
When an img is the first child of Card, it reaches the top and side edges.
Card.CardContent, it is 16px inside the top and side edges and has square corners, so users see a picture that is 32px narrower in the same Card.Content
| String | Rule | Example | Counterexample |
|---|---|---|---|
| Title | Name what the Card contains, with no period | “Recent invoices” | “Here are your recent invoices.” |
| Description | Add in one line what the title doesn’t say | “Last five issued” | “A list of invoices” |
Accessibility
A Card isn’t focusable and has no keys of its own. Users reach the controls inside it with Tab, in the order in which they are written.
If the title of a Card is the heading of a section of a page, it needs to be exposed as a heading so that screen
readers can announce it as one. CardTitle renders a div, so pass it role="heading" and an aria-level.
WCAG 2.2 SC 1.3.1 Info and Relationships requires that structure shown visually is also available to assistive technology.
Installation
npx shadcn@latest add @summit/cardUsage
import { Card, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
<Card>
<CardHeader>
<CardTitle>Outstanding</CardTitle>
<CardDescription>$12,480.00 across 6 invoices</CardDescription>
</CardHeader>
</Card>;Add an Action
Place CardAction inside CardHeader, after the title and the description.
import { Button } from '@/components/ui/button';
import { Card, CardAction, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
<Card>
<CardHeader>
<CardTitle>INV-2026-014</CardTitle>
<CardDescription>Atelier Brume, due October 27</CardDescription>
<CardAction>
<Button variant="outline" size="sm">
Edit
</Button>
</CardAction>
</CardHeader>
</Card>;Add a Footer
Place CardFooter last.
<Card>
<CardContent>$7,703.33 for design and development.</CardContent>
<CardFooter className="justify-end gap-2">
<Button variant="outline">Send reminder</Button>
<Button>Mark as paid</Button>
</CardFooter>
</Card>Lead With an Image
Place the img as the first child of Card.
<Card>
<img src="/projects/brume.jpg" alt="" className="aspect-video object-cover" />
<CardHeader>
<CardTitle>Website and brand</CardTitle>
<CardDescription>Atelier Brume, due October 24</CardDescription>
</CardHeader>
</Card>Expose the Title as a Heading
To expose the title as a heading, set role and aria-level on CardTitle, which passes them to its div.
<CardTitle role="heading" aria-level={2}>
Recent invoices
</CardTitle>API Reference
The parts accept the props of a div.
Card
| Prop | Type | Default | Description |
|---|---|---|---|
size | 'default' | 'sm' | 'default' | The padding, the gap, and the size of the title |