Button
Button starts an action, such as saving a form, opening a dialog or deleting a file.
Button starts an action, such as saving a form, opening a dialog or deleting a file. You choose what the action means with tone and how prominent it is with emphasis, and the theme works out the colours.
emphasis ranks the actions on a screen. A loud button is filled with the tone's solid colour, a medium button has a soft fill, and a quiet button has no fill. Give each screen or pane one loud button for its main action. Adding bordered draws a thin line around the button, which places a quiet button a little above the other quiet ones. The defaults are medium emphasis and the neutral tone.
Use tone for meaning rather than for a colour you like: destructive for an action that deletes or removes, accent for your brand's main action, and success for an action that approves.
size sets the height, padding, corner, icon and text size together, so controls at the same size line up in a row. When you don't set it, the button takes the size of the Field or Toolbar it sits in, or else the Theme's size, which is 2. On a touch screen every size is taller, so buttons stay easy to tap.
Put an icon before the label with leading, or after it with trailing. For a square button with only an icon, set iconOnly and give it an aria-label. While an action runs, set loading: a spinner takes the place of the leading icon, the label stays, and presses are blocked. When the action finishes, set done, and the icon changes to a tick until you set it back to false. A button without an icon shows the tick beside its label, so it grows a little wider.
Button renders a real <button>, so Enter and Space press it, and it submits a form when type is submit. To make it work as a link, pass render={<a href="/billing" />}. A screen reader reads the label, or the aria-label on an icon-only button, and it doesn't read the tick, so change the label as well when you use done, for example from "Copy" to "Copied".
Some neighbouring cases have their own components. For a main action with a menu of related ones, use a SplitButton. To join several buttons into one control, use a ButtonGroup. For something that stays on or off, use a Toggle, and for a link inside a sentence, use a Link.
- Link when pressing it takes people to another place.
Props
Generated from the types. It lists what this component DECLARES: a prop that arrives from a shared type or from the platform is real and is not repeated here.
| Prop | Type | What it does |
|---|---|---|
aria-label? | string | The name of the button for screen readers. |
aria-labelledby? | string | The id of an element on the page that names this button. |
backdrop? | boolean | Set backdrop when the button sits over other content, such as an image. |
bordered? | boolean | Adds a thin border. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
done? | boolean | Shows a tick in place of the icon to say that the action finished. |
emphasis? | "loud" | "medium" | "quiet" | Sets how prominent the button is next to the buttons beside it. |
focusableWhenDisabled? | boolean | Keep focus on the button when it becomes disabled part-way through an interaction. |
iconOnly | true | Makes the button square and shows only the icon in children. |
leading? | React.ReactNode | Content before the label, usually an icon. |
loading? | boolean | Shows a spinner and blocks the press while an action runs. |
nativeButton? | boolean | Says whether the rendered element is a real <button>. |
render? | RenderElement | Renders the button as a different element, such as a link. |
size? | "1" | "2" | "3" | "4" | Sets the size step of the button, from 1 to 4. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
tone? | "neutral" | "accent" | "destructive" | "blue" | "green" | "orange" | "amber" | "pink" | "purple" | "success" | "warning" | "info" | Sets what the action means, and the theme picks the colour. |
trailing? | React.ReactNode | Content after the label, such as a chevron, a count or a control. |
It also takes every prop of a <button>.
margin— No component sets the space around itself, because the layout that holds it decides that. Wrap the button in<Box m>or use thegapof its container.variant— A variant mixes how loud a button is with what it means, which makes a quiet destructive button impossible. Usetonefor the meaning andemphasisfor the loudness.- A shadow prop — Shadows are set for the whole app by the Theme's
depth, so buttons across your app always match. No single button can ask for its own.