Button

Buttons allow users to trigger an action or to navigate to another page. They are available in multiple styles for various purposes. Buttons are ideal for calling attention to actions users need to perform in order to move forward in a flow.

Example

Button Basic Example

UI recommendations

Recommendations for creating clear and effective buttons:

  1. Button text should be clear and concise. No more than 4 words or 20 characters is recommended.
  2. Use verbs for button text to indicate the action that will be taken when the button is clicked. For example, “Save”, “Delete”, or “Add friend”, rather than “Ok” or “Cancel”. Nouns or adjectives tend to be less clear.
  3. Use sentence case for button text with more than one word. For example, “Add friend” instead of “Add Friend” or “ADD FRIEND”.
  4. No punctuation is needed at the end of the button text.
  5. Use icons only when necessary, and not as a replacement for text or decoration. Icons should be used to provide additional context to the button’s action.
  6. When presenting choices, use a single filled accent button to suggest to users the recommended choice, paired with outlined primary or secondary buttons for the other options. This helps to visually distinguish the primary action from the secondary actions.
  7. Use negative buttons sparingly, as they can be visually distracting. They should be used for actions that are destructive or irreversible.

Consider using action_button for task-based actions, or in cases where buttons aren’t meant to draw attention to themselves. To represent a binary choice, use a toggle_button instead. If you have a collection of related buttons, you can group them using a button_group.

Events

Buttons accept a value to display and can trigger actions based on events such as setting state when pressed. See the API Reference for a full list of available events.

Variants

Buttons can have different styles to indicate their purpose.

Static-color buttons are available in white and black. They don’t dynamically change in response to the user’s theme. They should only be used over fixed-color backgrounds, not over theme colors that may change.

Icon buttons

Buttons can have icons when necessary to provide additional context. If no visible label is provided (e.g., an icon-only button), an alternative text label must be provided to identify the control for accessibility using the aria-label prop. See icon for a list of available icons.

Pending state

Buttons can be in a pending state to indicate that an action is in progress (such as an asynchronous server request). After a one-second delay, an indeterminate spinner will be displayed in place of the button label and icon. You can trigger this behavior by setting the is_pending prop. Button events are disabled while is_pending is true.

Disabled state

Buttons can be disabled to prevent user interaction. This is useful when the button is not available for interaction, but should still be visible.

Buttons can be used as links to navigate to another page if the href attribute is provided.

API reference

Buttons allow users to perform an action or to navigate to another page. They have multiple styles for various needs, and are ideal for calling attention to where a user needs to do something in order to move forward in a flow. Python implementation for the Adobe React Spectrum Button component: https://react-spectrum.adobe.com/react-spectrum/Button.html

Returns: Element The rendered button component.

ParametersTypeDefaultDescription
*childrenAnyThe contents to display inside the button.
variantLiteral['accent', 'primary', 'secondary', 'negative'] |
None
'accent'The visual style of the button.
styleLiteral['fill', 'outline'] |
None
'fill'The background style of the button.
static_colorLiteral['white', 'black'] |
None
NoneThe static color style to apply. Useful when the button appears over a color background.
is_pendingbool |
None
NoneWhether to disable events immediately and display a loading spinner after a 1 second delay.
typeLiteral['button', 'submit', 'reset']'button'The behavior of the button when used in an HTML form.
is_disabledbool |
None
NoneWhether the button is disabled.
auto_focusbool |
None
NoneWhether the button should automatically receive focus when the page loads.
hrefstr |
None
NoneA URL to link to when the button is pressed.
targetstr |
None
NoneThe target window or tab to open the linked URL in.
relstr |
None
NoneThe relationship between the current document and the linked URL.
keystr |
None
NoneA unique identifier used by React to render elements in a list.