Card
updatedImpressive. Very nice. Let's see Paul Allen's card. A surface that groups related content, with header, title, description, content and footer parts.
Upgrade to Pro
Unlimited projects and priority support for your whole team.
$12
per member, per month
Open Props in the corner of the example to try variant and size.
size goes from xs to xl, md by default. Padding, gap and radius grow together. The title and description keep their text size, so a text-* class of your own on them wins.
Bone. Eggshell. Romalian type. Ours come in four:
outline(default): a surface with an edgesolid: no edge, a small shadow instead; for a card on a plain pagesoft: a tinted surface, no edgesubtle: a tint with an edge; for grouping controls or a card on a card
Switching variants never moves the layout, and an image that reaches the sides never covers the edge.
Installation
Usage
<script setup lang="ts">
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'
</script>
<template>
<Card>
<CardHeader>
<CardTitle>Title</CardTitle>
<CardDescription>Description</CardDescription>
</CardHeader>
<CardContent>Content</CardContent>
<CardFooter>Footer</CardFooter>
</Card>
</template>
Every part is optional: leave one out, and no gap is left behind.
All the spacing comes from one variable, --card-spacing. size sets it, and a class like [--card-spacing:--spacing(8)] overrides it. Colours are --card and --card-foreground.
Examples
Edge to edge
Want content to reach the edges?
- A list:
px-0on the part, so the items and their hover reach the sides. Let the items pad themselves, like theItems of the card's size here. - An image on top:
pt-0andoverflow-hiddenon the card.
Jacques-Cartier
Three trails start at the visitor centre.
Dividers
Add border-b to the header or border-t to the footer, and it pads itself away from the line.
Team members
Three people can open this project.
- Ada LovelaceOwner
- Alan TuringEditor
- Grace HopperViewer
API Reference
Every part takes a class that merges with its own.
Card
| Prop | Default | Type and description |
|---|---|---|
| variant | "outline" | "outline" | "solid" | "soft" | "subtle" | null
|
| size | "md" | CardSizePadding, gaps, radius and text, from 12px and |
| Slot | Scope and description |
|---|---|
| default | {}The surface. Holds the other parts, or any content of your own. |
CardTitle
| Prop | Default | Type and description |
|---|---|---|
| asChild | — | booleanRender the single child instead of a wrapper, merging the title's attributes and classes onto it. |
| as | "h3" | AsTag | ComponentThe element to render. Pick the heading level that fits the page's outline. |
| Slot | Scope and description |
|---|---|
| default | {}The title text. |
CardHeader
| Slot | Scope and description |
|---|---|
| default | {}Title and description. |
CardDescription
| Slot | Scope and description |
|---|---|
| default | {}Supporting text for the title. |
CardContent
| Slot | Scope and description |
|---|---|
| default | {}The card's main content. |
CardFooter
| Slot | Scope and description |
|---|---|
| default | {}Actions, laid out in a row. |
Props
- variant
"outline" "outline" | "solid" | "soft" | "subtle" | nulloutline(the default) is the surface with an edge,solidthe surface lifted by a small shadow and no edge,softa tinted surface without an edge, andsubtlea tinted surface with one. The edge is a ring outside the box, not a border, so every variant has the same size.- size
"md" CardSizePadding, gaps, radius and text, from 12px andtitle-smforxsto 40px andheadline-smforxl.md, 24px, is the default; every part reads the same--card-spacing.
Slots
- default
{}The surface. Holds the other parts, or any content of your own.
Props
- asChild
booleanRender the single child instead of a wrapper, merging the title's attributes and classes onto it.- as
"h3" AsTag | ComponentThe element to render. Pick the heading level that fits the page's outline.
Slots
- default
{}The title text.
Slots
- default
{}Title and description.
Slots
- default
{}Supporting text for the title.
Slots
- default
{}The card's main content.
Slots
- default
{}Actions, laid out in a row.
Data attributes
| data-slot | Attributes | Description |
|---|---|---|
| card | data-variant, data-size | The surface. |
| card-header | — | Title and description. |
| card-title | — | The title. |
| card-description | — | Supporting text. |
| card-content | — | The main content. |
| card-footer | — | Actions. |
Accessibility
CardTitle is an h3. Screen reader users skim pages by headings, so set the level that fits with as: h2 for cards right under the page title, div if the title shouldn't be a heading at all.