Skip to content

Card

A container for related content in three forms: static, pressable or a link.

import { Card } from '@windmorph/react';

Props

By name or description, across the 13 props below

Card 13 props

  • hreftype string

    Renders a link. Navigation goes through React Aria's RouterProvider when one is set.

  • disabledtype booleandefault false

    Disables the element: it can't be pressed or focused, and shows the disabled style.

  • varianttype "filled" | "elevated" | "outlined"default "filled"

    The M3 style: filled, elevated or outlined.

  • draggedtype booleandefault false

    The card is being dragged (picked up to move it): M3 raises it (filled and outlined to level 3, elevated to 4) and, on an interactive card, shows the dragged state layer. Set it from your drag and drop code; it sets data-dragged.

  • childrentype ReactNode

    The card's content: its media, headline, text and actions.

  • reftype Ref<HTMLDivElement> | Ref<HTMLAnchorElement>

    Ref to the root element: the <div>, or the <a> with href.

Events

  • onPresstype ((e: PressEvent) => void)

    Handler that is called when the press is released over the target.

Also accepts every <a> attribute.

Tokens

M3's component tokens as CSS variables. Each is unset until you set it, on :root, a theme or any ancestor, and falls back to the default shown. The root carries data-variant (and data-size where it has sizes), which picks the variables that apply. See Component tokens in the Customisation guide.

Card tokens (md-comp-card)
VariableDefaultPaintsCompose
Filled (variant)
--md-comp-filled-card-container-colorvar(--md-sys-color-surface-container-highest)The container.FilledCardTokens.ContainerColor
--md-comp-filled-card-container-shapevar(--md-sys-shape-corner-medium)The corners.FilledCardTokens.ContainerShape
Elevated (variant)
--md-comp-elevated-card-container-colorvar(--md-sys-color-surface-container-low)The container.ElevatedCardTokens.ContainerColor
--md-comp-elevated-card-container-shapevar(--md-sys-shape-corner-medium)The corners.ElevatedCardTokens.ContainerShape
--md-comp-elevated-card-container-elevationvar(--md-sys-elevation-level-1)The shadow at rest.ElevatedCardTokens.ContainerElevation
Outlined (variant)
--md-comp-outlined-card-container-colorvar(--md-sys-color-surface)The container.OutlinedCardTokens.ContainerColor
--md-comp-outlined-card-container-shapevar(--md-sys-shape-corner-medium)The corners.OutlinedCardTokens.ContainerShape
--md-comp-outlined-card-outline-colorvar(--md-sys-color-outline-variant)The 1px border.OutlinedCardTokens.OutlineColor

Spec status

Built to the M3 Expressive card spec. Each item of its variants and configurations links to a live example; where the M3 Expressive column of the spec differs from the original M3 one, it wins.

  • Elevated card

    Built

    Variant · Variants

  • Filled card

    Built

    Variant · Variants

  • Outlined card

    Built

    Variant · Variants

  • Media, headline, supporting text and actions

    Built

    Use case · Content

  • Pressable and link cards

    Built

    Use case · Interactive

  • Clipped content

    Extension

    Cards clip their content to the 12px corners, as Compose does, so media gets rounded edges; overflow-visible turns it off.

  • Anatomy parts

    Not built

    No headline, media or actions sub-components: Compose ships none either, and layout utilities compose them.

Bundle size

Gzipped, as published: the component and the library code it imports. React, React Aria, Motion and the other dependencies aren't counted, and your bundler's minifier makes it smaller still. CI fails a change that grows it past its budget.

  • Card: 12.8 kB

M3 Expressive specs

Shape
rounded-corner-medium
Variants
filled, elevated, outlined

Spec values

  • Filled is surface-container-highest, elevated is surface-container-low at level 1, outlined is surface with a 1px outline. All have 12px corners and on-surface content.
  • Interactive cards rise one level on hover (filled and outlined 0→1, elevated 1→2) and drop back while pressed or keyboard-focused; a focused outlined card's border turns on-surface.
  • Set dragged while a card is being moved: it rises to level 3 (elevated to 4), as M3 asks when picking up a card.
  • Disabled cards keep a faded container, as M3's disabled tokens ask: filled is surface-variant and elevated surface, each at 38% over the card's own colour, and the outlined border is outline at 12%. Content is on-surface at 38%.
  • Content is clipped to the corners (overflow-hidden), so media gets rounded edges; add overflow-visible to turn that off.
  • There are no anatomy sub-components (headline, media, actions) yet; layout utilities cover them.