Card
A flat container that groups related content on one surface.
Weekend in Kyoto
Installation
npx shadcn@latest add @flyingsalmon/cardUsage
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@/components/ui/card'
export function CardUsage() {
return (
<Card>
<CardHeader>
<CardTitle>Weekend in Kyoto</CardTitle>
<CardDescription>Three days, ten stops</CardDescription>
</CardHeader>
<CardContent>Temples in the morning, tea in the afternoon.</CardContent>
</Card>
)
}Examples
Interactive
Pass interactive and put the link directly inside CardTitle. The link stretches over the whole card, so a click anywhere follows it. Buttons, fields, and labels inside the card stay clickable on their own, like the Save button here.
An action row
CardAction is a direct child of the card, not of the header. It pins to the bottom right, so the action never competes with the title for the top edge.
Invite Mai Tran
States
A static card has one state and an interactive card responds to hover, focus, and press. A card whose content is missing shows skeletons in the same layout. Neither kind has a disabled state.
Spacing
The one padding step is --card-spacing. Set it on a card to loosen or tighten that card, rather than padding its children.
Lisbon
Lisbon
Guidelines
When to use
- To group a trip, a place, or a traveller with its description and actions on one surface.
- For a list of items that each lead somewhere, as an interactive card.
When not to use
Do and don’t
- DoPut the actions on the card’s own item, such as accepting an invite, in its action row. Put a form’s submit row below the card that holds the fields.An action inside the edge acts on that one item. A submit row finishes the whole form, so it sits outside the card, and the result it produces appears below it, where the reader is already looking.
- DoMark the one card the reader is working on with an orange border, and leave every other card plain.Emphasis lives in the border on a flat surface. One marked card points the eye; two compete and neither reads as current.
- DoGive sibling cards in a grid the same slots in the same order.The reader compares siblings by position. When the price sits in the same place on every card, the difference between them is the only thing that moves.
- DoSet a large figure as the title, under a small label that says what it counts.The reader learns what the number means before reading it, and the figure stays the largest thing on the card.
- DoKeep the card on screen while its content is missing, and fill its slots with skeletons of the final shape.The card itself never changes: the content shows its own busyness, and the layout does not jump when it arrives.
- Don’tMake a card react to the pointer when nothing happens on click.Hover and press feedback promise an action. A dead target must not look almost clickable, which is also why a card has no disabled state.
- Don’tLift a card off the page with a shadow or a fill.Cards are flat. A solid border and the white surface separate them from the page, and the border alone carries emphasis.
Accessibility
| Key | Description |
|---|---|
| TabShift+Tab | On an interactive card, focuses the title link first, then any nested action. |
| Enter | On the title link, follows it. |
| EnterSpace | On a nested action, runs it. |
A static card is not focusable and takes no keyboard input. The interactive card is not itself a link, so a nested button stays valid HTML. The focus ring surrounds the whole card boundary, and the card border is decorative, so the content identifies the card.
On an interactive card the title link’s text is its accessible name, so a screen reader hears the trip name and not the whole card.
The title is a heading, so a screen reader user jumps from card to card by heading, and on an interactive card lands on the title link. Give the title the level one below the heading the card sits under: h3, the default, under a page section, and h4 under a subsection. The cards then nest inside that section in the page outline instead of reading as its siblings.
API
Card
| Prop | Type | Default | Description |
|---|---|---|---|
| interactive | boolean | false | Turns on hover, focus, and press feedback, and stretches the title link over the card. Put the link directly inside CardTitle. Buttons, links, fields, labels, and any element with a tabindex in the description, content, action, or footer stay above the stretched link. |
| className | string | – | Sets the width, or --card-spacing to change the padding. |
CardTitle
Takes every heading attribute, typed as CardTitleProps.
| Prop | Type | Default | Description |
|---|---|---|---|
| as | CardTitleElement | CardTitleElement.H3 | Sets the heading level, H2 through H6: one below the heading the card sits under. Div is for a title that is still a skeleton, which has no text to navigate to. |
CardHeader, CardDescription, CardAction, CardContent, and CardFooter each render a div and take its props. Use the ones you need. There is no variant and no size: width comes from your layout.