Button
A control that commits an action on this screen.
In Accessible first
See it live
npm run storybookWhen to use it
In Accessible first: Every action, with a large target.
- Use it when: The press does something here: save, submit, delete, open a dialog, go to the next step.
- Not when: The press only takes people to another page, or flips a setting that should persist.
Instead:
- Toggle: An on or off setting that should persist as state.
- Link: Navigation to another page or section.
Variants
What each variant is for in any design system, then what Accessible first decided and why. Each sample is the live story with that variant set.
primaryvariantUsed in Accessible firstWhat it is for
The one action this view is for.
In Accessible first
The one next step on a page.
secondaryvariantUsed in Accessible firstWhat it is for
A real action, quieter than the commit.
In Accessible first
Every other action, always with a word: alternatives, row actions, and the first step of a delete.
dangervariantUsed in Accessible firstWhat it is for
A destructive commit, after a confirm.
In Accessible first
The confirm of a delete, always with the verb and an icon, so color is never the only cue.
ghostvariantNot used in Accessible firstWhat it is for
The lowest emphasis; it never competes with the commit.
In Accessible first
Every action looks like a button people can find.
defaultsizeUsed in Accessible firstWhat it is for
The normal size, for ordinary actions in forms, dialogs and page chrome.
In Accessible first
Every button. Large targets help people with motor needs.
compactsizeNot used in Accessible firstWhat it is for
Denser, for toolbars and table rows that sit beside content.
In Accessible first
Large targets help people with motor needs; nothing smaller.
iconsizeNot used in Accessible firstWhat it is for
Icon only: the name is not on screen.
In Accessible first
Icons alone are guesswork: always add a word.
largesizeNot used in Accessible firstWhat it is for
The largest size: the one action that must stand out most.
In Accessible first
The default size is already large for motor needs; a bigger one adds nothing.
hoverstateUsed in Accessible firstWhat it is for
The pointer is over the control: an extra cue, never the only cue.
In Accessible first
Moderate feedback that is easy to follow.
focusstateUsed in Accessible firstWhat it is for
Keyboard or assistive tech is on this control. It must stay visible.
In Accessible first
Seen by everyone: the focus ring with an offset.
disabledstateNot used in Accessible firstWhat it is for
The action is not available. It must stay perceivable and say why.
In Accessible first
Keep it enabled and explain on press: nobody is left out, and nobody remembers the interface from last time.
How Accessible first uses it
Why it works this way
Button looks the way it does because of 7 answers about this product. Each card is one answer, in three steps: the answer, what it decided for Button, and what would move if it changed.
color.count1The answer
Primary and secondary only; fewer choices, fewer errors.
2So Button
- ✓uses primary: The one next step on a page.
3If it changed
No other answer follows from it.
human.q21The answer
Nobody remembers the interface from last time.
2So Button
- ✓uses secondary: Every other action, always with a word: alternatives, row actions, and the first step of a delete.
- –does not use ghost: Every action looks like a button people can find.
- –does not use disabled: Keep it enabled and explain on press: nobody is left out, and nobody remembers the interface from last time.
Field: responsive Toggle: default3If it changed
and 1 answer that follow from it: Actions and status.
outcomes.q21The answer
A failed form can cost someone a benefit.
2So Button
- ✓uses secondary: Every other action, always with a word: alternatives, row actions, and the first step of a delete.
- ✓uses danger: The confirm of a delete, always with the verb and an icon, so color is never the only cue.
Alert: destructive Badge: warning Badge: danger3If it changed
No other answer follows from it.
people.q21The answer
AAA where it applies; nobody is left out.
2So Button
- ✓uses danger: The confirm of a delete, always with the verb and an icon, so color is never the only cue.
- ✓uses focus: Seen by everyone: the focus ring with an offset.
- –does not use disabled: Keep it enabled and explain on press: nobody is left out, and nobody remembers the interface from last time.
Field: vertical Field: horizontal Input group: inline-start Input group: inline-end Input group: block-start Input group: block-end3If it changed
and 15 answers that follow from it: A ratio, line heights in proportion, Neutrals and one brand ramp, Nothing, and 12 more.
accessibility.values1The answer
Large targets for tremor and touch.
2So Button
- ✓uses default: Every button. Large targets help people with motor needs.
- –does not use compact: Large targets help people with motor needs; nothing smaller.
- –does not use large: The default size is already large for motor needs; a bigger one adds nothing.
Item: default Item: sm Toggle: default Toggle: sm Toggle: lg3If it changed
No other answer follows from it.
iconography.roles1The answer
Icons support words; they never replace them.
2So Button
- –does not use icon: Icons alone are guesswork: always add a word.
Input group: inline-end Toggle: outline3If it changed
No other answer follows from it.
motion.values1The answer
Moderate speed is easy to follow.
2So Button
- ✓uses hover: Moderate feedback that is easy to follow.
3If it changed
No other answer follows from it.
Words
- Use common words. Explain any term you must use.
- One idea per sentence. Put the action first.
- Never blame the person.
- Use: Continue, Change, Start, You. Avoid: Invalid, Utilise, Submit, Error code.
The labels components use, from the voice tokens:
content.action.commit: Continuecontent.action.cancel: Go backcontent.action.destroy: Deletecontent.action.retry: Try againcontent.action.empty-action: Start a new application
See Voice and tone for the whole voice.
Accessibility and keyboard
| Keyboard | What happens | Not |
|---|---|---|
| Moving through the page or a dialog. | Tab lands on the button in a logical order. | The control is skipped because it used HTML disabled. |
| The button is focused and the person confirms. | Enter runs the same action as a click. | Enter only works on submit buttons. |
| The button is focused. | Space runs the same action as a click. | Space scrolls the page instead. |
| The button opened a dialog, menu or popover that just closed. | After the action closes a surface, focus returns to the button. | Focus dropped on the page body. |
Test before you ship:
- The control has a name assistive tech can speak. Any button, especially an icon-only one.
- The focused control stays visible; color alone is not the cue. Keyboard or assistive-tech focus is on the button.
- Unavailable stays in the tab order and explains why. The action must not run, but focus must not jump away.
- A button that stays down exposes its pressed state. Pin, follow, or another sticky on or off on a button.
- A button that opens something exposes open or closed. The press reveals a menu, panel or more content.
- The hit area stays usable, including at a small size. Touch, pointer, or a compact toolbar button.
Use it in code
npx open-ds add button
The component reads only component keys and semantic tokens, so it follows the brand and mode on <html>.
Tokens it reads
Button reads 32 tokens of its own, each an alias of a semantic token. Each row is one part: its own token, the semantic it aliases, and the value it ends at. Change a semantic and every component that reads it follows; override one of Button's tokens to change Button alone.
Accessible first decides what changes when you switch theme. Here a switch changes colors only, so the marked rows differ between light and dark; everything else holds steady.
| Part | Its token and the semantic it aliases | Value |
|---|---|---|
| Primary | ||
| Fill Changes with theme | component.button.primary.backgroundcolor.action.primaryvar(--button-primary-background) | Lightblue.light.600:#0B4FC0Darkblue.dark.600:#8AB4F8 |
| Background hover Changes with theme on hover | component.button.primary.background.hovercolor.action.primary.hovervar(--button-primary-background-hover) | Lightblue.light.700:#013895Darkblue.dark.700:#A7C8FC |
| Text Changes with theme | component.button.primary.labelcolor.text.on-actionvar(--button-primary-label) | Lightgray.light.0:#FFFFFFDarkgray.light.900:#141414 |
| Secondary | ||
| Fill Changes with theme | component.button.secondary.backgroundcolor.action.secondaryvar(--button-secondary-background) | Lightgray.light.0:#FFFFFFDarkgray.dark.50:#141414 |
| Background hover Changes with theme on hover | component.button.secondary.background.hovercolor.action.secondary.hovervar(--button-secondary-background-hover) | Lightgray.light.100:#EDEDEDDarkgray.dark.100:#222222 |
| Text Changes with theme | component.button.secondary.labelcolor.text.primaryvar(--button-secondary-label) | Lightgray.light.900:#141414Darkgray.dark.900:#F7F7F7 |
| Border Changes with theme | component.button.secondary.bordercolor.border.strongvar(--button-secondary-border) | Lightgray.light.500:#595959Darkgray.dark.500:#949494 |
| Border width | component.button.secondary.border-widthborder-width.defaultvar(--button-secondary-border-width) | border-width.2:2px |
| Danger | ||
| Fill Changes with theme | component.button.danger.backgroundcolor.action.dangervar(--button-danger-background) | Lightred.light.600:#C42B2BDarkred.dark.600:#F28B8B |
| Background hover Changes with theme on hover | component.button.danger.background.hovercolor.action.danger.hovervar(--button-danger-background-hover) | Lightred.light.700:#981519Darkred.dark.700:#FAA9A8 |
| Text Changes with theme | component.button.danger.labelcolor.text.on-dangervar(--button-danger-label) | Lightgray.light.0:#FFFFFFDarkgray.light.900:#141414 |
| Ghost | ||
| Background hover Changes with theme on hover | component.button.ghost.background-hovercolor.surface.sunkenvar(--button-ghost-background-hover) | Lightgray.light.100:#EDEDEDDarkgray.dark.100:#222222 |
| Text Changes with theme | component.button.ghost.labelcolor.text.linkvar(--button-ghost-label) | Lightblue.light.700:#013895Darkblue.dark.700:#A7C8FC |
| Button | ||
| Height | component.button.heightsize.control.defaultvar(--button-height) | size.52:3.25rem |
| Padding, left and right | component.button.padding-xspace.inset.control-xvar(--button-padding-x) | space.24:1.5rem |
| Corner | component.button.radiusradius.controlvar(--button-radius) | radius.6:0.375rem |
| Text size | component.button.font-sizetype.label.font-sizevar(--button-font-size) | font.size.18:1.125rem |
| Weight | component.button.font-weighttype.label.font-weightvar(--button-font-weight) | font.weight.700:700 |
| Focus ring Changes with theme on focus | component.button.focus-ringcolor.border.focusvar(--button-focus-ring) | Lightblue.light.600:#0B4FC0Darkblue.dark.600:#8AB4F8 |
| Icon size | component.button.icon-sizesize.iconvar(--button-icon-size) | size.20:1.25rem |
| Gap | component.button.gapspace.gap.defaultvar(--button-gap) | space.16:1rem |
| Font family | component.button.font-familytype.label.font-familyvar(--button-font-family) | font.family.atkinson-hyperlegible:"Atkinson Hyperlegible", Verdana, sans-serif |
| Focus on focus | component.button.focusborder-width.focusvar(--button-focus) | border-width.3:3px |
| Canvas Changes with theme on focus | component.button.canvascolor.surface.canvasvar(--button-canvas) | Lightgray.light.50:#F7F7F7Darkgray.dark.0:#0A0A0A |
| Disabled | ||
| Fill Changes with theme when disabled | component.button.disabled.backgroundcolor.disabled.surfacevar(--button-disabled-background) | Lightgray.light.100:#EDEDEDDarkgray.dark.100:#222222 |
| Text Changes with theme when disabled | component.button.disabled.labelcolor.disabled.textvar(--button-disabled-label) | Lightgray.light.500:#595959Darkgray.dark.500:#949494 |
| Border Changes with theme when disabled | component.button.disabled.bordercolor.disabled.bordervar(--button-disabled-border) | Lightgray.light.200:#D6D6D6Darkgray.dark.200:#333333 |
| Compact | ||
| Height | component.button.compact.heightsize.control.compactvar(--button-compact-height) | size.48:3rem |
| Padding, left and right | component.button.compact.padding-xspace.inset.cell-xvar(--button-compact-padding-x) | space.16:1rem |
| Large | ||
| Height | component.button.large.heightsize.control.largevar(--button-large-height) | size.52:3.25rem |
| Shared | ||
| Transition duration | component.transition.durationmotion.duration.feedbackvar(--transition-duration) | duration.moderate:200ms |
| Transition easing | component.transition.easingmotion.easing.standardvar(--transition-easing) | easing.standard:cubic-bezier(0.2,0,0,1) |