Button
A button that triggers an action, with Dify variants, sizes and a pending state.
Usage guidelines
- Use
Buttonfor an action with a visible text label. An icon-only command usesIconButton, a persistent pressed state usesToggle, and navigation uses a native link. - Keep one
primarybutton per surface for the action the user most likely wants. Supporting actions usesecondary; low-emphasis actions in toolbars and dense rows useghostortertiary. - Mark an action that deletes or discards data with
tone="destructive". The accent variants exist for highlighted secondary actions and do not take a destructive tone. Buttonrenderstype="button". Settype="submit"when it submits a form.- Do not render a link through
Button: Base UI applies button semantics, keyboard interaction and disabled behavior to the rendered element. Keep navigation on a native anchor or routing link and reuse the look withbuttonVariants. - Use
renderwithnativeButton={false}only when a non-button element intentionally needs button semantics. It is not a link mode. - Use
loadingfor an action that was triggered and is now pending, anddisabledfor an action that is unavailable. They are separate facts and can both apply: pass the pending state only toloadingand keep independent availability conditions indisabled. - Pass
focusableWhenDisabled={false}only when a loading button should opt into native disabled behavior and may leave the tab order. PassfocusableWhenDisabledon adisabledbutton only when focus must still land on it: the return target of a closing surface, or a control whose tooltip explains why it is unavailable. - Keep a non-empty visible label throughout loading; the spinner is decorative. Do not replace a changing label with
aria-label. See Accessible names for choosing a naming source. Buttondoes not addaria-busy, which describes an element whose own updates assistive technology may defer, not a pending action. Long-running announcements and progress stay with the feature's status, live-region or progress owner.
Anatomy
Button owns the spacing between its children, so call sites do not add icon margins or a gap-* class. Override the gap through className only for a documented layout exception.
Examples
Variants and tones
Six variants set the emphasis. primary, secondary, tertiary and ghost also take tone="destructive".
Sizes
small, medium (the default) and large set the height, padding and gap together. medium and large use 4px and 6px gaps; small uses 3px for primary and 4px for the other variants.
Loading
loading blocks activation while the button keeps focus, and shows a decorative spinner. When the visible label changes during loading, give the label a stable ID and reference it with aria-labelledby so screen readers announce the new name; some browser and screen-reader combinations do not reliably announce changes to a focused button's descendant text. The consumer owns this relationship because only it knows whether the label changes and whether other visible context must also be referenced. A label that stays the same keeps naming the button through its text.
Disabled
disabled removes the button from the tab order. Add focusableWhenDisabled when focus must still reach it, such as a disabled action whose Tooltip explains why it is unavailable.
Link
Keep navigation on a native anchor or router link and apply buttonVariants to reuse the button appearance without turning the link into a button.
Keyboard
| Key | Action |
|---|---|
| Enter | Activates the button. |
| Space | Activates the button. |
| Tab | Moves focus to the next control. A loading button stays in the tab order; a disabled button leaves it unless focusableWhenDisabled is set. |
API reference
Button
A styled button that triggers an action. Renders a <button> element.
Setting loading disables activation and keeps the button focusable by default.
| Prop | Type | Default | Details |
|---|---|---|---|
size | 'large' | 'medium' | 'small' | 'medium' | |
variant | 'ghost' | 'ghost-accent' | 'primary' | 'secondary' | 'secondary-accent' | 'tertiary' | 'secondary' | |
tone | 'default' | 'destructive' | 'default' | |
loading | boolean | No default | |
focusableWhenDisabled | boolean | false | |
className | string | ((state: ButtonState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, ButtonState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: ButtonState) => React.CSSProperties | undefined) | No default | |
nativeButton | boolean | true | |
Valid prop combinations:
variant?: 'ghost' | 'primary' | 'secondary' | 'tertiary',tone?: 'default' | 'destructive'variant: 'ghost-accent' | 'secondary-accent',tone?: 'default'
| Attribute | Description |
|---|---|
data-disabled | Present when the button is disabled. |
buttonVariants
| Parameter | Type | Description |
|---|---|---|
props | (ConfigVariants<{ variant: { primary: string[]; secondary: string[]; 'secondary-accent': string[]; tertiary: string[]; ghost: string[]; 'ghost-accent': string[]; }; size: { small: string; medium: string; large: string; }; tone: { default: string; destructive: string; }; }> & ClassProp) | No description |
Returns
string