Skip to content
Cynosurev0.5.0
SearchStorybookGitHubnpmColour mode: System. Switch to Light

Components / Structure

Card

A content container. Give it href or onClick and the whole card becomes one link or one button. For a plain grouping with no surface, use Stack.

Variants and tones

When to useLink to "When to use"

  • surface (default): a raised panel for settings sections, dashboard tiles, plan options.
  • outline: border only, for lower emphasis or crowded layouts.
  • soft: a tone-tinted fill to highlight a state (info, warning).
  • href / onClick: the whole card is one target, such as a plan picker or a list of destinations.

Use something else when:

  • the card holds its own buttons, links or inputs: use a static Card (no href/onClick) and put those controls inside
  • you only need spacing between items: Stack or Inline

UsageLink to "Usage"

tsx
Copy
import { Card } from "@arshad-shah/cynosure";

<Card variant="outline" padding="lg" as="section">…</Card>
<Card href="/settings">Whole card is one link</Card>
<Card onClick={choose}>Whole card is one button</Card>
<Card variant="soft" tone="info">Heads up</Card>
<Card edge="success">Water the garden <Badge tone="success">Home</Badge></Card>
<Card as="section" title="Connection" description="Where the client connects.">…</Card>

Title and descriptionLink to "Title and description"

title and description put a header above the content; headingLevel (default 3) fits the title into the page outline. In a static or link card the title is a heading, and a section, article or aside card is named by it. A button may not hold a heading, so in a button card the title is plain text that still names the button.

Title and description head the card

With actions the header shares its row with them: the title wraps before the actions instead of running under them, on static cards and on link and button cards, where the actions stay outside the card's one target.

Header shares its row with the actions

PaddingLink to "Padding"

padding is none, sm, md (default) or lg, and uses space tokens.

Padding uses space tokens

Coloured edgeLink to "Coloured edge"

edge draws a coloured edge on the card's inline-start side: the left in left-to-right text, the right in right-to-left. A tone name (accent, neutral, danger, success, warning, info) uses that tone's colour. Any other string is a CSS colour, for categories with their own colours.

Edge shows atone or any colour

The edge is the card's own start border, so it follows the card's radius, and the content starts after it. It works with every variant and tone, on link and button cards and with actions, and it keeps its colour when the card is hovered or focused.

Colour must not be the only carrier of meaning. Some people cannot tell the colours apart and a screen reader does not announce them. Say the same thing in the card's text or with a Badge, as the cards above do.

Edge follows reading direction and its width token

Interactive cardsLink to "Interactive cards"

With href the card renders as a link; unsafe URL schemes are not linked. With onClick it renders as a button and supports disabled. Keep the content non-interactive: one card, one target. When a card is interactive, as is ignored.

PropsLink to "Props"

Every prop of Card
PropWhat it doesTypeDefault
variant
surface raised panel, outline border only, soft tone-tinted fill."soft" | "outline" | "surface"
padding
Space between the card's edge and its content. Default "md"."sm" | "md" | "lg" | "none""md"
tone
Semantic colour. Default "neutral".Tone"neutral"
edge
A coloured edge on the card's inline-start side (left in left-to-right text), e.g. a task's category. A tone name uses that tone's colour; any other string is a CSS colour. Colour alone carries no meaning for many people: say the same thing in the card's text or a Badge. Default: no edge.Edgeno edge
title
A heading at the top of the card, above the content, beside the actions. In a static or link card it is a heading (headingLevel); in a button card it is plain text, as a button may not hold a heading. A section, article or aside card is named by it.ReactNode
description
A quieter line under the title.ReactNode
headingLevel
Heading level of the title, to fit the page outline. Default 3.2 | 3 | 4 | 5 | 6 | 13
as
Element for a static card. Ignored when href or onClick makes the whole card interactive."div" | "section" | "article" | "li" | "aside"
href
Makes the whole card a link (rendered through LinkBase, so unsafe schemes are not linked).string
target
With href: where it opens, e.g. _blank.string
onClick
Makes the whole card a button.MouseEventHandler<HTMLElement>
disabled
With onClick (and no href): the card cannot be pressed.boolean
actions
Buttons that sit on the card but act on their own (a game card's 2-player mode, a file card's menu). They are placed over the card's top end, outside its one link or button, so nothing interactive is nested.ReactNode
className
Added to the card element, for layout.string
style
Layout only.CSSProperties
children
The card's content. Keep it non-interactive when the card is a link or a button.ReactNode
aria-label
Accessible name of the card, set on the card element.string
aria-current
Marks a link or button card as the current one of a set: "page" for the page being shown (a card grid of sections), or "step", "location", true. Read by screen readers, and the card's border takes the accent.boolean | "false" | "true" | "page" | "step" | "location" | "date" | "time"
data-testid
Set on the card element, to find it in tests.string

Generated from the type definitions in @arshad-shah/cynosure 0.5.0.

Behaviour and accessibilityLink to "Behaviour and accessibility"

Behaviour and accessibility, table 1
InputResult
Click, EnterFollows the link (href) or fires onClick
SpaceFires onClick on a button card
TabMoves focus to an interactive card
  • Static cards: choose the element with as (div, section, article, li, aside).
  • Names: a section, article or aside card with a title is named by it. Otherwise add aria-label when the card's content doesn't give a clear name.
  • Ref: the ref points at the rendered element.
  • Edge: edge is visual only and adds no element or name. In forced colours it stays as a thicker edge in the system text colour.

ThemingLink to "Theming"

Tokens: --cy-card-bg, --cy-card-border, --cy-card-radius, --cy-card-shadow and --cy-card-soft-mix.

Theming, table 2
TokenControls
--cy-card-edge-widthThickness of the edge. Default --cy-space-2.
--cy-card-title-sizeFont size of the title. Default --cy-font-size-lg.
ts
Copy
createTheme({ components: { card: { radius: "12px", shadow: "none", edgeWidth: "6px" } } });

className and style are for layout only.

Badge · Stack · Inline · Link · Button

These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.

Getting started
Theming
Icons
Accessibility
Code editors and highlighters
Using Cynosure without React
Build-tool adapters
Components
Accordion
AppShell
AspectRatio
Breadcrumbs
Calendar
Card
Container
Disclosure
Divider
DocumentViewport
Grid
Inline
PageHeader
PanZoomCanvas
ScrollArea
SideNav
SortableList
SplitPane
Stack
StatusBar
Tabs
TitleBar
Toolbar
Tree
VirtualList
ZoomControls
Announcer
Avatar
Badge
CodeBlock
DescriptionList
EmptyState
ErrorBoundary
Field
Heading
IconTile
Image
Kbd
List
LoadingDots
Notice
ProgressBar
Prose
Skeleton
Stat
Steps
Table
Text
Button
Checkbox
Checklist
ColorField
ColorSwatches
Combobox
CompareSlider
CopyButton
DateField
FileDrop
IconButton
KeyValueEditor
Link
NumberField
Pagination
PathField
RadioGroup
SearchField
SegmentedControl
Select
SelectionFrame
SignaturePad
Slider
Switch
TagInput
TextArea
TextField
ThemeToggle
TimeField
ButtonBase
ChoiceBase
DialogBase
FileInputBase
HiddenValue
Icon
InputBase
LinkBase
LiveRegion
TextAreaBase
ChatMessage
Choice
DataGrid
DeviceFrame
HighlightedText
HotkeyField
ListRow
OptionList
OverlayFrame
QRCode
RowActions
Section
SiteFooter
SiteHeader
SkipLink
SortButton
VisuallyHidden
CommandPalette
ContextMenu
Dialog
FloatingToolbar
HoverCard
Menu
Menubar
Popover
ProgressOverlay
Sheet
Toast
Tooltip
Changelog