Skip to content
Slotted

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 2019
Delivers pallets of cartons to Rotterdam every Tuesday and Friday.

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.

bash
pnpm add @slotted/react @slotted/theme @slotted/themes

Fill

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: outline
14 orders, 3 awaiting approval.

Invoices due this week

fill: elevated
6 invoices totaling $18,240.

Reorder alerts

fill: subtle
9 products below their reorder point.

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: sm
$4,820.00, due 15 December.
Meridian Packaging

Invoice 20418

size: md
$4,820.00, due 15 December.
Meridian Packaging

Invoice 20418

size: lg
$4,820.00, due 15 December.
Meridian Packaging

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 Packaging
Overdue
$4,820.00 was due on 15 November. A late fee of 1.5% applies from 1 December.

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 capacity

8,420 of 10,000 pallet positions are in use.

Counted on 24 November at 06:00.

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 warehouses
14 purchase orders are open, and the next delivery arrives on Tuesday.

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, Q4
Pallet positions in use rose from 71% to 84% between October and November.

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

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.

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.

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, lg
312 orders left the Reno warehouse today.

Returns received

outline, sm
18 returns arrived and 11 are restocked.

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

bleedbooleanDefault false
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'Default vertical
Puts the media beside the regions, and returns it to the top in a narrow container.
fill'outline' | 'elevated' | 'subtle'Default outline
Sets how the surface is bounded: a hairline edge, the edge plus a lift, or a filled ground.
size'sm' | 'md' | 'lg'Default md
Sets the inset of the card itself. Density is the application's choice; this inset is the card's.
selectedbooleanDefault false
Mirrors a selection that your page owns. The control inside the card is what announces it.
disabledbooleanDefault false
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

TokenDefault
--slotted-card-actions-gapvar(--slotted-action-gap, 8px)
--slotted-card-backgroundvar(--slotted-surface-raised, Canvas)
--slotted-card-background-disabledvar(--slotted-surface-sunken, Canvas)
--slotted-card-background-selectedvar(--slotted-tone-accent-surface, Canvas)
--slotted-card-background-selected-activevar(--slotted-tone-accent-subtle-active, Canvas)
--slotted-card-background-selected-hovervar(--slotted-tone-accent-subtle-hover, Canvas)
--slotted-card-background-subtlevar(--slotted-surface-sunken, Canvas)
--slotted-card-border-colorvar(--slotted-border-subtle, ButtonBorder)
--slotted-card-border-color-disabledvar(--slotted-disabled-border, GrayText)
--slotted-card-border-color-hovervar(--slotted-border-strong, ButtonBorder)
--slotted-card-border-widthvar(--slotted-border-width-thin, 1px)
--slotted-card-colorvar(--slotted-text, CanvasText)
--slotted-card-color-disabledvar(--slotted-disabled-foreground, GrayText)
--slotted-card-edge-color-selectedvar(--slotted-tone-accent-border, CanvasText)
--slotted-card-edge-width-selectedvar(--slotted-border-width-thin, 1px)
--slotted-card-footer-gapvar(--slotted-action-gap, 8px)
--slotted-card-header-column-gapvar(--slotted-space-5, 0.75rem)
--slotted-card-header-gapvar(--slotted-space-2, 0.25rem)
--slotted-card-media-sizeminmax(0, 1fr)
--slotted-card-padding-blockvar(--slotted-space-6, 1rem)
--slotted-card-padding-block-lgvar(--slotted-space-8, 1.5rem)
--slotted-card-padding-block-smvar(--slotted-space-5, 0.75rem)
--slotted-card-padding-inlinevar(--slotted-space-6, 1rem)
--slotted-card-padding-inline-lgvar(--slotted-space-8, 1.5rem)
--slotted-card-padding-inline-smvar(--slotted-space-5, 0.75rem)
--slotted-card-radiusvar(--slotted-radius-lg, 8px)
--slotted-card-region-gapvar(--slotted-space-3, 0.375rem)
--slotted-card-region-gap-lgvar(--slotted-space-4, 0.5rem)
--slotted-card-region-gap-smvar(--slotted-space-2, 0.25rem)
--slotted-card-selection-linecalc(var(--slotted-font-size-lg, 1rem) * var(--slotted-line-height-lg, 1.5))
--slotted-card-selection-sizevar(--slotted-selection-size-md, 16px)
--slotted-card-shadownone
--slotted-card-shadow-hovervar(--slotted-shadow-xs)

Theme tokens it reads

TokenDefault
--slotted-action-gapcomfortable 8px · compact 6px · dense 4px
--slotted-border-strongSet per scheme by the theme
--slotted-border-subtleSet per scheme by the theme
--slotted-border-width-thin1px
--slotted-disabled-backgroundSet per scheme by the theme
--slotted-disabled-borderSet per scheme by the theme
--slotted-disabled-foregroundSet per scheme by the theme
--slotted-duration-short120ms
--slotted-easing-standardcubic-bezier(0.2, 0, 0, 1)
--slotted-focus-ring-colorSet per scheme by the theme
--slotted-focus-ring-offsetvar(--slotted-border-width-thick)
--slotted-focus-ring-widthvar(--slotted-border-width-thick)
--slotted-font-size-lg1rem
--slotted-line-height-lg1.5
--slotted-radius-lg8px
--slotted-selection-size-md16px
--slotted-shadow-lgSet per scheme by the theme
--slotted-shadow-mdSet per scheme by the theme
--slotted-shadow-smSet per scheme by the theme
--slotted-shadow-xsSet per scheme by the theme
--slotted-space-20.25rem
--slotted-space-30.375rem
--slotted-space-40.5rem
--slotted-space-50.75rem
--slotted-space-61rem
--slotted-space-81.5rem
--slotted-surface-raisedSet per scheme by the theme
--slotted-surface-sunkenSet per scheme by the theme
--slotted-textSet per scheme by the theme
--slotted-tone-accent-borderSet per scheme by the theme
--slotted-tone-accent-subtle-activeSet per scheme by the theme
--slotted-tone-accent-subtle-hoverSet per scheme by the theme
--slotted-tone-accent-surfaceSet per scheme by the theme
--slotted-tone-secondary-subtle-activeSet per scheme by the theme