Card
Displays a card with header, content, and footer.
Installation
Install the following dependencies:
Set up the token layer and the StyleX compiler, if you have not already. See
Installation, and copy states.ts from the same page
for the footer's tray. The card also needs interop.css, which pulls a leading
image to the top edge.
Copy and paste the following code into your project.
Update the import paths to match your project setup.
Usage
Composition
CardHeader is a two-column grid. CardAction sits in the second column and
spans both rows, so a title and description stay to its left.
Size
Use size="sm" for a tighter inset and a title one step down.
Spacing
Set --carbon-card-spacing to change the gap between sections and the inset of
every part at once.
Bleed content to the card's edges with a negative
margin-inline: calc(-1 * var(--carbon-card-spacing)), then put the same value
back as padding to keep the text on the card's inset. When that content sits
above a footer, cancel the section gap less the footer's raised strip with
margin-block-end: calc(radius.xl - var(--carbon-card-spacing)) on
CardContent.
These terms govern your use of the workspace, including access to shared documents, project files, and collaboration tools.
You are responsible for the content you upload and for ensuring that your team has the appropriate permissions to view or edit it.
We may update features or limits as the service evolves. When those changes materially affect your workflow, we will notify your workspace administrators.
Image
Put an img first in the card. It runs to the top edge and its corners clip to
the card's radius.
interop.css pulls the image up with a negative margin keyed on
[data-slot="card"] > img:first-child. Without that stylesheet the image sits
inside the card's top padding.
API reference
Pass render to replace a part's element or compose it with another component.
Every part renders a div and takes xstyle and className alongside every
div attribute.
Card
| Prop | Type | Default |
|---|---|---|
size | "default" | "sm" | "default" |
xstyle | StyleXStyles | — |
className | string | — |
size sets --carbon-card-spacing and --carbon-card-title-size on the root.
Setting either directly overrides it.
CardHeader
A grid of 1fr auto, with a 0.25rem row gap. The second column collapses to
nothing without a CardAction.
CardTitle
Reads --carbon-card-title-size at weight 500.
CardDescription
Muted text at the card's own size.
CardAction
Pinned to the header's second column and first row, spanning both rows.
CardContent
The card's inset, and nothing else. Vertical rhythm is the root's row gap.
CardFooter
A tray under the card's body. The body's bottom edge rounds over the tray with a hairline shadow. The footer draws that shadow itself, so the body needs no wrapper. It cancels the root's bottom padding, so put it last.
cardStyles
The style maps behind the component. Spread them onto any element.
| Key | What it is |
|---|---|
base | The surface: fill, ring, radius, shadow, rhythm |
sizes | default and sm, each a pair of variables |
header | The two-column grid |
title | The title's type |
description | The muted description |
action | The header's second column |
content | The body's inset |
footer | The tray, its raised strip and negative margins |
Data attributes
| Attribute | On | Effect |
|---|---|---|
data-slot="card" | the root | Where interop.css keys a leading image |
data-size | the root | Reflects the size prop |
data-slot="card-header" | the header | Targets the header from a parent |
data-slot="card-title" | the title | Targets the title from a parent |
data-slot="card-description" | the description | Targets the description from a parent |
data-slot="card-action" | the action | Targets the action from a parent |
data-slot="card-content" | the body | Targets the body from a parent |
data-slot="card-footer" | the footer | Targets the footer from a parent |
CSS variables
| Variable | On | Effect |
|---|---|---|
--carbon-card-spacing | the root | The section gap and every part's inset. 16px, 12px at sm |
--carbon-card-title-size | the root | The title's size. 16px, 14px at sm |