Card
A surface that holds one thing, with a heading, an action beside it and a footer.
import { Button } from '@/components/panelui/button';
import { Field } from '@/components/panelui/field';
import { Input } from '@/components/panelui/input';
import { Card } from '@/components/panelui/card';
export default function CardForm() {
return (
<Card as="section" className="w-full max-w-sm">
<Card.Header>
<Card.Title>Create a workspace</Card.Title>
<Card.Description>Start on the free plan and invite your team later.</Card.Description>
<Card.Action>
<Button variant="link" className="px-0">
Sign in
</Button>
</Card.Action>
</Card.Header>
<Card.Content>
<form id="create-workspace" className="flex flex-col gap-5">
<Field>
<Field.Label>Work email</Field.Label>
<Input type="email" placeholder="you@company.com" required />
</Field>
<Field>
<Field.Label>Workspace name</Field.Label>
<Input placeholder="Northwind Studio" required />
<Field.Description>You can change it at any time.</Field.Description>
</Field>
</form>
</Card.Content>
<Card.Footer variant="panel" className="flex-col gap-2">
<Button type="submit" form="create-workspace" className="w-full">
Create workspace
</Button>
<Button variant="outline" className="w-full">
Continue with Google
</Button>
</Card.Footer>
</Card>
);
}Use it to hold one thing on a page: a plan, a setting, a summary, an item in a grid. It is a bordered surface with a header, a body and a footer, and the header keeps a place in its top trailing corner for a control that belongs to the whole card.
The padding lives on the parts, not on the card. A picture that should reach the card's edges goes straight inside it with overflow-hidden on the card.
It has no state and no event handlers of its own, so it renders as a server component.
For a list of rows under a title, use Frame.
Installation
npx shadcn@latest add https://panelui.dev/r/web/card.jsonpnpm dlx shadcn@latest add https://panelui.dev/r/web/card.jsonyarn dlx shadcn@latest add https://panelui.dev/r/web/card.jsonbunx shadcn@latest add https://panelui.dev/r/web/card.jsonThe source is copied into components/panelui/, where you can edit it.
Usage
import { Card } from "@/components/panelui/card"<Card>
<Card.Header>
<Card.Title>Create a workspace</Card.Title>
<Card.Description>Start on the free plan and invite your team later.</Card.Description>
<Card.Action>
<Button variant="link">Sign in</Button>
</Card.Action>
</Card.Header>
<Card.Content>
<Field>
<FieldLabel>Work email</FieldLabel>
<Input type="email" />
</Field>
</Card.Content>
<Card.Footer variant="panel">
<Button>Create workspace</Button>
</Card.Footer>
</Card>Composition
<Card>
<Card.Header>
<Card.Title />
<Card.Description />
<Card.Action />
</Card.Header>
<Card.Content>
<Card.Action />
<Card.Meta />
</Card.Content>
<Card.Footer />
</Card>Card.Header— The title, the line under it, and the action. It switches to two columns when there is an action.Card.Title— What the card is about. Anh3by default;aspicks another level to fit the page.Card.Description— A line under the title.Card.Action— A control for the whole card, held in the header's top trailing corner whatever order it is written in. In aninsetcard it can also go insideCard.Content, where it sits in the well's top trailing corner.Card.Content— The body. It starts with top padding of its own when the card has no header.Card.Footer— The row at the bottom.variant="panel"makes it a darker band set into the card, for actions.Card.Meta— A small reading pinned to the bottom trailing corner of the content, such as a count against a limit.labelis the word over it. Put it last inCard.Content.
Examples
Sizes
size="sm" tightens the padding and the title, for a card in a dense grid.
import { Badge } from '@/components/panelui/badge';
import { Card } from '@/components/panelui/card';
function Report({ size }: { size: 'default' | 'sm' }) {
return (
<Card size={size} className="w-full max-w-64">
<Card.Header>
<Card.Title>Weekly report</Card.Title>
<Card.Description>Sent every Monday at 09:00</Card.Description>
</Card.Header>
<Card.Content className="flex gap-1.5">
<Badge variant="secondary">Revenue</Badge>
<Badge variant="secondary">Churn</Badge>
</Card.Content>
</Card>
);
}
export default function CardSizes() {
return (
<div className="flex w-full flex-wrap items-start justify-center gap-4">
<Report size="default" />
<Report size="sm" />
</div>
);
}Footers
A plain footer continues the card. A panel footer is a band set into its bottom, which reads as what you do with the card rather than more of what it says.
import { Button } from '@/components/panelui/button';
import { Input } from '@/components/panelui/input';
import { Card } from '@/components/panelui/card';
export default function CardFooterVariants() {
return (
<div className="flex w-full flex-wrap items-stretch justify-center gap-4">
<Card className="w-full max-w-72">
<Card.Header>
<Card.Title>Invite a teammate</Card.Title>
<Card.Description>They join as a member.</Card.Description>
</Card.Header>
<Card.Content>
<Input type="email" placeholder="name@northwind.studio" aria-label="Email" />
</Card.Content>
<Card.Footer>
<Button className="w-full">Send invite</Button>
</Card.Footer>
</Card>
<Card className="w-full max-w-72">
<Card.Header>
<Card.Title>Delete workspace</Card.Title>
<Card.Description>Projects and files go with it. This cannot be undone.</Card.Description>
</Card.Header>
<Card.Footer variant="panel" className="justify-end">
<Button variant="ghost">Cancel</Button>
<Button variant="destructive">Delete</Button>
</Card.Footer>
</Card>
</div>
);
}Inset
variant="inset" puts the header on the card's outer shell and the content in a raised well inside it. Use it when the header labels what the well holds, here a draft and its rewrite, with a select in the header choosing the tone.
A Card.Action inside the content takes the well's top trailing corner, for clearing or copying what is in it. Card.Meta pins the character count to the bottom trailing corner.
'use client';
import { useState } from 'react';
import { Cancel01Icon, Copy01Icon, Tick02Icon } from '@hugeicons/core-free-icons';
import { HugeiconsIcon } from '@hugeicons/react';
import { Button } from '@/components/panelui/button';
import { Card } from '@/components/panelui/card';
import { Select } from '@/components/panelui/select';
const LIMIT = 280;
const TONES = {
plain: {
label: 'Plain',
main: 'The export runs overnight now, so the morning report is ready when you arrive.',
also: [
'Exports now run overnight. The morning report will be waiting.',
'We moved the export to night time; the report is ready by morning.',
],
},
brief: {
label: 'Brief',
main: 'Exports now run overnight. Report ready by 8am.',
also: ['Overnight exports: report ready at 8.', 'Report now ready first thing.'],
},
warm: {
label: 'Warm',
main: 'Good news: the export now runs while you sleep, so your report is waiting with your coffee.',
also: ['Your morning report now arrives before you do.', 'No more waiting on exports. They finish overnight.'],
},
} as const;
type Tone = keyof typeof TONES;
const TONE_ITEMS = (Object.keys(TONES) as Tone[]).map((value) => ({ value, label: TONES[value].label }));
export default function CardInset() {
const [draft, setDraft] = useState(
'we changed it so that the export job happens during the night which means the report should be done in the morning',
);
const [tone, setTone] = useState<Tone>('plain');
const [copied, setCopied] = useState(false);
const result = TONES[tone];
return (
<div className="grid w-full max-w-3xl gap-3 sm:grid-cols-2">
<Card variant="inset" className="min-h-72">
<Card.Header>
<Card.Title as="div">Your draft</Card.Title>
</Card.Header>
<Card.Content>
<textarea
value={draft}
maxLength={LIMIT}
onChange={(event) => setDraft(event.target.value)}
aria-label="Draft"
placeholder="Write something to rewrite"
className="min-h-28 w-full flex-1 resize-none bg-transparent text-[0.9375rem] leading-relaxed outline-none placeholder:text-muted-foreground"
/>
<Card.Action>
<Button
variant="ghost"
size="icon-sm"
shape="pill"
aria-label="Clear draft"
disabled={draft === ''}
onClick={() => setDraft('')}
>
<HugeiconsIcon icon={Cancel01Icon} />
</Button>
</Card.Action>
<Card.Meta label="Characters">
{draft.length} / {LIMIT}
</Card.Meta>
</Card.Content>
</Card>
<Card variant="inset" className="min-h-72">
<Card.Header>
<Card.Title as="div">Rewrite</Card.Title>
<Card.Action>
<Select items={TONE_ITEMS} value={tone} onValueChange={(value) => setTone(value as Tone)}>
<Select.Trigger variant="ghost" size="sm" aria-label="Tone">
<Select.Value />
</Select.Trigger>
<Select.Content>
{(Object.keys(TONES) as Tone[]).map((key) => (
<Select.Item key={key} value={key}>
{TONES[key].label}
</Select.Item>
))}
</Select.Content>
</Select>
</Card.Action>
</Card.Header>
<Card.Content>
<p className="text-[0.9375rem] leading-relaxed">{draft ? result.main : ''}</p>
<Card.Action>
<Button
variant="ghost"
size="icon-sm"
shape="pill"
aria-label={copied ? 'Copied' : 'Copy rewrite'}
disabled={!draft}
onClick={() => {
void navigator.clipboard?.writeText(result.main);
setCopied(true);
window.setTimeout(() => setCopied(false), 1400);
}}
>
{copied ? <HugeiconsIcon icon={Tick02Icon} /> : <HugeiconsIcon icon={Copy01Icon} />}
</Button>
</Card.Action>
{draft && (
<div className="mt-auto pt-8">
<p className="mb-2 text-xs text-muted-foreground">Other ways to say it</p>
<ul className="space-y-1.5 text-sm leading-snug">
{result.also.map((line) => (
<li key={line}>
<button
type="button"
onClick={() => setDraft(line)}
className="text-left text-foreground/80 transition-colors hover:text-foreground"
>
{line}
</button>
</li>
))}
</ul>
</div>
)}
</Card.Content>
</Card>
</div>
);
}Inset with a list
The well holds whatever the content does. Here it is a ranked list, with the header's select changing the range and Card.Meta keeping the total in the corner.
'use client';
import { useState } from 'react';
import { Card } from '@/components/panelui/card';
import { Select } from '@/components/panelui/select';
const RANGES = {
week: {
label: 'This week',
total: '38',
rows: [
['api-gateway', 14, '2m ago'],
['web', 11, '1h ago'],
['billing-worker', 8, 'Tue'],
['search-indexer', 5, 'Mon'],
],
},
month: {
label: 'This month',
total: '152',
rows: [
['web', 49, '1h ago'],
['api-gateway', 47, '2m ago'],
['billing-worker', 31, 'Tue'],
['search-indexer', 25, 'Mon'],
],
},
} as const;
type Range = keyof typeof RANGES;
const RANGE_ITEMS = [
{ value: 'week', label: 'This week' },
{ value: 'month', label: 'This month' },
];
export default function CardInsetList() {
const [range, setRange] = useState<Range>('week');
const data = RANGES[range];
const max = Math.max(...data.rows.map((row) => row[1]));
return (
<Card variant="inset" className="w-full max-w-80">
<Card.Header>
<Card.Title as="div">Deploys</Card.Title>
<Card.Action>
<Select items={RANGE_ITEMS} value={range} onValueChange={(value) => setRange(value as Range)}>
<Select.Trigger variant="ghost" size="sm" aria-label="Range">
<Select.Value />
</Select.Trigger>
<Select.Content>
<Select.Item value="week">This week</Select.Item>
<Select.Item value="month">This month</Select.Item>
</Select.Content>
</Select>
</Card.Action>
</Card.Header>
<Card.Content>
<ul className="space-y-3">
{data.rows.map(([name, count, last]) => (
<li key={name} className="grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-1.5">
<span className="truncate text-sm">{name}</span>
<span className="text-sm tabular-nums">{count}</span>
<span className="h-1 overflow-hidden rounded-full bg-muted">
<span
className="block h-full rounded-full bg-foreground/70 transition-[width] duration-500"
style={{ width: `${(count / max) * 100}%` }}
/>
</span>
<span className="text-xs text-muted-foreground">{last}</span>
</li>
))}
</ul>
<Card.Meta label="Total">{data.total} deploys</Card.Meta>
</Card.Content>
</Card>
);
}Image
A picture placed first in the card reaches its edges. Give the card overflow-hidden so the picture takes its top corners; the parts after it keep their own padding.
import { Badge } from '@/components/panelui/badge';
import { Button } from '@/components/panelui/button';
import { Card } from '@/components/panelui/card';
export default function CardImage() {
return (
// `overflow-hidden` is all the picture needs: the padding is on the parts.
<Card as="article" className="w-full max-w-xs overflow-hidden">
<img
src="https://images.unsplash.com/photo-1510127034890-ba27508e9f1c?auto=format&fit=crop&w=720&q=70"
alt="A silver rangefinder camera on a table beside a stack of prints"
className="aspect-[4/3] w-full object-cover"
/>
<Card.Header>
<Card.Title>Silver rangefinder, 23 mm lens</Card.Title>
<Card.Description>Used for one season · Lisbon</Card.Description>
<Card.Action>
<Badge variant="secondary">£640</Badge>
</Card.Action>
</Card.Header>
<Card.Footer>
<Button className="w-full">Message the seller</Button>
</Card.Footer>
</Card>
);
}In a list
as="li" puts the card in a list, and Card.Title's as sets the heading level to fit the page around it.
import { Badge } from '@/components/panelui/badge';
import { Card } from '@/components/panelui/card';
const PROJECTS = [
{ name: 'Checkout redesign', team: 'Payments', status: 'In review', tone: 'info' as const },
{ name: 'Onboarding emails', team: 'Growth', status: 'Shipped', tone: 'success' as const },
{ name: 'Search ranking', team: 'Discovery', status: 'Blocked', tone: 'warning' as const },
];
export default function CardList() {
return (
<ul className="grid w-full max-w-2xl gap-3 sm:grid-cols-3">
{PROJECTS.map((project) => (
<Card as="li" size="sm" key={project.name}>
<Card.Header>
<Card.Title as="h4">{project.name}</Card.Title>
<Card.Description>{project.team}</Card.Description>
</Card.Header>
<Card.Content>
<Badge variant={project.tone}>{project.status}</Badge>
</Card.Content>
</Card>
))}
</ul>
);
}API Reference
Card
| Prop | Type | Default | Description |
|---|---|---|---|
size | 'default' | 'sm' | 'default' | sm tightens the padding and the title, for a card in a dense grid. Default default. |
as | 'div' | 'article' | 'section' | 'li' | 'div' | The element to render. article for a card that stands on its own, li for one in a list, section for one that groups a part of a page. |
variant | 'default' | 'inset' | 'default' | default is one surface. inset puts the header on the card's shell and the content in a raised well inside it, for a card whose header labels what the content holds. Default default. |
Card.Header
| Prop | Type | Default | Description |
|---|---|---|---|
defaultTagName | 'div', | — | |
props | mergeProps({ 'data-slot': 'card-header', className: slots.header({ className }) }, props), | — |
Card.Title
| Prop | Type | Default | Description |
|---|---|---|---|
as | 'h2' | 'h3' | 'h4' | 'div' | 'div' | The heading level, to fit the page around the card. Default h3. |
Card.Description
| Prop | Type | Default | Description |
|---|---|---|---|
defaultTagName | 'p', | — | |
props | mergeProps({ 'data-slot': 'card-description', className: slots.description({ className }) }, props), | — |
Card.Action
| Prop | Type | Default | Description |
|---|---|---|---|
defaultTagName | 'div', | — | |
props | mergeProps({ 'data-slot': 'card-action', className: slots.action({ className }) }, props), | — |
Card.Content
| Prop | Type | Default | Description |
|---|---|---|---|
defaultTagName | 'div', | — | |
props | mergeProps({ 'data-slot': 'card-content', className: slots.content({ className }) }, props), | — |
Card.Footer
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'plain' | 'panel' | 'default' | plain continues the card. panel is a darker band set into its bottom, for actions. Default plain. |
Card.Meta
| Prop | Type | Default | Description |
|---|---|---|---|
label | ReactNode | — | A small word over the value: "Characters", "Updated". |
Every part also takes the props of the element it renders, and a className.
Notes
as on the card renders it as a div, article, section or li. Use article for a card that makes sense on its own and li inside a list.
Card.Title is a heading so the page outline includes it. Set its level with as, from h2 to h4, or div for a card that should stay out of the outline.
Inset
In an inset card the well's radius is the card's less the shell's padding, so the two corners stay concentric. In light mode the shell is a step greyer than the well; in dark mode the well is a step lighter, so it reads as raised in both. A footer still goes on the shell, below the well.
Server Components
Card is a client component. In a file that starts with "use client", write its parts with a dot, as on this page. A Server Component cannot read Card.Header off the import, so each part is also exported by name: CardHeader is Card.Header, and so on for the others.
import { Card, CardHeader, CardTitle, CardDescription, CardAction, CardContent, CardFooter, CardMeta } from "@/components/panelui/card"