Web · Components
Button
A button that starts an action, or a link that looks like a button.
Live example
Import
A button that starts an action, or a link that looks like a button.
- The look has two axes:
variantsets the style,tonethe meaning (color). Every combination like<Button variant="soft" tone="danger">is valid. - If
onClickreturns a Promise the button shows loading automatically; no need to keep a separateloadingstate. - With
hrefit becomes a link; Next.jsLinkis given once toUIProvider, noasChildneeded. - When
typeis omitted it is"button", so it doesn't submit a form by accident. UseSubmitButtonto submit a form. - Use
IconButtonfor icon-only buttons. tooltipadds a tooltip; it also works on a disabled button.shapepicks the corner shape (rounded,pill,sharp),effectthe effect (ripple,pulse,bounce,glow,tilt,beam…). For app-wide style, color, size and effect useUIProviderappearance.defaults.button; for your own stylesappearance.variants.button(defineAppearance).- Inside a
ButtonGroup,variant,tone,sizeanddisablednot given come from the group.
Examples
A square icon-only button. With size it has the same height as text buttons; the default style is ghost (the group's style inside a ButtonGroup).
Examples
Groups related buttons together as one piece: toolbars, split buttons (Save + ▾), view switchers, alignment and format buttons.
- Two ways to use: put your own
Button/IconButton/Menuelements withchildren; or pass theitemsarray and the group draws the buttons itself. Selection mode, split buttons and the "More" menu work withitems. variant,tone,size,disabledpass to all buttons inside; a button's own value wins.- Attached (default): inner corners go away, borders overlap and a thin line separates filled buttons. With
attached={false}they are spaced. - Selection mode:
selection="single"is single-select,"multiple"multi-select; pressed buttons carryaria-pressedand look highlighted. - Split button: when an item has
menu, that button opens a menu. - Keyboard: ←/→ (↑/↓ when vertical) move between buttons, Home/End go to the first and last; the direction flips on right-to-left pages.
- Mobile: with
overflow="menu", buttons that don't fit on narrow screens move into the trailing ⋯ menu (which opens as a bottom sheet); it recomputes when the width changes (rotation, side panel), and since measurements are cached the buttons don't flicker. Touch areas are at least 44 px, as on buttons.
Examples
ButtonAsButtonProps
interfaceProps of a Button rendered as <button>.
Extends: Omit<ComponentProps<"button">, "onClick">
| Name | Type | Default | Description |
|---|---|---|---|
href? | undefined | Not given to render as a button; when given see ButtonAsLinkProps. | |
onClick? | (event: MouseEvent<HTMLButtonElement>) => unknown | Called on click. If it returns a Promise (e.g. an async function) the button automatically shows "loading" until the Promise settles and a second click is blocked. | |
effect? | ButtonEffect | Effect or effects: on press scale, ripple, pulse, bounce; on hover lift, border, beam, glow, tilt, shine; or a custom effect added with defineAppearance. Can be combined as an array (["ripple", "glow"]). Defaults to UIProvider appearance.defaults.button.effect, otherwise scale (none for the link style). On keyboard press the effect plays from the button's center. See ButtonEffect. | |
icon? | IconProp | Icon at the start of the text: a name ("save") or an element. While loading a spinner takes its place, so the button doesn't shift. | |
iconEnd? | IconProp | Icon at the end of the text (e.g. an arrow). | |
loading? | boolean | Shows the loading state manually: a spinner appears, the button locks and aria-busy is set. Not needed when onClick returns a Promise; the button does this itself. | |
tooltip? | TooltipProp | Tooltip shown on hover, keyboard focus or long press on touch screens: text, content or settings ({ content, side, delay }). Also visible while the button is disabled; good for explaining why it can't be clicked. See TooltipProp. | |
variant? | ButtonVariant | CustomVariant<"button"> | undefined | "solid" | Style: one of the built-in styles or a custom style added with defineAppearance. |
tone? | ButtonTone | undefined | Color. Defaults to "neutral" for outline, ghost, elevated and dashed, and "primary" for the other styles. | |
size? | ButtonSize | undefined | "md" | Height. |
shape? | ButtonShape | undefined | "rounded" | Corner shape. |
block? | boolean | undefined | Takes the full width of its area. |
ButtonAsLinkProps
interfaceProps of a Button rendered as a link.
Extends: Omit<ComponentProps<"a">, "href">
| Name | Type | Default | Description |
|---|---|---|---|
href | string | When given the button becomes a link. Internal URLs are drawn with the link component given to UIProvider (e.g. Next.js Link), external URLs like https: or mailto: with a plain <a>. | |
disabled? | boolean | Shows the link as disabled; not clickable and not keyboard selectable. | |
effect? | ButtonEffect | Effect or effects: on press scale, ripple, pulse, bounce; on hover lift, border, beam, glow, tilt, shine; or a custom effect added with defineAppearance. Can be combined as an array (["ripple", "glow"]). Defaults to UIProvider appearance.defaults.button.effect, otherwise scale (none for the link style). On keyboard press the effect plays from the button's center. See ButtonEffect. | |
icon? | IconProp | Icon at the start of the text: a name ("save") or an element. While loading a spinner takes its place, so the button doesn't shift. | |
iconEnd? | IconProp | Icon at the end of the text (e.g. an arrow). | |
loading? | boolean | Shows the loading state manually: a spinner appears, the button locks and aria-busy is set. Not needed when onClick returns a Promise; the button does this itself. | |
tooltip? | TooltipProp | Tooltip shown on hover, keyboard focus or long press on touch screens: text, content or settings ({ content, side, delay }). Also visible while the button is disabled; good for explaining why it can't be clicked. See TooltipProp. | |
variant? | ButtonVariant | CustomVariant<"button"> | undefined | "solid" | Style: one of the built-in styles or a custom style added with defineAppearance. |
tone? | ButtonTone | undefined | Color. Defaults to "neutral" for outline, ghost, elevated and dashed, and "primary" for the other styles. | |
size? | ButtonSize | undefined | "md" | Height. |
shape? | ButtonShape | undefined | "rounded" | Corner shape. |
block? | boolean | undefined | Takes the full width of its area. |
ButtonProps
typeProps of the Button component.
Extends: Omit<ComponentProps<"button">, "onClick"> | Omit<ComponentProps<"a">, "href">
| Name | Type | Default | Description |
|---|---|---|---|
href? | undefined | string | Not given to render as a button; when given see ButtonAsLinkProps. | |
onClick? | (event: MouseEvent<HTMLButtonElement>) => unknown | Called on click. If it returns a Promise (e.g. an async function) the button automatically shows "loading" until the Promise settles and a second click is blocked.(ButtonAsButtonProps) | |
effect? | ButtonEffect | Effect or effects: on press scale, ripple, pulse, bounce; on hover lift, border, beam, glow, tilt, shine; or a custom effect added with defineAppearance. Can be combined as an array (["ripple", "glow"]). Defaults to UIProvider appearance.defaults.button.effect, otherwise scale (none for the link style). On keyboard press the effect plays from the button's center. See ButtonEffect. | |
icon? | IconProp | Icon at the start of the text: a name ("save") or an element. While loading a spinner takes its place, so the button doesn't shift. | |
iconEnd? | IconProp | Icon at the end of the text (e.g. an arrow). | |
loading? | boolean | Shows the loading state manually: a spinner appears, the button locks and aria-busy is set. Not needed when onClick returns a Promise; the button does this itself. | |
tooltip? | TooltipProp | Tooltip shown on hover, keyboard focus or long press on touch screens: text, content or settings ({ content, side, delay }). Also visible while the button is disabled; good for explaining why it can't be clicked. See TooltipProp. | |
variant? | ButtonVariant | CustomVariant<"button"> | undefined | "solid" | Style: one of the built-in styles or a custom style added with defineAppearance. |
tone? | ButtonTone | undefined | Color. Defaults to "neutral" for outline, ghost, elevated and dashed, and "primary" for the other styles. | |
size? | ButtonSize | undefined | "md" | Height. |
shape? | ButtonShape | undefined | "rounded" | Corner shape. |
block? | boolean | undefined | Takes the full width of its area. | |
disabled? | boolean | Shows the link as disabled; not clickable and not keyboard selectable.(ButtonAsLinkProps) |
IconButtonProps
typeProps of the IconButton component.
Extends: Omit<Omit<ComponentProps<"button">, "onClick">, "children" | "iconEnd" | "block"> | Omit<Omit<ComponentProps<"a">, "href">, "children" | "iconEnd" | "block">
| Name | Type | Default | Description |
|---|---|---|---|
href? | undefined | string | Not given to render as a button; when given see ButtonAsLinkProps. | |
onClick? | (event: MouseEvent<HTMLButtonElement>) => unknown | Called on click. If it returns a Promise (e.g. an async function) the button automatically shows "loading" until the Promise settles and a second click is blocked.(ButtonAsButtonProps) | |
effect? | ButtonEffect | Effect or effects: on press scale, ripple, pulse, bounce; on hover lift, border, beam, glow, tilt, shine; or a custom effect added with defineAppearance. Can be combined as an array (["ripple", "glow"]). Defaults to UIProvider appearance.defaults.button.effect, otherwise scale (none for the link style). On keyboard press the effect plays from the button's center. See ButtonEffect. | |
icon? | IconProp | Icon at the start of the text: a name ("save") or an element. While loading a spinner takes its place, so the button doesn't shift. | |
loading? | boolean | Shows the loading state manually: a spinner appears, the button locks and aria-busy is set. Not needed when onClick returns a Promise; the button does this itself. | |
tooltip? | TooltipProp | Tooltip shown on hover, keyboard focus or long press on touch screens: text, content or settings ({ content, side, delay }). Also visible while the button is disabled; good for explaining why it can't be clicked. See TooltipProp. | |
variant? | ButtonVariant | CustomVariant<"button"> | undefined | "solid" | Style: one of the built-in styles or a custom style added with defineAppearance. |
tone? | ButtonTone | undefined | Color. Defaults to "neutral" for outline, ghost, elevated and dashed, and "primary" for the other styles. | |
size? | ButtonSize | undefined | "md" | Height. |
shape? | ButtonShape | undefined | "rounded" | Corner shape. |
disabled? | boolean | Shows the link as disabled; not clickable and not keyboard selectable.(ButtonAsLinkProps) | |
label | string | Name of the button. Screen readers read it; it shows as a Tooltip * on hover, keyboard focus or long press on touch screens. Required, because * an icon alone isn't a name. |
ButtonGroupItem
interfaceA button in the ButtonGroup items array.
| Name | Type | Description |
|---|---|---|
value? | V | Id of the item. In selection mode (selection) this is the selected value; also used as the React key. Required in selection mode. |
label | ReactNode | Button text. With iconOnly it must be text; it becomes the screen reader name and tooltip. |
icon? | IconProp | Icon at the start of the text: a name or an element. |
iconEnd? | IconProp | Icon at the end of the text. |
iconOnly? | boolean | Shows only the icon (square button, IconButton); label becomes the screen reader name and tooltip. |
tone? | ButtonTone | Color of this button; defaults to the group's color. |
disabled? | boolean | Not clickable. Locks this item regardless of the group's disabled value. |
loading? | boolean | Loading state. Automatic when onClick returns a Promise. |
tooltip? | TooltipProp | Tooltip. See TooltipProp. |
href? | string | When given the button becomes a link (same as Button href). |
onClick? | (event: MouseEvent<HTMLElement>) => unknown | Called on click. If it returns a Promise the button shows loading automatically. In selection mode it is called after the selection changes. If the item moved into the "More" menu, it is also called when chosen there. |
menu? | readonly MenuEntry[] | When given the button opens a menu (like the arrow part of a split button). See MenuEntry. |
className? | string | Classes added to the button. |
What happens to buttons that don't fit in the group.
"none": nothing; buttons stay on one line."wrap": wrap to the next line. Only meaningful withattached={false}."menu": those that don't fit move into a trailing "More actions" (⋯) menu. The group takes the full width of its area. Works only withitemsand in a horizontal group.
ButtonGroupProps
typeProps of the ButtonGroup component: an action group, a single-select or a multi-select group.
Extends: Omit<ComponentProps<"div">, "children" | "defaultValue" | "onChange"> | Omit<Omit<ComponentProps<"div">, "children" | "defaultValue" | "onChange">, "items">
| Name | Type | Default | Description |
|---|---|---|---|
selection? | undefined | "single" | "multiple" | Selection mode off. | |
value? | undefined | V | null | V[] | Only in selection mode. | |
defaultValue? | undefined | V | null | V[] | Only in selection mode. | |
onValueChange? | undefined | (value: V | null) => void | (value: V[]) => void | Only in selection mode. | |
required? | undefined | boolean | boolean | Only in selection mode. | |
variant? | ButtonVariant | Style of the buttons inside (a button's own variant wins). | |
tone? | ButtonTone | Color of the buttons inside. | |
size? | ButtonSize | Height of the buttons inside. | |
disabled? | boolean | Disables all buttons. | |
orientation? | "horizontal" | "vertical" | "horizontal" | Layout direction. |
attached? | boolean | true | Are the buttons attached? When true the inner corners go away and borders merge; when false there is space between buttons. |
block? | boolean | Takes the full width of its area; buttons share the space equally. | |
label? | string | Screen reader name of the group (e.g. "Text alignment"). | |
overflow? | ButtonGroupOverflow | "none" | What happens to buttons that don't fit. See ButtonGroupOverflow. |
items? | readonly ButtonGroupItem[] | readonly ButtonGroupItem<V>[] | readonly ButtonGroupItem<V>[] | Buttons as an array. Selection mode, split buttons (menu) and overflow="menu" work this way. When omitted, children is rendered. | |
children? | ReactNode | Your own buttons: Button, IconButton, Menu with a button trigger. variant, tone, size, disabled not given come from the group. |
ButtonVariant
typeButton style: how "heavy" it looks.
solid: filled background; the main action on the page.soft: light tinted background; a secondary but colored action.outline: bordered; a secondary action.ghost: no background; toolbars and lists.link: underlined text like a link.gradient: a slightly bright gradient from the tone's color; an eye-catching filled button for showcase and campaign actions.elevated: a shadowed card button raised from the surface; rises a bit on hover.dashed: dashed border; placeholder actions like "add" or "create new".
ButtonShape
typeCorner shape of the button.
rounded: the theme's corner radius (--ui-radius).pill: a fully rounded pill; a circle for icon buttons.sharp: no rounding, sharp corners.
ButtonEffect
typeButton effect or effects. Given to the Button effect prop or app-wide with UIProvider appearance.defaults.button.effect. The default is scale (none for the link style).
All built-in effects work on buttons and can be combined (["ripple", "glow"]): on press scale, ripple, pulse, bounce; on hover lift, border, beam, glow, tilt, shine. See BuiltinEffect. Effects don't play with the "reduced motion" preference. Their colors come from the button's own color; compatible with every variant and tone.
ButtonTone
typeButton color: the meaning of the action. See Tone.
ButtonSize
typeButton height: sm 32 px, md 40 px, lg 48 px.
ButtonStyleOptions
interfaceOptions of the buttonVariants function.
| Name | Type | Default | Description |
|---|---|---|---|
variant? | ButtonVariant | CustomVariant<"button"> | undefined | "solid" | Style: one of the built-in styles or a custom style added with defineAppearance. |
tone? | ButtonTone | undefined | Color. Defaults to "neutral" for outline, ghost, elevated and dashed, and "primary" for the other styles. | |
size? | ButtonSize | undefined | "md" | Height. |
shape? | ButtonShape | undefined | "rounded" | Corner shape. |
effect? | ButtonEffect | undefined | "scale" | Effect. The classes only carry the scale effect (CSS); Button draws the other effects itself. The default is none for the link style. |
appearance? | AppearanceConfig | undefined | Appearance settings from which custom styles are read. Defaults to the app-wide registry (getAppearance). | |
square? | boolean | undefined | Square button (icon only). IconButton sets this itself. | |
block? | boolean | undefined | Takes the full width of its area. | |
className? | ClassValue | Classes to add; these win on conflicts. |