Demos

Default is the primary action. Outline and ghost are quieter. Destructive is for a harmful action. Link looks like text.

Usage

Use a button for an action on the current page: save, open, delete, or continue. If the control navigates to another URL, render it as a link. One primary button per section is enough. The rest should be outline, secondary, or ghost.

Import it from @workspace/ui/components/button.

Anatomy

  • Button — variant is default, outline, outlineglass, secondary, ghost, destructive, link, or invert. size is sm, default, lg, icon-sm, icon, or icon-lg.
  • buttonVariants — The class function behind Button. Use it to style another element, such as a link, as a button.

Notes

  • Icon-only buttons need an aria-label. The icon is not a name.
  • Put data-icon="inline-start" or data-icon="inline-end" on an icon so the padding stays even.
  • Disabled buttons stay visible. Do not hide an action the reader is not allowed to take. Explain why nearby if it is not obvious.
  • To make a button navigate, set nativeButton={false} and pass an anchor through render.

Examples

Outline

A quieter action next to a primary one. outlineglass is the same with a soft inner shadow.

Secondary

For actions that matter less than the primary one.

Ghost

No border or fill until hover. Use in toolbars and dense rows.

Destructive

For actions that delete or cannot be undone.

Looks like text. Use for low-weight navigation.

For navigation, render an a through render and set nativeButton={false}.

Invert

Uses the foreground colour as the fill.

Sizes

sm, default, and lg, plus a matching icon size for each.

Icon

An icon-only button. Always give it an aria-label.

With icon

Mark the icon with data-icon so the padding adjusts on that side.

Disabled

Disabled buttons fade and ignore clicks.

Props

These are the props you set most often. Unlisted props pass through to the underlying element.

Button

PropTypeDefaultDescription
variant"default", "outline", "outlineglass", "secondary", "ghost", "destructive", "link", or "invert"defaultEmphasis of the action.
size"sm", "default", "lg", "icon-sm", "icon", or "icon-lg"defaultHeight and padding.
disabledbooleanfalseBlocks the action and dims the button.
nativeButtonbooleantrueSet false when render is not a button, such as a link.
renderReactElement—Element to render instead of a button.
classNamestring—Classes merged onto the element.