Design System

Design System

Button

Actions

Open in Storybook: Button (opens in a new tab)

On this page

Overview

The button for an action on the current page: submit a form, open a dialog, toggle a setting, play media, delete an item. It is always a native button, which gives Enter and Space, focus, a role and a disabled state for free. If the control takes the user somewhere else it is a link, even when the design makes it look like a button.

Primary is for the one action a view exists for, Secondary for the rest and Tertiary for the quietest. Verb first, sentence case: “Erase account”. Never two Primary buttons in one view.

Anatomy

  1. Button

    button type="button"

    The one element. It holds the role, the name, the state and the focus. A hard shadow of 4px, an edge of 2px and a radius of 8.

  2. Icon

    svg aria-hidden="true"

    Decorative, 24px, in the colour of the label. A check replaces it when a toggle is on, a chevron turns in a menu button, a spinner is drawn while it loads.

  3. Label

    text

    The visible words are the accessible name: verb and object. An icon-only button has an aria-label instead.

Usage

Use cases

The nine of the design, each the real button, and each works.

  • Variants

    Primary for the one action a view exists for, Secondary for the rest, Tertiary for the quietest. Hover them, tab to them, press Enter or Space.

    button type="button", variant

  • Loading and feedback

    Press Save changes. While it works the button keeps its label and its focus, and the end is said once.

    Nothing is saved yet.

    aria-disabled="true", svg aria-hidden="true", ariaNotify()

  • disabled and aria-disabled

    disabled leaves the tab order. aria-disabled stays in it, points at the reason and does nothing when it is activated: tick the box to use it.

    disabled

    Out of the tab order, ignored by click. For a control that is irrelevant right now.

    aria-disabled="true" and a reason

    Accept the terms to continue.

    disabled, aria-disabled="true" with aria-describedby

  • Toggle button

    The label never changes, the state does: a heart while it is off, a check while it is on.

    button aria-pressed

  • Menu button

    Opens a list of actions. Esc closes it from the button or from inside it, and focus returns to the button.

    Nothing chosen.

    button aria-expanded aria-controls

  • Say what happens

    The visible label is the accessible name: verb and object, so each button makes sense on its own.

    Don’t

    Generic labels. Out of context, in a list of the buttons of the page, nobody knows what they do.

    Do

    Verb and object. Each button makes sense on its own.

    The visible text is the name

  • Icon only

    An icon with no words is named by an aria-label, and the same words are a tooltip on hover and on focus.

    Don’t

    An icon with no name. A screen reader says “button”, and a trash can means delete, discard or clear.

    Do

    aria-label="Delete draft" on the button and the icon hidden. The same words are a tooltip on hover and on focus.

    button aria-label, svg aria-hidden="true", role="tooltip"

  • Label in name

    An aria-label that replaces the visible words breaks voice control: “Click Send” does nothing.

    Don’t

    aria-label="Submit the contact form"

    The aria-label replaces the visible words. “Click Send” in voice control does nothing.

    Do

    No aria-label, or aria-label="Send message"

    Let the visible words be the name. If you add context, start with them.

    No aria-label, or one that starts with the visible words

  • Room for the focus ring

    The ring is 3px outside the button, so a parent that cuts what is outside it cuts the ring.

    Don’t

    outline: none, or a parent with overflow: hidden that cuts the ring. A keyboard user loses their place.

    Do

    The ring of the site and room around the button for it, and its shadow.

    :focus-visible, no overflow: hidden around

Props

Props
PropDoesDefault
childrenThe label, and the accessible name. Verb and object.required
variantprimary, secondary or tertiary.primary
loadingWork is running: aria-disabled, the spinner is drawn, the label and the focus stay, and the click does nothing.false
typeA button left to the browser submits its form. This one says button unless told otherwise.button
disabled, aria-disabled, onClick, ref, any native attributeAs on a native button. A click on an aria-disabled button is stopped before onClick, so it submits nothing.—
IconButton: icon, labelAn icon with no words. label is the aria-label; the icon is hidden. Show the same words as a tooltip.both required
ToggleButton: icon, pressed, defaultPressed, onPressedChangearia-pressed is the state and the label never changes. icon is shown while off, a check while on.defaultPressed false
MenuButton: expanded, controlsaria-expanded and aria-controls. The chevron turns with expanded. The menu is yours.both required

Example

loading is the whole of the loading state: do not set disabled while it works, or focus falls to body. Say the end with ariaNotify() after the page has changed.

<Button variant="primary" loading={saving} onClick={save}>
  Save changes
</Button>

<IconButton icon={Trash2} label="Delete draft" />

<ToggleButton icon={Heart}>Favourite</ToggleButton>

<MenuButton expanded={open} controls={menuId} onClick={() => setOpen(!open)}>
  Options
</MenuButton>

<Button aria-disabled={!accepted} aria-describedby={reasonId}>
  Continue
</Button>
<p id={reasonId}>Accept the terms to continue.</p>

Specs

Measurements

Measurements
PartPropertyValue
Targetmin-block-size, min-inline-size2.75rem (44px). It grows with the text
Buttonpadding0.75rem 1.25rem (12px 20px)
Icon buttonpadding0.625rem (10px): 24px of icon and the edge make 48 × 48
Edgeborderbw (2px), transparent where the design draws none, so the button never changes size
Cornerborder-radiusradius (8px)
Shadowbox-shadowshadow (4px 4px 0 ink)
Gapgap0.5rem (8px)
Iconsize24px, in the colour of the label
Labelfont1rem (16px), 700
Focus ringoutlinefocus-ring-width (4px), 3px outside, focus-ring-primary. The site’s own, not declared again
Presstranslate4px 4px

Variants

Variants
VariantFillWordsEdgeShadow
Primaryaccentaccent-foregroundnoneshadow
Secondarywhiteinkinkshadow
Tertiarynonelilacnonenone
On (a toggle with aria-pressed="true")accentaccent-foregroundnoneshadow

States

States
StatePrimarySecondaryTertiary
Defaultaccent fill, white words, shadowwhite fill, ink words and edge, shadowno fill, lilac words, no shadow
Hoverlilac-deep fill, shadow stayswash fill, shadow stayswash fill, lilac-deep words
Focusthe ring, and no shadowthe ring, and no shadowthe ring
Pressedlilac-deep fill, no shadow, moves 4pxwash fill, no shadow, moves 4pxline fill, lilac-deep words
Disabledfill, ink-soft words, dashed ink-soft edge, no shadowas Primaryas Primary, with no fill
Loadingits Default look and a spinner before the labelits Default look and a spinnerits Default look and a spinner

Hover darkens the fill and is never the only cue for anything: touch and keyboard users do not see it. Pressed is feedback, not meaning. A button that is aria-disabled, loading included, answers to neither.

Kinds

Kinds
KindElementIts state isIcon
Buttonbuttonloading, disabled or aria-disablednone
Icon buttonbutton aria-labelas Button24px, hidden from assistive technology
Toggle buttonbutton aria-pressedaria-presseda heart while off, a check while on
Menu buttonbutton aria-expanded aria-controlsaria-expandeda chevron down, up while open

disabled and aria-disabled

disabled and aria-disabled
AttributeTab orderClickUse it for
disabledout: Tab skips it, so a user may never learn why it is thereignored by the browsera control that is irrelevant right now
aria-disabled="true"in, and announced as dimmedstopped by the component: no handler, no submita submit button or a step, with the reason in aria-describedby

Better still: keep the button enabled, validate on submit and move focus to the first error. The disabled look is exempt from contrast rules, and ours stays readable (ink-soft on fill, 7.8 to 1) and adds a dashed edge so it is not shown by colour alone.

Markup

<button type="submit" class="bt bt--primary">Save changes</button>

<button type="button" class="bt bt--secondary bt--icon" aria-label="Delete draft">
  <svg aria-hidden="true" focusable="false">…</svg>
</button>

<button type="button" class="bt bt--secondary" aria-pressed="false">
  <svg aria-hidden="true" focusable="false">…</svg>Favourite
</button>

<button type="button" class="bt bt--secondary" aria-expanded="false" aria-controls="options-menu">
  Options<svg aria-hidden="true" focusable="false">…</svg>
</button>

<button type="submit" class="bt bt--primary" aria-disabled="true" aria-describedby="terms-hint">Continue</button>
<p id="terms-hint">Accept the terms to continue.</p>

Styling

.bt { min-block-size: 2.75rem; min-inline-size: 2.75rem; }
.bt:focus-visible { box-shadow: none; } /* the ring is the site's */
.bt:active:not(:disabled, [aria-disabled='true']) {
  box-shadow: none;
  translate: 4px 4px;
}
@media (prefers-reduced-motion: reduce) {
  .bt:active:not(:disabled, [aria-disabled='true']) { translate: none; }
  .bt__spinner { animation: none; }
}

Tokens

Component tokens

Component tokens
PartPropertyTokenValue
Primarybackgroundaccent#5e548e
Primarycoloraccent-foreground#ffffff
Primary, hover and pressedbackgroundlilac-deep#3d3459
Secondarybackgroundwhite#ffffff
Secondarycolor, border-colorink#16161a
Secondary, hover and pressedbackgroundwash#edebf4
Tertiarycolorlilac#5e548e
Tertiary, hoverbackground, colorwash, lilac-deep#edebf4, #3d3459
Tertiary, pressedbackgroundline#d7d7dc
Disabledbackgroundfill#f3f3f5
Disabledcolor, border-colorink-soft#4b4b55
Shadowbox-shadowshadow4px 4px 0 #16161a
Cornerborder-radiusradius8px
Edgeborder-widthbw2px
Focus ringoutlinefocus-ring-primary, focus-ring-width#0066ff, 4px

Guidelines

Button or link

Button or link
ElementUse it whenExamples
buttonit does something on the current pagesubmit or save a form · open or close a dialog, menu or drawer · toggle a setting (aria-pressed) · play, pause, mute · add to cart, delete, copy · show more content on the same page · export a file that has no URL yet
a hrefit goes somewhereanother page or route · a section of the same page (#id) · a file that already has a URL · an external site · open in a new tab

Style follows the design; the element follows the behaviour. A “Shop now” that navigates is an a href styled as a button. A “Load more” that stays on the page is a button, even styled as a text link (then do not underline it).

Which variant

Which variant
VariantUse it for
Primarythe one action a view exists for. Never two in one view
Secondarythe rest
Tertiarythe quietest: an action that sits among others or in a dense row
Dangerthe site’s destructive button, for an action that cannot be undone, has no design on the Figma page and is not built here

Content

Content
PartFormatExample
Labelverb first, then the object, sentence caseSave changes · Send message
Icon onlyan aria-label with the action and the object, and the same words as a tooltip for sighted usersDelete draft
Togglethe label never changes: “Unfavourite” would be read twice and contradict itselfFavourite
Reasona sentence next to an aria-disabled button, in its aria-describedbyAccept the terms to continue.
The endwords on the page, said onceChanges saved

Behavior

Behavior
EventResult
Activateruns onClick. Focus stays on the button
Activate while loading or aria-disablednothing: no handler and no submit
Loading startsaria-disabled, the spinner, the label and the focus stay. disabled would drop focus to body (2.4.3)
Loading endsthe button is Default again, the end is words on the page and is said once with ariaNotify()
Togglearia-pressed flips, the label stays, the icon is a heart or a check
Menu buttonaria-expanded flips. Esc closes the menu and focus returns to the button
Pressedthe shadow drops and the button moves 4px. Not under prefers-reduced-motion

Fake buttons

Fake buttons
MarkupWhy not
div onclickNo role, no focus, no Enter or Space. Rebuilding that is more code and easier to break (4.1.2, 2.1.1)
a href="#" onclickAnnounced as a link, Space scrolls the page, the URL gets a #. If it does something, it is a button
button inside aNested interactive elements: one is unreachable or both are announced at once. Keep them siblings
A button with no type in a formIt defaults to submit: a “Show password” button submits the form. The component says type="button"

Accessibility

Keyboard

Keyboard
KeyActionNative
Tab, Shift+Tabmoves to and from the button in DOM order. disabled is skipped, aria-disabled is notyes
Enteractivatesyes
Spaceactivates, on release. A link does not respond to Space: one more reason not to fake buttonsyes
Escin a menu or dialog opened by the button, closes it and returns focus to the buttonno, script

Roles and properties

Roles and properties
PropertyExposedNote
rolebuttonimplicit; a toggle is announced as a toggle button
namethe visible label, or the aria-label of an icon buttonstarts with the visible words (2.5.3)
aria-pressedtrue or falsea toggle only
aria-expanded, aria-controlsthe state and the menu it opensa menu button only
aria-disabledtruea loading button, or one with a reason. Still focusable
disableddimmed, out of the tab orderfor a control that is irrelevant
aria-describedbythe reasonon an aria-disabled button
typebuttonthe component’s default

Screen reader

The words of the design. Listen in NVDA, JAWS and VoiceOver before relying on them: none was run.

Screen reader
MomentWhat is read
A toggle that is on“Favourite, toggle button, pressed”
A menu button that is closed“Options, button, collapsed”
An aria-disabled buttondimmed or unavailable, then the reason
An icon button“Delete draft, button”

Announcements

The Figma page says <p role="status">. A live region is not used here: the words are on the page and ariaNotify() says them once, as in the Progress and the Video player.

Announcements
EventSaid byAnnouncedPriority
Work startednothing: aria-disabled and the spinner——
Work doneariaNotify() on the button, after the page has changed“Changes saved”normal
Toggledthe browser, from aria-pressedthe state—
Menu opened or closedthe browser, from aria-expandedthe state—

Measured behavior

Chromium 148.0.7778.96, from the tests.

Measured behavior
ObservationConsequence
Space fires the click on release, not when it goes downthe pressed look is :active, which is true while it is held
Hovered and focused at once, the button has no shadow:focus-visible comes after :hover and :active
disabled is skipped by Tab and aria-disabled is focuseda button with a reason must be aria-disabled
A native aria-disabled submit button still submits on click and Enterthe component stops the click itself
A line of text in the system font makes the button 46px high, not the 47 that the Figma draws in Work Sansthe target is min-block-size, never a fixed height

Support

Support
BrowserChecked
Chromium 148yes, in the tests and the stories
WebKit, Firefoxnot run

WCAG criteria

WCAG criteria
CriterionLevelRequirement here
1.4.1 Use of ColorAdisabled is a dashed edge and muted words, and a toggle that is on is a fill and a check
1.4.3 Contrast (Minimum)AAthe label is 6.7 to 1 or more in every state. Disabled is exempt and is 7.8 to 1
1.4.4 Resize TextAAsizes are in rem: the button grows with the text
1.4.11 Non-text ContrastAAthe ring is 4.8 to 1 against the page
1.4.13 Content on Hover or FocusAAthe tooltip of an icon button shows on hover and on focus, and Esc dismisses it
2.1.1 KeyboardAa native button: Enter and Space
2.4.3 Focus OrderAloading never uses disabled, so focus never falls to body
2.4.7 Focus VisibleAAthe ring is shown by :focus-visible
2.4.11 Focus Not Obscured (Minimum)AAroom around the button for the ring and its shadow: no overflow: hidden cuts it
2.5.3 Label in NameAthe visible text is the name, and any aria-label starts with it
2.5.8 Target Size (Minimum)AA24 × 24 or more, with 8px between neighbours
2.5.5 Target Size (Enhanced)AAA44 × 44 or more: our default
4.1.2 Name, Role, ValueAa native button with its state in aria-pressed, aria-expanded or aria-disabled
4.1.3 Status MessagesAAthe end of a task is said once with ariaNotify()

Related

This section is still in progress.

References

Read the post: Link or Button (opens in a new tab)