Card
Groups the content of one subject on a bounded surface, with regions for media, a header, a body and a footer.
Meridian Packaging
Supplier since 2019import { Button } from '@slotted/react/button';import { Card, CardBody, CardFooter, CardHeader } from '@slotted/react/card';import { Heading, Text } from '@slotted/react/typography';export default function CardBasic() { return ( <Card> <CardHeader> <Heading level={2} size="md"> Meridian Packaging </Heading> <Text size="sm" tone="muted"> Supplier since 2019 </Text> </CardHeader> <CardBody> <Text>Delivers pallets of cartons to Rotterdam every Tuesday and Friday.</Text> </CardBody> <CardFooter> <Button variant="outline">View orders</Button> </CardFooter> </Card> );}Installation
The packages are a 0.x beta on npm, and their public API changes between beta releases without deprecation. One line installs the binding and the default theme.
pnpm add @slotted/react @slotted/theme @slotted/themesFill
fill sets how the surface is bounded: outline, the default, is a hairline edge; elevated adds a lift to the edge; subtle is a filled ground. A set of cards sits in a Grid or a Stack, as here.
Open purchase orders
fill: outlineInvoices due this week
fill: elevatedReorder alerts
fill: subtleimport { Card, CardBody, CardHeader } from '@slotted/react/card';import type { CardFill } from '@slotted/react/card';import { Grid } from '@slotted/react/grid';import { Heading, Text } from '@slotted/react/typography';const SUMMARIES: { fill: CardFill; title: string; body: string }[] = [ { fill: 'outline', title: 'Open purchase orders', body: '14 orders, 3 awaiting approval.' }, { fill: 'elevated', title: 'Invoices due this week', body: '6 invoices totaling $18,240.' }, { fill: 'subtle', title: 'Reorder alerts', body: '9 products below their reorder point.' },];export default function CardFills() { return ( <Grid columns={3} gap={4} minItemWidth="xs"> {SUMMARIES.map((summary) => ( <Card fill={summary.fill} key={summary.fill}> <CardHeader> <Heading level={2} size="md"> {summary.title} </Heading> <Text size="sm" tone="muted">{`fill: ${summary.fill}`}</Text> </CardHeader> <CardBody> <Text>{summary.body}</Text> </CardBody> </Card> ))} </Grid> );}Sizes
size sets the inset of the card itself: sm, md or lg. Density is the choice of the application, and this inset is the choice of the card. The same content under each size shows the step between them.
Invoice 20418
size: smInvoice 20418
size: mdInvoice 20418
size: lgimport { Card, CardBody, CardFooter, CardHeader } from '@slotted/react/card';import type { CardSize } from '@slotted/react/card';import { Grid } from '@slotted/react/grid';import { Heading, Text } from '@slotted/react/typography';const SIZES: CardSize[] = ['sm', 'md', 'lg'];export default function CardSizes() { return ( <Grid columns={3} gap={4} minItemWidth="xs"> {SIZES.map((size) => ( <Card key={size} size={size}> <CardHeader> <Heading level={2} size="md"> Invoice 20418 </Heading> <Text size="sm" tone="muted">{`size: ${size}`}</Text> </CardHeader> <CardBody> <Text>$4,820.00, due 15 December.</Text> </CardBody> <CardFooter> <Text size="sm" tone="muted"> Meridian Packaging </Text> </CardFooter> </Card> ))} </Grid> );}Regions
CardHeader holds a title and the line that supports it, both written with Heading and Text. CardActions is the corner of the header: beside a title alone it is centered on the title, and beside a title and its line it is centered on both. CardBody holds the content. CardFooter holds actions and metadata.
Invoice 20418
Meridian Packagingimport { Badge } from '@slotted/react/badge';import { Button } from '@slotted/react/button';import { Card, CardActions, CardBody, CardFooter, CardHeader } from '@slotted/react/card';import { Inline } from '@slotted/react/inline';import { Heading, Text } from '@slotted/react/typography';export default function CardRegions() { return ( <Card> <CardHeader> <Heading level={2} size="md"> Invoice 20418 </Heading> <Text size="sm" tone="muted"> Meridian Packaging </Text> <CardActions> <Badge tone="warning">Overdue</Badge> </CardActions> </CardHeader> <CardBody> <Text>$4,820.00 was due on 15 November. A late fee of 1.5% applies from 1 December.</Text> </CardBody> <CardFooter> <Inline> <Button>Pay invoice</Button> <Button tone="secondary" variant="outline"> Download PDF </Button> </Inline> </CardFooter> </Card> );}Rules between regions
A rule between two regions is a Divider written between them. Mark it decorative so that it is not announced as a separator, which is what a rule inside one card usually is. inset indents the rule from both edges.
Rotterdam warehouse
Pallet capacityimport { Card, CardBody, CardFooter, CardHeader } from '@slotted/react/card';import { Divider } from '@slotted/react/divider';import { Heading, Text } from '@slotted/react/typography';export default function CardDividers() { return ( <Card> <CardHeader> <Heading level={2} size="md"> Rotterdam warehouse </Heading> <Text size="sm" tone="muted"> Pallet capacity </Text> </CardHeader> <Divider decorative /> <CardBody> <Text>8,420 of 10,000 pallet positions are in use.</Text> </CardBody> <Divider decorative inset /> <CardFooter> <Text size="sm" tone="muted"> Counted on 24 November at 06:00. </Text> </CardFooter> </Card> );}Media
CardMedia runs to the edge of the card and rounds the corners it touches. An img, video, canvas, picture or svg inside it fills the part and is cropped to cover it. Media clips itself, so an overlay opened inside the card is not cut off. The picture here is an inline SVG, so the example makes no network request.
Meridian Packaging
Rotterdam, 3 warehousesimport { Button } from '@slotted/react/button';import { Card, CardBody, CardFooter, CardHeader, CardMedia } from '@slotted/react/card';import { Heading, Text } from '@slotted/react/typography';const COVER = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 320 160'%3E%3Crect width='320' height='160' fill='%23c7d2fe'/%3E%3Crect x='40' y='70' width='80' height='90' fill='%234338ca'/%3E%3Crect x='130' y='40' width='70' height='120' fill='%236366f1'/%3E%3Crect x='210' y='85' width='70' height='75' fill='%234338ca'/%3E%3C/svg%3E";export default function CardMediaExample() { return ( <Card> <CardMedia> <img alt="" src={COVER} /> </CardMedia> <CardHeader> <Heading level={2} size="md"> Meridian Packaging </Heading> <Text size="sm" tone="muted"> Rotterdam, 3 warehouses </Text> </CardHeader> <CardBody> <Text>14 purchase orders are open, and the next delivery arrives on Tuesday.</Text> </CardBody> <CardFooter> <Button variant="outline">View supplier</Button> </CardFooter> </Card> );}Horizontal
orientation="horizontal" places the media beside the regions. The card measures its own inline size, and at 24rem or less the media returns to the top, so the card stacks in a narrow column or on a phone with no breakpoint.
Rotterdam warehouse
Capacity report, Q4import { Button } from '@slotted/react/button';import { Card, CardBody, CardFooter, CardHeader, CardMedia } from '@slotted/react/card';import { Heading, Text } from '@slotted/react/typography';const COVER = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 320 160'%3E%3Crect width='320' height='160' fill='%23c7d2fe'/%3E%3Crect x='40' y='70' width='80' height='90' fill='%234338ca'/%3E%3Crect x='130' y='40' width='70' height='120' fill='%236366f1'/%3E%3Crect x='210' y='85' width='70' height='75' fill='%234338ca'/%3E%3C/svg%3E";export default function CardHorizontal() { return ( <Card orientation="horizontal"> <CardMedia> <img alt="" src={COVER} /> </CardMedia> <CardHeader> <Heading level={2} size="md"> Rotterdam warehouse </Heading> <Text size="sm" tone="muted"> Capacity report, Q4 </Text> </CardHeader> <CardBody> <Text>Pallet positions in use rose from 71% to 84% between October and November.</Text> </CardBody> <CardFooter> <Button variant="outline">Open report</Button> </CardFooter> </Card> );}Body that bleeds
bleed on CardBody removes the padding of the body and clips it to the corners of the card it touches. The children run from one edge to the other, which suits a list whose rules and row grounds reach the edge.
Open invoices
Due before 31 December- Meridian Packaging$4,820.00
- Alder Freight$12,115.50
- Kestrel Pallets$1,340.00
import { Card, CardBody, CardHeader } from '@slotted/react/card';import { List } from '@slotted/react/list';import { ListItem, ListItemBody, ListItemContent, ListItemEnd, ListItemLabel,} from '@slotted/react/list-item';import { Heading, Text } from '@slotted/react/typography';const INVOICES = [ { id: '20418', supplier: 'Meridian Packaging', amount: '$4,820.00' }, { id: '20431', supplier: 'Alder Freight', amount: '$12,115.50' }, { id: '20437', supplier: 'Kestrel Pallets', amount: '$1,340.00' },];export default function CardBleed() { return ( <Card> <CardHeader> <Heading level={2} size="md"> Open invoices </Heading> <Text size="sm" tone="muted"> Due before 31 December </Text> </CardHeader> <CardBody bleed> <List aria-label="Open invoices" variant="ruled"> {INVOICES.map((invoice) => ( <ListItem key={invoice.id}> <ListItemContent> <ListItemBody> <ListItemLabel>{invoice.supplier}</ListItemLabel> </ListItemBody> <ListItemEnd>{invoice.amount}</ListItemEnd> </ListItemContent> </ListItem> ))} </List> </CardBody> </Card> );}A card that links
CardLink is the one destination of the card. Its hit area covers the whole surface, so a press anywhere on the card follows the link, while the accessible name stays the title and Enter, the context menu and middle-click remain the browser’s. A card carries at most one. CardActions and CardFooter sit above the hit area, so the link in the footer stays operable. The card answers hover and press unless it is disabled. Text over the hit area cannot be selected with the pointer.
import { Card, CardBody, CardFooter, CardHeader, CardLink } from '@slotted/react/card';import { Link } from '@slotted/react/link';import { Heading, Text } from '@slotted/react/typography';export default function CardLinkExample() { return ( <Card> <CardHeader> <CardLink href="#meridian"> <Heading level={2} size="md"> Meridian Packaging </Heading> </CardLink> <Text size="sm" tone="muted"> Supplier since 2019 </Text> </CardHeader> <CardBody> <Text>12 open invoices totaling $31,460.00.</Text> </CardBody> <CardFooter> <Link href="#meridian-terms">Payment terms</Link> </CardFooter> </Card> );}A card that chooses
A choice card is a label around a native radio or checkbox placed in CardSelection. In React, render makes the root a label; in Angular, slCard is written on a label. The whole surface becomes the target, and the text of the label names the control. Write that text with Text: a heading has no place in a label. The set of cards is a named radiogroup, so the question is announced with the options. Options that need no card are the tiles of a RadioGroup. selected paints the accent ground and edge. disabled dims the card and removes its hover; the disabled of the input is what refuses the interaction. Both are painted only: the input announces the state to assistive technology. Choose Express, then try the last card.
import { useState } from 'react';import { Card, CardHeader, CardSelection } from '@slotted/react/card';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';const METHODS = [ { id: 'standard', name: 'Standard', note: '5 to 7 days, free', available: true }, { id: 'express', name: 'Express', note: '2 days, $12.00', available: true }, { id: 'same-day', name: 'Same day', note: 'Not offered for this address', available: false },];export default function CardChoice() { const [method, setMethod] = useState('standard'); return ( <Stack aria-label="Delivery method" gap={3} role="radiogroup"> {METHODS.map((option) => ( <Card disabled={!option.available} key={option.id} render={(props) => <label {...props} />} selected={method === option.id} > <CardHeader> <CardSelection> <input checked={method === option.id} disabled={!option.available} name="delivery" onChange={() => { setMethod(option.id); }} type="radio" value={option.id} /> </CardSelection> <Text size="lg" weight="semibold"> {option.name} </Text> <Text size="sm" tone="muted"> {option.note} </Text> </CardHeader> </Card> ))} </Stack> );}Defaults
CardDefaultsProvider in React and provideCardDefaults in Angular set fill, orientation and size once for every card under them. A card that states a value of its own keeps it.
Orders shipped
elevated, lgReturns received
outline, smimport { Card, CardBody, CardDefaultsProvider, CardHeader } from '@slotted/react/card';import { Grid } from '@slotted/react/grid';import { Heading, Text } from '@slotted/react/typography';export default function CardDefaults() { return ( <CardDefaultsProvider fill="elevated" size="lg"> <Grid columns={2} gap={4} minItemWidth="xs"> <Card> <CardHeader> <Heading level={2} size="md"> Orders shipped </Heading> <Text size="sm" tone="muted"> elevated, lg </Text> </CardHeader> <CardBody> <Text>312 orders left the Reno warehouse today.</Text> </CardBody> </Card> <Card fill="outline" size="sm"> <CardHeader> <Heading level={2} size="md"> Returns received </Heading> <Text size="sm" tone="muted"> outline, sm </Text> </CardHeader> <CardBody> <Text>18 returns arrived and 11 are restocked.</Text> </CardBody> </Card> </Grid> </CardDefaultsProvider> );}Accessibility
- There is no card pattern in the WAI-ARIA Authoring Practices, and a card is structure rather than a widget. The applicable guidance is Structural Roles: use the HTML element that already carries the meaning.
- The root is a div with no role. Use render to make it an article with its own heading, a section, the li of a list of results, or the label of a chooser — whichever the page actually means.
- The card contributes no keyboard behavior. CardLink is an anchor, so Enter, the context menu and middle-click are the platform’s.
- CardLink is named by its own text. A card whose root were the link would take every string inside it into that name, which is the reason the hit area is stretched from the link instead.
- A card carries at most one CardLink, and it navigates. A whole surface that fires a command on any click, with no visible control boundary, is a misclick nobody can undo; put a button in CardActions or the footer instead.
- CardActions and CardFooter both sit above the stretched hit area, so a control in either stays operable. An interactive element anywhere else needs position: relative of its own.
- Text over the stretched area cannot be selected with the pointer. That is the cost of the whole-card target, and the reason a card with no CardLink stretches nothing.
- selected and disabled are painted, never announced. The radio, checkbox or button inside the card is what carries the state for assistive technology.
- selected is the accent surface under a hairline accent edge, the pair a selected row paints. In high contrast and forced colors both flatten, and the checked control inside is what carries the state. elevated keeps its hairline because a shadow is removed there outright.
- The focus ring is drawn on the card while the link has focus. In a browser without :has() the link keeps its own native outline instead.
- A rule between two regions is a Divider written between them. It is announced as a separator unless it is marked decorative, which is usually what a rule inside one card is.
API
card
Props
bleedbooleanDefaultfalse- On CardBodyRuns the children of the body from one edge of the card to the other. The body gives up its padding and is clipped to the corners of the card it touches. Use it for a list whose rules and row grounds reach the edge.
orientation'vertical' | 'horizontal'Defaultvertical- Puts the media beside the regions, and returns it to the top in a narrow container.
fill'outline' | 'elevated' | 'subtle'Defaultoutline- Sets how the surface is bounded: a hairline edge, the edge plus a lift, or a filled ground.
size'sm' | 'md' | 'lg'Defaultmd- Sets the inset of the card itself. Density is the application's choice; this inset is the card's.
selectedbooleanDefaultfalse- Mirrors a selection that your page owns. The control inside the card is what announces it.
disabledbooleanDefaultfalse- Mirrors a control that your page has disabled. The card disables nothing itself.
render(props) => ReactNode- On Card, CardMedia, CardHeader, CardActions, CardSelection, CardBody, CardFooter, CardLinkRenders the part into another element from the props it receives.
refRef<HTMLElement>- On every partReaches the native element. Each part extends the props of its own element.
hrefstring- On CardLinkSets the destination of the card, on the anchor whose hit area covers the surface.
CardDefaultsProvider{ fill, orientation, size }- On a subtreeSets the defaults once for every card under it. An explicit prop still wins.
Theming
Each token is a CSS custom property: set it in a theme, or on any element to retune every card inside it.
Card tokens
| Token | Default |
|---|---|
--slotted-card-actions-gap | var(--slotted-action-gap, 8px) |
--slotted-card-background | var(--slotted-surface-raised, Canvas) |
--slotted-card-background-disabled | var(--slotted-surface-sunken, Canvas) |
--slotted-card-background-selected | var(--slotted-tone-accent-surface, Canvas) |
--slotted-card-background-selected-active | var(--slotted-tone-accent-subtle-active, Canvas) |
--slotted-card-background-selected-hover | var(--slotted-tone-accent-subtle-hover, Canvas) |
--slotted-card-background-subtle | var(--slotted-surface-sunken, Canvas) |
--slotted-card-border-color | var(--slotted-border-subtle, ButtonBorder) |
--slotted-card-border-color-disabled | var(--slotted-disabled-border, GrayText) |
--slotted-card-border-color-hover | var(--slotted-border-strong, ButtonBorder) |
--slotted-card-border-width | var(--slotted-border-width-thin, 1px) |
--slotted-card-color | var(--slotted-text, CanvasText) |
--slotted-card-color-disabled | var(--slotted-disabled-foreground, GrayText) |
--slotted-card-edge-color-selected | var(--slotted-tone-accent-border, CanvasText) |
--slotted-card-edge-width-selected | var(--slotted-border-width-thin, 1px) |
--slotted-card-footer-gap | var(--slotted-action-gap, 8px) |
--slotted-card-header-column-gap | var(--slotted-space-5, 0.75rem) |
--slotted-card-header-gap | var(--slotted-space-2, 0.25rem) |
--slotted-card-media-size | minmax(0, 1fr) |
--slotted-card-padding-block | var(--slotted-space-6, 1rem) |
--slotted-card-padding-block-lg | var(--slotted-space-8, 1.5rem) |
--slotted-card-padding-block-sm | var(--slotted-space-5, 0.75rem) |
--slotted-card-padding-inline | var(--slotted-space-6, 1rem) |
--slotted-card-padding-inline-lg | var(--slotted-space-8, 1.5rem) |
--slotted-card-padding-inline-sm | var(--slotted-space-5, 0.75rem) |
--slotted-card-radius | var(--slotted-radius-lg, 8px) |
--slotted-card-region-gap | var(--slotted-space-3, 0.375rem) |
--slotted-card-region-gap-lg | var(--slotted-space-4, 0.5rem) |
--slotted-card-region-gap-sm | var(--slotted-space-2, 0.25rem) |
--slotted-card-selection-line | calc(var(--slotted-font-size-lg, 1rem) * var(--slotted-line-height-lg, 1.5)) |
--slotted-card-selection-size | var(--slotted-selection-size-md, 16px) |
--slotted-card-shadow | none |
--slotted-card-shadow-hover | var(--slotted-shadow-xs) |
Theme tokens it reads
| Token | Default |
|---|---|
--slotted-action-gap | comfortable 8px · compact 6px · dense 4px |
--slotted-border-strong | Set per scheme by the theme |
--slotted-border-subtle | Set per scheme by the theme |
--slotted-border-width-thin | 1px |
--slotted-disabled-background | Set per scheme by the theme |
--slotted-disabled-border | Set per scheme by the theme |
--slotted-disabled-foreground | Set per scheme by the theme |
--slotted-duration-short | 120ms |
--slotted-easing-standard | cubic-bezier(0.2, 0, 0, 1) |
--slotted-focus-ring-color | Set per scheme by the theme |
--slotted-focus-ring-offset | var(--slotted-border-width-thick) |
--slotted-focus-ring-width | var(--slotted-border-width-thick) |
--slotted-font-size-lg | 1rem |
--slotted-line-height-lg | 1.5 |
--slotted-radius-lg | 8px |
--slotted-selection-size-md | 16px |
--slotted-shadow-lg | Set per scheme by the theme |
--slotted-shadow-md | Set per scheme by the theme |
--slotted-shadow-sm | Set per scheme by the theme |
--slotted-shadow-xs | Set per scheme by the theme |
--slotted-space-2 | 0.25rem |
--slotted-space-3 | 0.375rem |
--slotted-space-4 | 0.5rem |
--slotted-space-5 | 0.75rem |
--slotted-space-6 | 1rem |
--slotted-space-8 | 1.5rem |
--slotted-surface-raised | Set per scheme by the theme |
--slotted-surface-sunken | Set per scheme by the theme |
--slotted-text | Set per scheme by the theme |
--slotted-tone-accent-border | Set per scheme by the theme |
--slotted-tone-accent-subtle-active | Set per scheme by the theme |
--slotted-tone-accent-subtle-hover | Set per scheme by the theme |
--slotted-tone-accent-surface | Set per scheme by the theme |
--slotted-tone-secondary-subtle-active | Set per scheme by the theme |