Skip to content

Toggle

Two-state button that switches a single option on or off.

  • stable
  • since v0.1.0
  • 1.39 kB
  • feedback
  • control
  • action

Exposes aria-pressed for the on/off state, native keyboard activation (Enter/Space), and focus styles driven by design tokens.

Preview
Open
tsx

Toggle ships three variants — ghost (default), outline, and solid.

Preview
Open
tsx

Four sizes are available: xs, sm, md (default), and lg.

Preview
Open
tsx

Use pressed and onPressedChange to control the toggled state.

Preview
Open
tsx
Preview
Open
tsx
PropTypeDefaultDescription
pressed
boolean
—
Controlled pressed state.
defaultPressed
boolean
—
Uncontrolled initial pressed state.
onPressedChange
((pressed: boolean) => void)
—
Fires with the next pressed state when toggled.
size
"xs"|"sm"|"md"|"lg"
"md"
Pixel scale. One of `xs`, `sm`, `md`, `lg`. Inherits from a parent `ToggleGroup` when unset.
variant
"ghost"|"outline"|"solid"
"ghost"
Visual style. `ghost` is borderless, `outline` is bordered, `solid` has a filled active background. Inherits from a parent `ToggleGroup` when unset.
  • Exposes aria-pressed for the on/off state.
  • Native keyboard activation: Space and Enter toggle the pressed state.
  • Always include a visible label or an aria-label describing what is being toggled (<Toggle aria-label="Bold">B</Toggle>).
  • Pressed state is communicated through aria-pressed, not colour alone — the variant styling layers on top of accessible semantics.
  • Focus outline uses the token-driven focus ring; never removed.
  • Use toggles for formatting controls (bold, italic, underline).
  • Group related toggles inside a ToggleGroup to share size and variant via context.
  • Pair an icon with aria-label for icon-only toolbar controls.
  • Use variant="solid" for emphasis when the toggle reflects a primary state.