Button

A button allows a user to initiate an action.

Anatomy

Structure

<Button> <IconList /> /* (Optional) A list of icons in the button */ <Icon /> /* (Optional) An icon in the button */ <Text /> /* (Optional) Text in the button, required if using an Icon or an IconList */ </Button>

Composed Components

A Button uses the following components:

Usage

Variants

Each button variant has a particular function and its design signals that function to the user. It is therefore very important that the different variants are implemented consistently across products so that they message the correct actions.

VariantPurpose
PrimaryFor the principal call to action on the page. Primary buttons should only appear once per screen (not including the application header, modal or side panel).
SecondaryFor secondary actions on each page. Secondary buttons can be used in conjunction with a primary button or on its own. Paired with a Primary button, the secondary button usually performs the negative action of the set, such as “Cancel.”
GhostFor less prominent, and sometimes independent, actions. Ghost buttons can be used in isolation or paired with a primary button when there are multiple calls to action. Ghost buttons can also be used for sub-tasks on a page where a primary button for the main and final action is present.
UpsellFor upsell actions that relates to upgrading an account or a plan. Use the upsell button to distinguish from an existing primary button. In some case a primary button can be used in its place when the general context of the page is about upselling.
DangerFor actions that could have destructive effects on the user's data.

Sizes

A button can vary in size.

Disabled

A button can be disabled.

Loading

A button can show a loading indicator. The button text is hidden but the button maintains the width that it would have if the text were visible.

Pending

Buttons can indicate that a quick progress task is taking place (e.g., saving settings on a server). After a 1 second delay, an indeterminate spinner will be displayed in place of the button label and icon.

Fluid

A button can be expanded to full width to fill its parent container.

Icon Only

A button can contain only an icon. An accessible name must be provided through aria-label prop. See also WCAG practices.

Icon

A button can contain icons.

End Icon

Nonstandard end icons can be provided to handle special cases. However, think twice before adding end icons, start icons should be your go-to.

Best Practices

Buttons are clickable elements that are used to trigger actions. They communicate calls to action to the user and allow users to interact with pages in a variety of ways. Button labels express what action will occur when the user interacts with it. Use buttons to communicate actions users can take and to allow users to interact with the page. Each page should have only one primary button, and any remaining calls to action should be represented as lower emphasis buttons.

Emphasis

You don't necessarily need to use the buttons in the order that their labels imply. For example, you don't always need to use the secondary button as the second button in your layout. The most important thing is to establish a visual hierarchy between the buttons in your interface. Keep these best practices in mind.

A single, high-emphasis button

As a general rule, a layout should contain a single high-emphasis button that makes it clear that other buttons have less importance in the hierarchy. This high-emphasis button commands the most attention.

Multiple button emphasis

A high-emphasis button can be accompanied by medium- and low-emphasis buttons that perform less important actions. Keep in mind that you should only groups together calls to action that have a relationship to one another.

Alignment

Alignment refers to whether the buttons are aligned to the right or the left of a container or layout. Buttons are unique, more so than any other component, in that their alignment depends on where they appear and whether or not they're contained within another component.

As a general rule, on full-page designs, the primary button is on the right side of the page. When the browser window is large and the user is scrolling to read, it's best to have the primary button where the users's attention has been focused all along. Whereas in wizards, where a user is progressing through a series of steps or modal, the primary action traditionally sits at the bottom right. Buttons within components are also right-aligned.

Do's and Don'ts

Do
When a Button contains anything other than a single text node, the accompanying text must be wrapped in a <Text> component.
Don't
Use text without <Text> if you have anything other than a single text node inside the Button.
Do
Use 1 or 2 words, no longer than 4 words, with fewer than 20 characters including spaces.
Don't
Use punctuation marks such as periods or exclamation points.
Do
Use links when the desired action is to take the user to a new page.
Don't
Use buttons as navigational elements.

Props

variant?

The visual style of the button.

Defaults to primary.
size?

A button can vary in size.

Defaults to md.
isFluid?

Whether or not the button takes up the width of its container.

isLoading?

A button can show a loading indicator.

spinnerProps?

The props for the Spinner.

form?

The element to associate the button with. The value of this attribute must be the id of a in the same document.

style?

The inline style for the element. A function may be provided to compute the style based on component state.

children?

The children of the component. A function may be provided to alter the children based on component state.

isDisabled?

Whether the button is disabled.

autoFocus?

Whether the element should receive focus on render.

type?

The behavior of the button when used in an HTML form.

Defaults to 'button'.
formAction?

The URL that processes the information submitted by the button. Overrides the action attribute of the button's form owner.

formEncType?

Indicates how to encode the form data that is submitted.

formMethod?

Indicates the HTTP method used to submit the form.

formNoValidate?

Indicates that the form is not to be validated when it is submitted.

formTarget?

Overrides the target attribute of the button's form owner.

name?

Submitted as a pair with the button's value as part of the form data.

value?

The value associated with the button's name when it's submitted with the form data.

className?

The CSS className for the element. A function may be provided to compute the class based on component state.

Migration Notes

Coming from Orbiter, you should be aware of the following changes:

  • onClick has been renamed to onPress to be closer to the React Aria API.
  • Counter is no longer allowed as a specialized slot.
  • ButtonAsLink is renamed to LinkButton.
  • IconButton is now integrated into the Button component.
  • as(Button, ReactRouterLink) is now integrated into the Button component.