Button
Button is used to initiate actions on a page or form.
Page navigation navigation
React examples
Default
Style variants
- Primary: Highest-priority action; use sparingly. Never put more than one in a group of buttons, and rarely use more than one per page.
- Default: Default style for general actions. They can be paired with a primary Button to perform a secondary action.
- Invisible: Transparent for minimal UI or compound components like ActionList.
- Danger: Used sparingly for destructive actions, typically prompt a confirmation dialog.
Full-width
Size variants
- Medium (default): Best for most interfaces.
- Small: For compact spaces or less prominent actions.
- Large: Use sparingly to emphasize an action. More often than not a medium sized Button will be more appropriate.
With a leading visual
Leading visuals add context to Button labels. For example, a “search” icon next to the label for a search field submit.
With a trailing visual
Trailing visuals such as counters display additional information about the action or task at hand.
With a trailing action
Trailing actions (for example: a triangle icon to indicate a dropdown) are fixed at the Button's end. The Button label and leading visual is center-aligned for calls-to-action and left-aligned for buttons that toggle a selection UI (for example: Weeks ▾, Iteration ▾, Sort ▾, etc).
Loading
Use a loading state while waiting for action completion. See Button loading state for accessibility details.
Inactive
More code examples
The previous examples are a curated subset of the full capabilities of the Button
component. For more examples, see the Button Storybook stories.
Props
Button
Name | Required | Description |
---|---|---|
alignContent | 'start' | 'center' Content alignment for when visuals are present. | |
as | React.ElementType | |
block | boolean Allow button width to fill its container. | |
children | Required | React.ReactNode The content of the button. |
count | number For counter buttons, the number to display. | |
inactive | boolean Whether the button looks visually disabled, but can still accept all the same interactions as an enabled button.
This is intended to be used when a system error such as an outage prevents the button from performing its usual action.
Inactive styles are slightly different from disabled styles because inactive buttons need to have an accessible color contrast ratio. This is because inactive buttons can have tooltips or perform an action such as opening a dialog explaining why it's inactive.
If both `disabled` and `inactive` are true, `disabled` takes precedence. | |
leadingIcon Deprecated | React.ComponentType<OcticonProps> An icon to display before the button text. | |
leadingVisual | React.ElementType A visual to display before the button text. | |
loading | boolean When true, the button is in a loading state. | |
loadingAnnouncement | string The content to announce to screen readers when loading. This requires `loading` prop to be true | |
ref | React.RefObject<HTMLButtonElement> | |
size | 'small'
| 'medium'
| 'large' | |
sx | SystemStyleObject | |
trailingIcon Deprecated | React.ComponentType<OcticonProps> An icon to display after the button text. | |
trailingVisual | React.ElementType A visual to display after the button text. | |
trailingAction | React.ElementType Trailing action appears to the right of the trailing visual and is always locked to the end | |
variant | 'default'
| 'primary'
| 'danger'
| 'invisible'
| 'link' Change the visual style of the button. | |
labelWrap | boolean Whether the button label should wrap to multiple lines of it is longer than the button width. | |
disabled | boolean Avoid disabling buttons because it will make them inaccessible to users who rely on keyboard navigation. Buttons that are disabled can not be clicked, selected, or navigated through. |