Documentation Index
Fetch the complete documentation index at: https://mintlify.com/shadcn-ui/ui/llms.txt
Use this file to discover all available pages before exploring further.
Installation
npx shadcn@latest add card
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card"
<Card>
<CardHeader>
<CardTitle>Card Title</CardTitle>
<CardDescription>Card Description</CardDescription>
</CardHeader>
<CardContent>
<p>Card Content</p>
</CardContent>
<CardFooter>
<p>Card Footer</p>
</CardFooter>
</Card>
Component Code
import * as React from "react"
import { cn } from "@/lib/utils"
function Card({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card"
className={cn(
"flex flex-col gap-6 rounded-xl border bg-card py-6 text-card-foreground shadow-sm",
className
)}
{...props}
/>
)
}
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-header"
className={cn(
"grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto]",
className
)}
{...props}
/>
)
}
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-title"
className={cn("leading-none font-semibold", className)}
{...props}
/>
)
}
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-description"
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
)
}
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-action"
className={cn(
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
className
)}
{...props}
/>
)
}
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-content"
className={cn("px-6", className)}
{...props}
/>
)
}
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-footer"
className={cn("flex items-center px-6", className)}
{...props}
/>
)
}
export {
Card,
CardHeader,
CardFooter,
CardTitle,
CardAction,
CardDescription,
CardContent,
}
Examples
Basic
With Action
Interactive
A basic card with header, content, and footer.<Card>
<CardHeader>
<CardTitle>Create project</CardTitle>
<CardDescription>Deploy your new project in one-click.</CardDescription>
</CardHeader>
<CardContent>
<form>
<Input placeholder="Project name" />
</form>
</CardContent>
<CardFooter>
<Button>Create</Button>
</CardFooter>
</Card>
Add an action button in the header using CardAction.<Card>
<CardHeader>
<CardTitle>Notifications</CardTitle>
<CardDescription>You have 3 unread messages.</CardDescription>
<CardAction>
<Button variant="ghost" size="icon">
<MoreHorizontalIcon />
</Button>
</CardAction>
</CardHeader>
<CardContent>
<p>Card content goes here</p>
</CardContent>
</Card>
Make the entire card clickable.<Card className="cursor-pointer hover:bg-accent transition-colors">
<CardHeader>
<CardTitle>Interactive Card</CardTitle>
<CardDescription>Click anywhere on this card</CardDescription>
</CardHeader>
<CardContent>
<p>Card content</p>
</CardContent>
</Card>
Composition
Cards are highly composable and can contain any content. Common patterns include:
- Forms with input fields
- Lists of items
- Charts and data visualizations
- Image galleries
- User profiles
API Reference
| Prop | Type | Default |
|---|
className | string | - |
| Prop | Type | Default |
|---|
className | string | - |
CardTitle
| Prop | Type | Default |
|---|
className | string | - |
CardDescription
| Prop | Type | Default |
|---|
className | string | - |
CardAction
| Prop | Type | Default |
|---|
className | string | - |
CardContent
| Prop | Type | Default |
|---|
className | string | - |
| Prop | Type | Default |
|---|
className | string | - |