Skip to content

Button

A button that triggers an action, with Dify variants, sizes and a pending state.

hero.tsx

Usage guidelines

  • Use Button for an action with a visible text label. An icon-only command uses IconButton, a persistent pressed state uses Toggle, and navigation uses a native link.
  • Keep one primary button per surface for the action the user most likely wants. Supporting actions use secondary; low-emphasis actions in toolbars and dense rows use ghost or tertiary.
  • 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.
  • Button renders type="button". Set type="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 with buttonVariants.
  • Use render with nativeButton={false} only when a non-button element intentionally needs button semantics. It is not a link mode.
  • Use loading for an action that was triggered and is now pending, and disabled for an action that is unavailable. They are separate facts and can both apply: pass the pending state only to loading and keep independent availability conditions in disabled.
  • Pass focusableWhenDisabled={false} only when a loading button should opt into native disabled behavior and may leave the tab order. Pass focusableWhenDisabled on a disabled button 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.
  • Button does not add aria-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

tsx
tsx

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".

Default
Accent
Destructive
variants.tsx

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.

sizes.tsx

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.

loading.tsx

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.

disabled.tsx

Keep navigation on a native anchor or router link and apply buttonVariants to reuse the button appearance without turning the link into a button.

link.tsx

Keyboard

KeyAction
EnterActivates the button.
SpaceActivates the button.
TabMoves 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.

Base UI Button docs

Props
PropTypeDefaultDetails
size'large' | 'medium' | 'small''medium'
variant'ghost' | 'ghost-accent' | 'primary' | 'secondary' | 'secondary-accent' | 'tertiary''secondary'
tone'default' | 'destructive''default'
loadingbooleanNo default
Base UI Button docs

Valid prop combinations:

  • variant?: 'ghost' | 'primary' | 'secondary' | 'tertiary', tone?: 'default' | 'destructive'
  • variant: 'ghost-accent' | 'secondary-accent', tone?: 'default'
Data attributes
AttributeDescription
data-disabled

Present when the button is disabled.

buttonVariants

Parameters
ParameterTypeDescription
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