Toggle Button
A button that switches between an on and off (selected) state.
Overview
A toggle button is a button that stays pressed. Use it for a single binary
choice that the user can turn on and off — like pinning an item, toggling a
filter, or enabling an option. It shares the Button's geometry and interaction
model, with five styles (filled, tonal, outlined, elevated,
glass) and a selected state.
When the toggle carries an icon, show the outline form while unselected and
the filled form once selected — pass them as icon and selectedIcon and
the component swaps automatically.
$ npx morpha-ui add toggle-buttonExamples
Variants
Each style has a low-emphasis unselected state (top row) and a high-emphasis selected state (bottom row).
With icon
Pass an outline icon for the unselected state and a filled selectedIcon for
the selected state; the toggle swaps between them. Use an icon size with an
aria-label for icon-only toggles.
Sizes
Five sizes scale padding and label together — xs, sm (default), md, lg,
xl, shared with the Button.
Radius
Four shapes via the shape prop: full (pill, default), rounded (12px),
squared whose corner radius grows with the size, and none.
Coming from shadcn? ToggleButton is Morpha UI's toggle — a
two-state pressed button. For groups with single/multiple selection see
Toggle Group.
Installation
Morpha UI components are distributed via the Morpha CLI (coming in a later
step): npx morpha-ui add toggle-button.
API Reference
Accessibility
- Renders a native
<button type="button">witharia-pressedreflecting theselectedstate. - Control
selectedfrom your own state and flip it ononClick(see the demo above). - Icon-only toggles (any
iconsize) must provide anaria-labeldescribing the action. - Reinforce the state beyond color: pass an outline
iconand a filledselectedIconso the change reads without relying on the fill alone. - A visible focus ring (3px accent with a 2px offset) is provided via
focus-visible. - Shares the Button's
size(xs–xl) andshape(full/rounded/squared) props.