<!-- index: /slotted/llms.txt -->
# button

`data-ui="button"` · Button, link button, icon button and toggle button.

## Import

```tsx
import {
  Button,
  ButtonDefaultsProvider,
  ButtonLink,
  IconButton,
  ToggleButton,
} from '@slotted/react';
```

## Minimal example

Example

```tsx
import { Button } from '@slotted/react/button';

export default function ButtonBasic() {
  return <Button onClick={() => console.log('saved')}>Save changes</Button>;
}
```

## Anatomy

### button

| Part | Element | Required |
| --- | --- | --- |
| `root` | button, or the element render returns | yes |
| `start` | span | no |
| `label` | span | yes |
| `end` | span | no |
| `indicator` | span with role="progressbar" | no |

### buttonLink

| Part | Element | Required |
| --- | --- | --- |
| `root` | a, or the element render returns | yes |
| `start` | span | no |
| `label` | span | yes |
| `end` | span | no |

### iconButton

| Part | Element | Required |
| --- | --- | --- |
| `root` | button, or the element render returns | yes |
| `icon` | span | yes |
| `indicator` | span with role="progressbar" | no |

### iconButtonLink

| Part | Element | Required |
| --- | --- | --- |
| `root` | a, or the element render returns | yes |
| `icon` | span | yes |

### toggleButton

| Part | Element | Required |
| --- | --- | --- |
| `root` | button, or the element render returns | yes |
| `start` | span | no |
| `label` | span | yes |
| `end` | span | no |
| `indicator` | span with role="progressbar" | no |

## Props

### button

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `tone` | `accent \| secondary \| neutral \| info \| success \| warning \| danger` | accent | Button | The semantic color: accent for the primary action, secondary for a neutral one, neutral for a primary action drawn in ink where the accent is kept for data, and success, warning or danger for what the action does. |
| `variant` | `solid \| outline \| ghost` | solid | Button | How the tone is painted: solid, outline or ghost. |
| `size` | `sm \| md \| lg` | md | Button | The step of the control scale. Each step reads the --slotted-control-* tokens, so the density of the theme sets the height. |
| `start` | `ReactNode` | — | Button | Content before the label, such as an icon. It mirrors in a right-to-left document. |
| `end` | `ReactNode` | — | Button | Content after the label, such as an icon. It mirrors in a right-to-left document. |
| `fullWidth` | `boolean` | false | Button | Fills the inline size of the container. |
| `flush` | `'start' \| 'end' \| 'both'` | — | Button | Stands the label on the edge of the text around it: the button is pulled out by its own inset on the stated side, and the hover ground, the target and the focus ring extend past that edge. For a ghost button as the first line of a stacked cell. It has no effect on an inline button, which has no inset. |
| `inline` | `boolean` | false | Button | A word of the surrounding text, for an action inside a sentence or a dense cell: no box in any variant, the font, line height and baseline of the text around it, underlined in the tone. A stated size sets the step of the text scale (--slotted-font-size-sm, -md, -lg); without one the font is the one around it, whatever a provider states. A row of small text keeps its height. |
| `justify` | `center \| between` | center | Button | Where the content sits along the inline axis: center keeps the label and end together in the middle; between sets the label at the start and end at the inline end, as a field trigger reads, with start beside the label. It mirrors in a right-to-left document. |
| `widest` | `readonly string[]` | — | Button | Every text the label can take, for a label that changes under the pointer (the month of a stepper): the control reserves the width of its whole content with the widest of them, in tabular figures, and centers what is visible. A start that renders nothing keeps its room in the reservation and takes none beside the label, so a mark comes and goes at one width; --slotted-button-widest-start states the width reserved for a start narrower than an icon. The entries stay out of the accessible name; no effect under fullWidth. |
| `disabled` | `boolean` | false | Button | Refuses the action and marks the control unavailable. On its own, it sets the native disabled attribute, which also removes the control from the tab sequence. |
| `focusableWhenDisabled` | `boolean` | false | Button | Keeps a disabled control in the tab sequence: aria-disabled replaces the native attribute, and activation is still refused. |
| `loading` | `boolean` | false | Button | Refuses activation, keeps focus, and shows a progress indicator named by messages.loading. |
| `loadingDelay` | `number` | 0 | Button | Milliseconds before the indicator appears. Activation is refused from the start of the wait. |
| `messages` | `Partial<ButtonMessages>` | — | Button | Overrides for the strings of the active locale, key by key. loading names the progress indicator. |
| `render` | `(rootProps) => ReactElement` | — | Button | Renders the root through another element. The function receives every root prop and must pass all of them on. |
| `type` | `button \| submit \| reset` | button | Button | The native button type. Set submit only for a button that submits its form. |
| `ButtonDefaultsProvider` | `{ size?, tone?, variant?, children }` | — | Button | Sets the default size, tone and variant of every button inside it, ButtonLink, IconButton and ToggleButton included. An explicit prop wins, and an axis left unset keeps each member’s own default. |

### buttonLink

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `href` | `string` | required without render | ButtonLink | The destination. A disabled ButtonLink does not render it. |
| `render` | `(rootProps) => ReactElement` | — | ButtonLink | Renders the root through a router’s link component. The function receives every root prop and must pass all of them on. |
| `tone` | `accent \| secondary \| neutral \| info \| success \| warning \| danger` | accent | ButtonLink | The semantic color: accent for the primary action, secondary for a neutral one, neutral for a primary action drawn in ink where the accent is kept for data, and success, warning or danger for what the action does. |
| `variant` | `solid \| outline \| ghost` | solid | ButtonLink | How the tone is painted: solid, outline or ghost. |
| `size` | `sm \| md \| lg` | md | ButtonLink | The step of the control scale. Each step reads the --slotted-control-* tokens, so the density of the theme sets the height. |
| `start` | `ReactNode` | — | ButtonLink | Content before the label, such as an icon. It mirrors in a right-to-left document. |
| `end` | `ReactNode` | — | ButtonLink | Content after the label, such as an icon. It mirrors in a right-to-left document. |
| `fullWidth` | `boolean` | false | ButtonLink | Fills the inline size of the container. |
| `justify` | `center \| between` | center | ButtonLink | Where the content sits along the inline axis: center keeps the label and end together in the middle; between sets the label at the start and end at the inline end, as a field trigger reads, with start beside the label. It mirrors in a right-to-left document. |
| `widest` | `readonly string[]` | — | ButtonLink | Every text the label can take, for a label that changes under the pointer (the month of a stepper): the control reserves the width of its whole content with the widest of them, in tabular figures, and centers what is visible. A start that renders nothing keeps its room in the reservation and takes none beside the label, so a mark comes and goes at one width; --slotted-button-widest-start states the width reserved for a start narrower than an icon. The entries stay out of the accessible name; no effect under fullWidth. |
| `disabled` | `boolean` | false | ButtonLink | Removes the href and refuses activation. The link stays focusable with role="link" and aria-disabled. |

### iconButton

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `aria-label \| aria-labelledby` | `string` | required | IconButton | The accessible name. Required, because an icon supplies no text. When both are present, aria-labelledby names the button. |
| `tone` | `accent \| secondary \| neutral \| info \| success \| warning \| danger` | secondary | IconButton | The semantic color: accent for the primary action, secondary for a neutral one, neutral for a primary action drawn in ink where the accent is kept for data, and success, warning or danger for what the action does. |
| `variant` | `solid \| outline \| ghost` | ghost | IconButton | How the tone is painted: solid, outline or ghost. |
| `size` | `sm \| md \| lg` | md | IconButton | The step of the control scale. Each step reads the --slotted-control-* tokens, so the density of the theme sets the height. |
| `shape` | `square \| circle` | square | IconButton | The corners of the control: square keeps the radius of the control scale, circle rounds it fully. Both are as wide as they are tall. |
| `inline` | `boolean` | false | IconButton | One line of the surrounding text tall, for a help trigger inside a sentence or a term: the line does not grow, and a 24px target stays around it. The icon is drawn from the capital height of the text, centered on the capital beside it, and the size of the Icon has no effect; in a flex row, align-items: baseline puts it on the first line. In ghost it draws no ground under the pointer; in the secondary tone it is muted at rest and takes the text color on hover, on keyboard focus and while its tooltip or popover is open. |
| `disabled` | `boolean` | false | IconButton | Refuses the action and marks the control unavailable. On its own, it sets the native disabled attribute, which also removes the control from the tab sequence. |
| `focusableWhenDisabled` | `boolean` | false | IconButton | Keeps a disabled control in the tab sequence: aria-disabled replaces the native attribute, and activation is still refused. |
| `loading` | `boolean` | false | IconButton | Refuses activation, keeps focus, and shows a progress indicator named by messages.loading. |
| `loadingDelay` | `number` | 0 | IconButton | Milliseconds before the indicator appears. Activation is refused from the start of the wait. |
| `messages` | `Partial<ButtonMessages>` | — | IconButton | Overrides for the strings of the active locale, key by key. loading names the progress indicator. |
| `render` | `(rootProps) => ReactElement` | — | IconButton | Renders the root through another element. The function receives every root prop and must pass all of them on. |
| `pressed` | `boolean` | — | IconButton | The pressed state, controlled. Passing it makes the button a toggle whose value you own. |
| `defaultPressed` | `boolean` | — | IconButton | The initial pressed state when the button owns it, read once. Passing it makes the button a toggle. |
| `onPressedChange` | `(pressed, request) => void` | — | IconButton | Called with the requested value and the request: value, previous value, reason (pointer or keyboard), event and cancel(). |
| `type` | `button \| submit \| reset` | button | IconButton | The native button type. Set submit only for a button that submits its form. |

### iconButtonLink

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `aria-label \| aria-labelledby` | `string` | required | IconButtonLink | The accessible name. Required, because an icon supplies no text. When both are present, aria-labelledby names the link. |
| `href` | `string` | required without render | IconButtonLink | The destination. A disabled IconButtonLink does not render it. |
| `render` | `(rootProps) => ReactElement` | — | IconButtonLink | Renders the root through a router’s link component. The function receives anchor props — every root prop — and must pass all of them on. |
| `tone` | `accent \| secondary \| neutral \| info \| success \| warning \| danger` | secondary | IconButtonLink | The semantic color: accent for the primary action, secondary for a neutral one, neutral for a primary action drawn in ink where the accent is kept for data, and success, warning or danger for what the action does. |
| `variant` | `solid \| outline \| ghost` | ghost | IconButtonLink | How the tone is painted: solid, outline or ghost. |
| `size` | `sm \| md \| lg` | md | IconButtonLink | The step of the control scale. Each step reads the --slotted-control-* tokens, so the density of the theme sets the height. |
| `shape` | `square \| circle` | square | IconButtonLink | The corners of the control: square keeps the radius of the control scale, circle rounds it fully. Both are as wide as they are tall. |
| `disabled` | `boolean` | false | IconButtonLink | Removes the href and refuses activation. The link stays focusable with role="link" and aria-disabled. |

### toggleButton

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `tone` | `accent \| secondary \| neutral \| info \| success \| warning \| danger` | secondary | ToggleButton | The semantic color: accent for the primary action, secondary for a neutral one, neutral for a primary action drawn in ink where the accent is kept for data, and success, warning or danger for what the action does. |
| `variant` | `solid \| outline \| ghost` | outline | ToggleButton | How the tone is painted: solid, outline or ghost. |
| `size` | `sm \| md \| lg` | md | ToggleButton | The step of the control scale. Each step reads the --slotted-control-* tokens, so the density of the theme sets the height. |
| `start` | `ReactNode` | — | ToggleButton | Content before the label, such as an icon. It mirrors in a right-to-left document. |
| `end` | `ReactNode` | — | ToggleButton | Content after the label, such as an icon. It mirrors in a right-to-left document. |
| `fullWidth` | `boolean` | false | ToggleButton | Fills the inline size of the container. |
| `justify` | `center \| between` | center | ToggleButton | Where the content sits along the inline axis: center keeps the label and end together in the middle; between sets the label at the start and end at the inline end, as a field trigger reads, with start beside the label. It mirrors in a right-to-left document. |
| `widest` | `readonly string[]` | — | ToggleButton | Every text the label can take, for a label that changes under the pointer (the month of a stepper): the control reserves the width of its whole content with the widest of them, in tabular figures, and centers what is visible. A start that renders nothing keeps its room in the reservation and takes none beside the label, so a mark comes and goes at one width; --slotted-button-widest-start states the width reserved for a start narrower than an icon. The entries stay out of the accessible name; no effect under fullWidth. |
| `disabled` | `boolean` | false | ToggleButton | Refuses the action and marks the control unavailable. On its own, it sets the native disabled attribute, which also removes the control from the tab sequence. |
| `focusableWhenDisabled` | `boolean` | false | ToggleButton | Keeps a disabled control in the tab sequence: aria-disabled replaces the native attribute, and activation is still refused. |
| `loading` | `boolean` | false | ToggleButton | Refuses activation, keeps focus, and shows a progress indicator named by messages.loading. |
| `loadingDelay` | `number` | 0 | ToggleButton | Milliseconds before the indicator appears. Activation is refused from the start of the wait. |
| `messages` | `Partial<ButtonMessages>` | — | ToggleButton | Overrides for the strings of the active locale, key by key. loading names the progress indicator. |
| `render` | `(rootProps) => ReactElement` | — | ToggleButton | Renders the root through another element. The function receives every root prop and must pass all of them on. |
| `pressed` | `boolean` | — | ToggleButton | The pressed state, controlled. Passing it makes you the owner of the value. |
| `defaultPressed` | `boolean` | false | ToggleButton | The initial pressed state when the button owns it, read once. |
| `onPressedChange` | `(pressed, request) => void` | — | ToggleButton | Called with the requested value and the request: value, previous value, reason (pointer or keyboard), event and cancel(). |
| `type` | `button \| submit \| reset` | button | ToggleButton | The native button type. Set submit only for a button that submits its form. |

## Axes and defaults

| Axis | Values | Default |
| --- | --- | --- |
| `tone` | `accent`, `secondary`, `neutral`, `info`, `success`, `warning`, `danger` | `accent`, `secondary` |
| `variant` | `solid`, `outline`, `ghost` | `solid`, `ghost`, `outline` |
| `size` | `sm`, `md`, `lg` | `md` |
| `shape` | `square`, `circle` | `square` |
| `justify` | `center`, `between` | `center` |
| `flush` | `start`, `end`, `both` | — |

## Rules

- Button renders a native button element, so Space, Enter, focus and the disabled state come from the platform. The visible label supplies the accessible name.
- While loading, the indicator is a progress bar named by messages.loading, and the button announces aria-disabled while it keeps focus. React Aria’s pending button and Primer’s loading button use the same pattern. aria-busy is not set: screen readers do not announce it reliably on a button, and one mechanism already carries the state.
- Where motion is allowed, the indicator is not drawn: once loadingDelay has passed, a band in the button’s own ink sweeps behind the label and the icon, which stay visible. With reduced motion or forced colors, the indicator is a ring drawn in the start or end icon’s box; a button with neither draws it over the label, which drops to zero opacity but stays in the accessibility tree and in the layout, so the accessible name survives the wait and the button keeps its size.
- loading refuses activation in the capture phase, before any click handler you attach, so a submit button cannot submit its form twice.
- focusableWhenDisabled keeps a disabled button reachable. Use it when the button has a tooltip or an explanation a keyboard user needs, such as inside a toolbar. A reachable disabled button uses muted text on the subtle neutral background, at a contrast of 4.5:1 or more; a natively disabled button keeps the disabled grey.
- An icon in start or end repeats the label, so mark it aria-hidden. Glyph sets aria-hidden itself.
- type defaults to button. Set submit only for a button that submits its form.
- ButtonLink renders an anchor, so it is announced as a link and activates on Enter. Space does not activate it, as it does not activate any link.
- Use ButtonLink for navigation only. An action without a destination is a Button.
- A disabled ButtonLink renders no href. An anchor that kept its destination and only blocked click would still navigate on a middle click or a modified click.
- A disabled ButtonLink stays in the tab sequence with role="link" and aria-disabled, so a keyboard user can discover that it is unavailable.
- The render function receives every root prop, including the accessible name and the data attributes, and must pass all of them to the element it renders.
- The type requires an accessible name: pass aria-label or aria-labelledby. An icon supplies no text the name could be computed from.
- aria-pressed is rendered only when pressed or defaultPressed is passed, so a plain icon button does not announce a toggle state it does not have.
- Keep the name the same in both pressed states. The APG toggle button pattern announces the state beside an unchanging label.
- A pressed icon button uses the selected colors of the theme — accent text on the accent selection background, inside the accent edge — whatever its tone and variant. On hover it uses the hover step of that background, not the neutral hover of an unpressed button.
- The control is as wide as it is tall, at the control height, and never smaller than the WCAG 2.2 minimum target of 24 by 24 CSS pixels at any density.
- Add a tooltip when the icon alone does not say what the action does. The accessible name does not replace a visible label.
- IconButtonLink renders an anchor, so it is announced as a link and activates on Enter. Use it for an icon-only control that navigates, such as the previous and next record; an icon-only action is an IconButton.
- A disabled IconButtonLink renders no href and stays in the tab sequence with role="link" and aria-disabled.
- ToggleButton renders a native button with aria-pressed, so it is announced as a toggle button and activates on Space and Enter.
- Keep the label the same in both states: "Mute" stays "Mute" and the state is announced beside it. When the label has to change, use a Button.
- The change request carries a reason. A native button fires the same click for a pointer, Space and Enter; the reason is pointer when the click reports a click count and keyboard when it reports none.
- Calling preventDefault in onClick refuses the activation, and the pressed state does not change.
- Use Checkbox, not ToggleButton, for a value a form submits.
- A toggle that saves to a server can set loading while the request runs. Activation is refused during the wait, so the button keeps the state it had until loading ends.

## Tokens

`--slotted-border-subtle`, `--slotted-border-width-thin`, `--slotted-button-widest-start`, `--slotted-control-border-color`, `--slotted-control-border-width`, `--slotted-control-font-family`, `--slotted-control-font-size-lg`, `--slotted-control-font-size-md`, `--slotted-control-font-size-sm`, `--slotted-control-font-weight`, `--slotted-control-gap-lg`, `--slotted-control-gap-md`, `--slotted-control-gap-sm`, `--slotted-control-height-lg`, `--slotted-control-height-md`, `--slotted-control-height-sm`, `--slotted-control-icon-size-lg`, `--slotted-control-icon-size-md`, `--slotted-control-icon-size-sm`, `--slotted-control-letter-spacing`, `--slotted-control-line-height`, `--slotted-control-padding-inline-lg`, `--slotted-control-padding-inline-md`, `--slotted-control-padding-inline-sm`, `--slotted-control-radius`, `--slotted-control-shadow`, `--slotted-control-transition-duration`, `--slotted-control-transition-easing`, `--slotted-disabled-background`, `--slotted-disabled-border`, `--slotted-disabled-foreground`, `--slotted-duration-instant`, `--slotted-duration-loop`, `--slotted-focus-ring-color`, `--slotted-focus-ring-offset`, `--slotted-focus-ring-width`, `--slotted-font-size-lg`, `--slotted-font-size-md`, `--slotted-font-size-sm`, `--slotted-line-height-sm`, `--slotted-radius-full`, `--slotted-radius-sm`, `--slotted-space-2`, `--slotted-target-min`, `--slotted-text`, `--slotted-text-box-edge`, `--slotted-text-muted`, `--slotted-tone-accent-border`, `--slotted-tone-accent-on-solid`, `--slotted-tone-accent-solid`, `--slotted-tone-accent-solid-active`, `--slotted-tone-accent-solid-hover`, `--slotted-tone-accent-subtle-active`, `--slotted-tone-accent-subtle-hover`, `--slotted-tone-accent-text`, `--slotted-tone-danger-border`, `--slotted-tone-danger-on-solid`, `--slotted-tone-danger-solid`, `--slotted-tone-danger-solid-active`, `--slotted-tone-danger-solid-hover`, `--slotted-tone-danger-text`, `--slotted-tone-info-on-solid`, `--slotted-tone-info-solid`, `--slotted-tone-info-solid-active`, `--slotted-tone-info-solid-hover`, `--slotted-tone-info-text`, `--slotted-tone-neutral-on-solid`, `--slotted-tone-neutral-solid`, `--slotted-tone-neutral-solid-active`, `--slotted-tone-neutral-solid-hover`, `--slotted-tone-neutral-text`, `--slotted-tone-secondary-on-solid`, `--slotted-tone-secondary-solid`, `--slotted-tone-secondary-solid-active`, `--slotted-tone-secondary-solid-hover`, `--slotted-tone-secondary-subtle-active`, `--slotted-tone-secondary-subtle-hover`, `--slotted-tone-secondary-text`, `--slotted-tone-success-on-solid`, `--slotted-tone-success-solid`, `--slotted-tone-success-solid-active`, `--slotted-tone-success-solid-hover`, `--slotted-tone-success-text`, `--slotted-tone-warning-on-solid`, `--slotted-tone-warning-solid`, `--slotted-tone-warning-solid-active`, `--slotted-tone-warning-solid-hover`, `--slotted-tone-warning-text`

## Examples

See [button.examples.md](./button.examples.md).
