Button
The reference implementation of the GHDS component documentation standard.
This page is the reference implementation of the GHDS component documentation standard — every future component page (Card, Input, and everything in M10/M11) follows the same eight sections in the same order.
Overview
A Button triggers a single, immediate, user-initiated action — submitting a form, confirming a
choice, opening something. Use a link instead when the destination is navigation, not an action —
in React wrap an <a> with asChild; on Web Components set href on <gh-button> to render a
real <a href> with the same button styling.
Anatomy
A real <button> (or a Radix Slot-rendered element via asChild in React, or a real <a href>
when href is set on <gh-button>) carries all native keyboard and click semantics. A hand-drawn
SketchSurface outline sits behind the label, purely decorative (aria-hidden="true",
focusable="false", with an SVG <title> for tooling) — it never carries meaning, so removing it
never changes what the button does or how it’s announced.
Variants & States
Exactly three variants exist: primary, danger, neutral — there is no secondary, ghost, or
link variant.
| State | Status | Notes |
|---|---|---|
| Default | Implemented | — |
| Hover | Implemented | Fill/text color shifts per variant. |
| Active / pressed | Implemented | — |
| Focus | Implemented | A manual focus ring (comp.button.focus.ring), not native :focus-visible. |
| Disabled | Implemented | — |
| Loading | Not implemented | — |
| Error | Not implemented | — |
Usage
Do
- Use danger only for destructive or irreversible actions.
- Use asChild (React) or href (Web Components) to keep link semantics when a button needs to look like a button but navigate.
- Keep one primary button per view — it should be obvious what the main action is.
Don't
- Don't rely on color alone to convey a danger action — the label should say what happens.
- Don't disable a button without explaining why somewhere else on screen.
- Don't nest an <a> inside a native <button> — use asChild (React) or href (Web Components) instead.
Accessibility
- Native
<button>keyboard behavior (Space/Enter activates, native tab order) comes for free — no customonKeyDownortabIndexexists in the implementation. - Disabling is not uniform across the render paths: the native
<button disabled>path removes the element from the tab order entirely (the browser’s native behavior), while theasChildpath setsaria-disabled="true"and cancels clicks, middle-clicks, and keyboard Enter before any of the child’s click handlers run — but it stays in the tab order so assistive technology can still discover it. The link keeps itshref, so it can still be opened from the context menu, dragged, or followed by crawlers; drophreffrom the child while disabled if it must not be followable at all. - On Web Components,
disabledalways wins overhref: a disabled<gh-button href>renders a disabled<button>, never a navigable<a>. An enabled<gh-button href>takes its link role from the inner<a>(no hostrole="button"), so it is announced as a link, can be opened in a new tab, and is followed with Enter (not Space). - When a
<gh-button>’s only child is an<a href>, that light-DOM anchor is the link: it is in the static HTML before JavaScript runs, and the component renders no inner<button>or<a>(anchors never nest, even withhrefset). A light-DOM link cannot be removed bydisabled, so, like ReactasChild, a disabled button marks itaria-disabled="true"and cancels clicks, middle-clicks, and Enter until it is enabled again, but leaves it in the tab order so assistive technology can still discover it. That cancellation needs the component to have upgraded: before JavaScript runs (or with JavaScript disabled) the anchor keeps itshrefand navigates normally, so leavehrefoff the anchor in the HTML if it must never be followable. Put ARIA for a light-DOM link on the anchor itself. <gh-button>has no role of its own; the inner<button>/<a>is the one control. ARIA set on the host is forwarded to it:aria-label,aria-expanded,aria-pressed,aria-haspopup, andaria-currentas attributes, andaria-controls,aria-describedby, andaria-labelledbyas element references (in browsers with ARIA element reflection). Other host ARIA is not exposed.- See the Accessibility Guide for the general keyboard and ARIA conventions shared across all components.
Content
Labels are short verb phrases — “Delete”, “Cancel”, “Save changes” — not sentences, and carry no trailing punctuation.
Props API
React@ghds/react
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'primary' | 'danger' | 'neutral' | 'primary' | Visual intent. |
asChild | boolean | false | Render as the single child element (Radix Slot) instead of a <button>. |
disabled | boolean | false | Disables interaction. |
type | 'button' | 'submit' | 'reset' | 'button' | Native button type. |
...rest | ButtonHTMLAttributes | — | All other native <button> attributes pass through. |
Web Components@ghds/web-components
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'primary' | 'danger' | 'neutral' | 'primary' | Reflected attribute. |
type | 'button' | 'submit' | 'reset' | 'button' | Drives form association (formAssociated = true). |
disabled | boolean | false | Reflected attribute. Wins over href — a disabled button renders a <button>, not a shadow link. A light-DOM <a href> child stays a link: it gets aria-disabled="true" and its activation is cancelled once the component upgrades. |
href | string | — | When set (and not disabled), renders a real <a href> instead of a <button>, keeping variant/focus styling. |
target | string | — | Forwarded to the inner <a> when href is set. |
rel | string | — | Forwarded to the inner <a> when href is set (e.g. 'noopener noreferrer' with target='_blank'). |
React Native@ghds/react-native
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | — | Visible, accessible label — required (no children). |
onPress | (event: GestureResponderEvent) => void | — | Press handler. |
variant | 'primary' | 'danger' | 'primary' | No neutral variant on React Native. |
disabled | boolean | false | Disables interaction. |
testID | string | — | Test handle for queries. |
accessibilityHint | string | — | Supplementary a11y hint describing the action's outcome. |
Code examples
// React — @ghds/react
import { Button } from '@ghds/react/button';
<Button variant="primary">Primary</Button>;
<Button variant="danger">Delete</Button>;
<Button variant="neutral">Cancel</Button>;
// As a link — keeps <a> semantics, gets button styling
<Button asChild variant="primary">
<a href="/getting-started/">Get Started →</a>
</Button>;
<!-- Web Components — @ghds/web-components -->
<script type="module">
import '@ghds/web-components/button';
</script>
<gh-button variant="primary">Primary</gh-button>
<gh-button variant="danger">Delete</gh-button>
<gh-button variant="neutral">Cancel</gh-button>
<!-- As a link — renders a real <a href> inside the shadow root -->
<gh-button variant="primary" href="/getting-started/">Get Started →</gh-button>
<gh-button variant="neutral" href="https://example.com/" target="_blank" rel="noopener noreferrer">
External
</gh-button>
<!-- As a light-DOM link — the <a href> is in the static HTML before any JS runs
(crawlers, no-JS visitors). gh-button styles the slotted anchor; put
target / rel / aria-label on the anchor itself. -->
<gh-button variant="primary"><a href="/getting-started/">Get Started →</a></gh-button>
// React Native — @ghds/react-native (no 'neutral' variant; label string + onPress, no children)
import { Button } from '@ghds/react-native/button';
<Button label="Delete" variant="danger" onPress={() => {}} />;
Live Demo
React and Web Components render live below, driven by the same tokens — toggle dark mode in the
header to see both respond identically. React Native can’t run in a browser without additional
react-native-web wiring (not set up in this site), so its usage is shown as a code sample instead.