Card
A generic hand-drawn surface container for grouping related content.
Overview
A Card is a generic surface for grouping related content — it isn’t interactive by itself and
carries no built-in meaning beyond “these things belong together.” On the web it can also be a
single link: see Link cards.
Anatomy
A sketchy rectangle outline drawn behind plain children. On Web Components, gh-card has two
slots: a named title slot rendered first, and the default slot for the body. Content in the
title slot, and any <h1>/<h2>/<h3> in the default slot, gets title styling (::slotted
CSS). React and React Native have no equivalent title slot — content is just plain children.
Variants & States
Unlike Button and Input, Card is mostly a static container — this section is intentionally thin rather than force-fitting states that don’t exist.
| State | Status | Notes |
|---|---|---|
| Hover | Implemented | With interactive or as a link card (React, Web Components): the card lifts, and a link card's plain stroke darkens. Not on React Native. |
| Focus | Implemented | A link card, or a card you make focusable with tabindex (interactive or not), is focusable and shows the comp.card.focus.ring ring on its paper on keyboard focus, following the folded corner and tilt, instead of the browser default. With interactive, a card also lifts while focus is inside (React, Web Components). |
| Disabled | Not implemented | — |
| Loading | Not implemented | — |
| Error | Not implemented | — |
The one real variation is a different prop per platform, not a shared state: React’s fill
('solid' | 'hachure') controls the fill pattern; Web Components and React Native instead expose
elevated (a boolean drop-shadow effect) — a genuinely different API, not a superset of React’s.
Paper variants
variant switches the surface to a paper look. plain is the default sketch outline; sticky is a
sticky note and lined is ruled paper. tone picks the paper colour, fastener adds a piece of
tape or a pin, and tilt rotates the card slightly. Tape and pin are decorative and hidden from
assistive technology.
React@ghds/react
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'plain' | 'sticky' | 'lined' | 'plain' | Surface style. |
tone | 'neutral' | 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'neutral' | Paper colour of sticky, and the pin colour on every variant. |
fastener | 'none' | 'tape' | 'pin' | 'none' | Decorative tape or pin. Renders on every variant. |
tilt | 'none' | 'left' | 'right' | 'none' | Rotates the card. No effect on plain. |
interactive | boolean | false | Lifts on hover and on focus within. Plain cards lift with transform only. No animation under reduced motion. |
Web Components@ghds/web-components
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'plain' | 'sticky' | 'lined' | 'plain' | Surface style (reflected attribute). |
tone | 'neutral' | 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'neutral' | Paper colour of sticky, and the pin colour on every variant. |
fastener | 'none' | 'tape' | 'pin' | 'none' | Decorative tape or pin. Renders on every variant. |
tilt | 'none' | 'left' | 'right' | 'none' | Rotates the card. No effect on plain. |
interactive | boolean | false | Lifts on hover and on focus within. Plain cards lift with transform only. No animation under reduced motion. |
React Native@ghds/react-native
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'plain' | 'sticky' | 'lined' | 'plain' | Surface style. |
tone | 'neutral' | 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'neutral' | Paper colour of sticky, and the pin colour on every variant. |
fastener | 'none' | 'tape' | 'pin' | 'none' | Decorative tape or pin. Renders on every variant. |
tilt | 'none' | 'left' | 'right' | 'none' | Rotates the card. No effect on plain. |
- React Native has no
interactiveor link mode yet. - A card with
tabindex="0"(tabIndex={0}in React) shows thecomp.card.focus.ringoutline on keyboard focus. The ring is drawn on the card’s paper, so it follows the folded corner and the tilt. Withoutinteractiveit shows the ring but does not lift. - Tape is tinted with
sys.color.paper.tape(amber masking tape) atcomp.card.fastener.tape.opacity, so it stays visible on light and dark pages and on every paper colour. - React’s
filland Web Components/React Native’selevatedapply toplainonly. - React Native reads the values from the Restyle theme (
theme.card.*), so a custom theme overrides them.
// React
<Card variant="sticky" tone="warning" fastener="tape" tilt="left">
<h3>Reminder</h3>
<p>Water the plants.</p>
</Card>
Customizing paper colours
On the web every value is a CSS custom property. Set it on a container that wraps the cards to
change the paper inside it. Don’t set it on :root: the dark theme redeclares every
--comp-card-* property (on [data-theme] and, in OS dark mode, on :root:not([data-theme])), so
the override is lost there. For the same reason, keep the container inside any element that carries
data-theme.
.notes {
--comp-card-sticky-bg-warning: var(--sys-color-paper-info);
}
Lined cards
The rule gap equals the body line box, so body text sits on the rules. This holds for body text
only: headings and element margins (such as the default <p> margins) shift the lines below them
off the rules. Fill a lined card with body text without extra margins, and don’t change its
line-height.
Link cards
To make the whole card one link, use href on Web Components or asChild with an <a> child on
React (the same pattern as Button’s asChild). The link is the card surface itself, so there is no
wrapper element.
- On mouse hover the card lifts like
interactive, and aplaincard’s sketch stroke darkens (comp.card.stroke.hover). - On keyboard focus the card shows a focus ring (
comp.card.focus.ring) and lifts. - Paper variants,
tone,fastenerandtiltwork as usual.
React@ghds/react
| Prop | Type | Default | Description |
|---|---|---|---|
asChild | boolean | false | Renders the single child element (for example an <a>) as the card root. The card is then interactive: mouse hover and keyboard focus lift it, and keyboard focus shows a focus ring. A mouse click that focuses the link does not lift it. |
Web Components@ghds/web-components
| Prop | Type | Default | Description |
|---|---|---|---|
href | string | — | When non-empty, the surface renders as <a class="content" part="content"> covering the whole card. |
target | string | — | Anchor target. Used only with href. |
rel | string | — | Anchor rel. Used only with href. Pair target="_blank" with rel="noopener". |
// React
<Card asChild variant="sticky" tone="info">
<a href="/docs/tokens">
<h3>Tokens</h3>
<p>Design values for every platform.</p>
</a>
</Card>
<!-- Web Components -->
<gh-card href="/docs/tokens" variant="sticky" tone="info">
<h3 slot="title">Tokens</h3>
<p>Design values for every platform.</p>
</gh-card>
href renders the anchor inside the shadow root, so it exists only after the element upgrades in
the browser. When the link must be in the static HTML before JavaScript runs (crawlers, no-JS
visitors), wrap the card content in a light-DOM <a href> instead. When the anchor is the card’s
only child, the card moves its padding onto the anchor so the whole card is clickable, draws the
focus ring on the paper while the anchor has keyboard focus, and renders no shadow anchor (anchors
never nest, even with href). Like an href card and React Card asChild, it is interactive by
nature: it lifts and its stroke darkens on hover, and it lifts on keyboard focus. Any other element child, including a slot="title" heading, turns link
mode off, so put the heading inside the anchor. Headings inside the anchor are not slotted
headings, so style them yourself. A label on the card becomes the anchor’s aria-label, unless
the anchor already has its own.
<!-- Web Components — light-DOM link -->
<gh-card variant="sticky" tone="info">
<a href="/docs/tokens">
<h3>Tokens</h3>
<p>Design values for every platform.</p>
</a>
</gh-card>
Don’t put buttons, inputs or other links inside a link card: interactive elements can’t be nested inside a link. The card’s text content becomes the link’s accessible name, so keep it short.
Usage
Do
- Supply your own role/aria-label (React) or label (WC/RN) when the card functions as a landmark or region.
- Use Card for visual grouping (a settings panel, a list item) rather than as a substitute for semantic HTML.
Don't
- Don't expect a role or accessible name automatically on React — the caller is fully responsible for it there.
- Don't rely on fill and elevated meaning the same thing across platforms — they're different props with different visual effects.
Accessibility
- React: renders a plain
<div>. No role or label is set automatically — “any ARIA role/ landmark is the caller’s to set” (per the component’s own doc comment). WithasChild, the child keeps its own semantics (for example a link). - Web Components: when a
labelis supplied,gh-cardautomatically setsinternals.role = 'group'andinternals.ariaLabel— a real behavior React does not replicate. Withhref, the host has no role: the inner<a>is the link, andlabelbecomes itsaria-label, replacing the text content as the accessible name. A light-DOM link card works the same way:labelis set as the slotted anchor’saria-label, unless the anchor has its own. - React Native: sets
accessibilityRole="summary"only whenaccessibilityLabelis passed. - See the Accessibility Guide for general conventions.
Content
N/A — Card has no fixed content model. Content is whatever the caller passes as children (React/RN) or slots (Web Components).
Props API
React@ghds/react
| Prop | Type | Default | Description |
|---|---|---|---|
fill | 'solid' | 'hachure' | 'solid' | Fill style of the card body. |
asChild | boolean | false | Renders the single child element as the card root. See Link cards. |
...rest | HTMLAttributes<HTMLDivElement> | — | Native <div> attributes (e.g. role, aria-label) pass through. |
Web Components@ghds/web-components
| Prop | Type | Default | Description |
|---|---|---|---|
elevated | boolean | false | Renders a sketch drop-shadow outline. No fill prop exists. |
label | string | — | When set, exposes the card as an ARIA group with this label. On a link card, it labels the link instead. |
href | string | — | Renders the whole card as a link. See Link cards. |
target / rel | string | — | Anchor target and rel, used only with href. |
React Native@ghds/react-native
| Prop | Type | Default | Description |
|---|---|---|---|
elevated | boolean | false | Same effect as Web Components. No fill prop. |
accessibilityLabel | string | — | When set, accessibilityRole becomes "summary". |
testID | string | — | Test handle for queries. |
Code examples
// React — @ghds/react (has `fill`, no `elevated`)
import { Card } from '@ghds/react/card';
<Card fill="hachure">
<h3>Hachure</h3>
<p>Sketched, translucent fill.</p>
</Card>;
<!-- Web Components — @ghds/web-components (has `elevated` + `label`, no `fill`) -->
<script type="module">
import '@ghds/web-components/card';
</script>
<gh-card label="Elevated" elevated>
<h3 slot="title">Elevated</h3>
<p>Drop-shadow sketch outline suggests elevation.</p>
</gh-card>
// React Native — @ghds/react-native (has `elevated`, no `fill`)
import { Card } from '@ghds/react-native/card';
import { Text } from '@ghds/react-native/theme';
<Card elevated accessibilityLabel="Summary">
<Text>Elevated card content</Text>
</Card>;
Live Demo
React uses fill; Web Components uses elevated + label — the demo below deliberately shows
each platform’s actual prop, not a unified example.
React @ghds/react
Web Components @ghds/web-components
Flat
Default sketch outline, no elevation.
Drop-shadow sketch outline suggests elevation.
Sticky note with tape.
Ruled paper with a pin.
Link card
The whole card is one link. Hover or tab to it.