shadcn.io is an independent project built on shadcn/ui
On this page9 sections
A card is a surface with its own background and outline that holds one subject: a title with a short description under it, an optional action in the top corner, the body, and a footer for the buttons. Reach for it when a block has to stand on its own, like a login form, a pricing plan or an upcoming event.
For rows that repeat, such as files or team members, an Item is lighter. To put several panels under one heading, use a Frame.
Installation
Anatomy

Usage
import { Button } from "@/components/ui/button";
import {
Card, CardAction, CardContent, CardDescription, CardFooter,
CardHeader, CardTitle,
} from "@/components/ui/card";Every part is optional, and a header with content is already a whole card. CardAction lands in the top corner only when it sits inside CardHeader.
<Card className="w-full max-w-sm">
<CardHeader>
<CardTitle>Team plan</CardTitle>
<CardDescription>$12 per member, billed monthly.</CardDescription>
<CardAction>
<Button variant="link">Compare plans</Button>
</CardAction>
</CardHeader>
<CardContent>
<p>Shared projects, unlimited guests and priority support.</p>
</CardContent>
<CardFooter>
<Button className="w-full">Upgrade to Team</Button>
</CardFooter>
</Card>Accessibility
The card is a plain div with no role, and it takes no focus or keys of its own. The links, fields and buttons inside it keep their own semantics and tab order. CardTitle renders an h2, so each title is a heading a screen reader can jump to. Make sure that level fits the page, and change it where the cards sit under an h2 of their own.
Demos
Small
The Scheduled reports feature card sets size="sm" on Card, which tightens --card-spacing, and pairs it with small buttons in the footer. Reach for it in a grid of feature cards or a hint beside a settings form, where a full-size card would outweigh what is around it. A form people fill in reads better at the default size.
Spacing
A toggle above the login card sets --card-spacing to 16, 20, 24 or 32 pixels, and the side insets of every part and the gaps between them follow that one value. Set the variable with a class on Card when the style's default is too tight for a marketing page or too loose for a dense admin screen.
Edge to edge
The terms of service scroll in a muted box that reaches both side edges of the card: it takes -mx-(--card-spacing) and puts the same value back as padding, and a negative bottom margin on CardContent closes the gap above the footer. The box is a named region in the tab order, so a keyboard can scroll it. Use this for an agreement, a table or a log.
Image
A design systems meetup with a grayscale cover image above the header, a Featured badge in CardAction and a View Event button. A card whose first child is an img drops its top padding by itself, but here a dark scrim div comes first, so the demo adds pt-0 to Card. Use this layout for events, articles or products, where the picture is what people scan for.
RTL
The login card in Arabic, with dir="rtl" on Card. The sign-up button moves to the left corner, because CardAction sits at the end of the header's grid, and the forgot-password link uses a logical margin so it stays at the end of its row. Set dir on the card when it is an Arabic or Hebrew block on a left-to-right page.
FAQ
How do I put a button or badge in the top corner of a Card?
Place it in CardAction inside CardHeader. The header is a grid that switches to two columns when it holds an action, so the title and description stay in the first column and the action sits at the top of the second, against the end of the row. The Image demo puts a Featured badge there.
Keep that corner for small, secondary things: a menu, a badge, a link. The action the card exists for, such as Save or Buy, reads better as a full button in CardFooter.
How do I add a full-width image to the top of a Card?
Make the img the first child of Card, before CardHeader. The card drops its top padding, and its rounded corners and hidden overflow clip the picture, so it runs edge to edge. Give the image w-full and a fixed ratio such as aspect-video so the card doesn't jump while it loads.
The padding rule only looks at the first child. If something else comes first, like the scrim in the Image demo, add pt-0 to the card yourself. For a full-width block lower down, use the negative margins from the Edge to edge demo.
How do I make a Card smaller or change its padding?
Set size="sm" on Card for the compact preset, which lowers --card-spacing, as the Small demo does. For any other value, set the variable yourself with a class such as [--card-spacing:--spacing(8)], as in the Spacing demo.
That one value drives the card's top and bottom padding, the gaps between header, content and footer, and each part's side inset, so they stay in proportion. Padding one part by hand, say with p-8 on CardContent, pulls it out of line with the header above it.
How do I make Cards in a grid the same height with buttons at the bottom?
Put the cards in a CSS grid and their heights already match, since grid items stretch to fill their row. The spare height collects under the footer, though, because Card is a flex column that packs its parts at the top.
Add mt-auto to CardFooter, or flex-1 to CardContent, and the footers line up along the bottom of the row. In a flex row the same works as long as the row doesn't set items-start, which turns the stretching off.
How do I make a whole Card clickable?
Wrap the card in LinkBox from Link Overlay and put a LinkOverlay inside CardTitle. A pseudo-element stretches that link over the whole card, so a click anywhere follows it, while a screen reader hears one short link named by the title. Other links in the card stay clickable above the overlay.
Wrapping the card in an <a> works only while nothing inside it is interactive. Once it holds a button or a second link, the markup is invalid, because interactive elements can't nest.
Is there a shorter way to write a Card header in React?
Pass title and description to CardHeader as strings, and it renders CardTitle and CardDescription for you, in that order. A CardAction still goes in as a child and lands in the corner as usual. A header whose only child is plain text also renders that text as the title, above a description passed as a prop.
Use the parts themselves when the title needs markup of its own, such as a link, an icon or a badge next to the words.
Is CardTitle a heading, and how do I change its level?
It is an h2, which fits cards placed right under the page's h1. When the cards sit in a section that has its own h2, their titles should be h3, so the outline keeps its levels. Change the h2 in components/ui/card, which is your code once installed, to the level your page needs.
Should I use a Card or an Item for a list?
Use an Item for rows that repeat, such as files, team members or notification settings. Each one is a compact line with media, a title, a description and actions at its end, and a list of them stays easy to scan. A Card is a block of its own, with a header, a body and a footer, sized for a form, a plan or an event.
A page usually holds a few cards side by side or in a grid. When you find yourself stacking dozens of cards in a column, the content is a list, and items will read better.
API Reference
Card
<div> data-slot="card"
size?"default" | "sm"
The size.
- Type
"default" | "sm"- Default
"default"
className?string
Merged with the part's classes.
data-size?string
Mirrors size.
CardMedia
<div> data-slot="card-media"
variant?"default" | "icon" | "image"
The visual style.
- Type
"default" | "icon" | "image"- Default
"default"
className?string
Merged with the part's classes.
data-variant?string
Mirrors variant.
CardHeader
<div> data-slot="card-header"
description?string
The description of the card.
title?string
The title of the card.
className?string
Merged with the part's classes.
CardTitle
<h2> data-slot="card-title"
className?string
Merged with the part's classes.
CardDescription
<div> data-slot="card-description"
className?string
Merged with the part's classes.
CardAction
<div> data-slot="card-action"
className?string
Merged with the part's classes.
CardContent
<div> data-slot="card-content"
className?string
Merged with the part's classes.
CardFooter
<div> data-slot="card-footer"
className?string
Merged with the part's classes.











