Card
Displays content in a contained card format with various styling options and layouts.
Installation
Add Card to your project with the CK-UI CLI. It copies the source into your project, so the code is yours to change.
- Adds
card.tsxto your CK-UI folder (src/components/ck-ui by default)- Installs
@radix-ui/react-slotclass-variance-authorityif your project does not have them yet
First time with CK-UI in this project? Run npx ck-ui-cli@latest init once before adding components. The installation guide explains what it sets up.
Manual installationInstall the packages and copy the files yourself.
Install the following dependencies
Run these commands in your terminal to install the required packages
Create or update your card component
Copy this code to create your card component
Test Your Component
- 1. Add the component to a test page
- 2. Check all props and variants work as expected
- 3. Verify responsive behavior
- 4. Test with different content/data
- 5. Ensure accessibility features work correctly
Composition
Card.Root is a padded container, so any content works inside it. For the common layout, use the optional parts: Card.Header with Card.Title and Card.Description, then Card.Content and Card.Footer. Each part after the first is spaced according to the card size.
Team plan
Billed monthly. Cancel anytime.
Sizes
API Reference
The Card component provides a flexible container for grouping related content and actions. Every part forwards its ref and accepts asChild.
Card.Root
Main container (a div). Uses Radix UI's Slot primitive when asChild is true.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "default""ghost" | "default" | default has a 1px border; ghost has no border and a hover background |
size | "sm""md""lg" | "md" | Padding, text size and the spacing between card parts |
width | "auto""full""fit" | "undefined" | Width class. Unset adds no width class; constrained is a deprecated alias of auto. |
asChild | "boolean" | "false" | Render the single child element instead of a div, merging the card props onto it (Radix Slot) |
className | "string" | "undefined" | Additional CSS classes, merged last |
Card.Header
Groups the title and description (a div, stacked with a small gap).
| Prop | Type | Default | Description |
|---|---|---|---|
asChild | "boolean" | "false" | Render the single child element instead of the default element |
className | "string" | "undefined" | Additional CSS classes, merged last |
Card.Title
Renders an h3. Use asChild to choose the heading level that fits your page outline, e.g. asChild with an h2 child.
| Prop | Type | Default | Description |
|---|---|---|---|
asChild | "boolean" | "false" | Render the single child element instead of the default element |
className | "string" | "undefined" | Additional CSS classes, merged last |
Card.Description
Supporting text in the muted foreground colour (a p).
| Prop | Type | Default | Description |
|---|---|---|---|
asChild | "boolean" | "false" | Render the single child element instead of the default element |
className | "string" | "undefined" | Additional CSS classes, merged last |
Card.Content
Main content area (a div).
| Prop | Type | Default | Description |
|---|---|---|---|
asChild | "boolean" | "false" | Render the single child element instead of the default element |
className | "string" | "undefined" | Additional CSS classes, merged last |
Card.Footer
Bottom row for actions (a div laid out as a horizontal flex row).
| Prop | Type | Default | Description |
|---|---|---|---|
asChild | "boolean" | "false" | Render the single child element instead of the default element |
className | "string" | "undefined" | Additional CSS classes, merged last |
Used in these blocks
Block families with at least one block built on this component. Each page previews its blocks and lists the components and packages they use.