Toggle

A two-state button that stays pressed when toggled on. Used for formatting toolbars (bold/italic) or option toggles.

Variants

Sizes

With text

Disabled

Installation

pnpm
pnpm dlx @hex-core/cli add toggle

API Reference

PropTypeDefaultDescription
pressed
booleanControlled pressed state
defaultPressed
booleanfalseDefault pressed state for uncontrolled usage
onPressedChange
functionCallback on pressed change: (pressed: boolean) => void
variant
"default" | "outline"defaultVisual style
size
"default" | "sm" | "lg"defaultToggle size
disabled
booleanfalseDisable the toggle

AI Guidance

When to use

Use for binary on/off actions that persist: toolbar formatting buttons (bold, italic), layout mode switches, filter toggles. Not submitted as form data.

When not to use

Don't use for instant settings (use Switch). Don't use for form boolean fields (use Checkbox). Don't use for choosing one of many (use ToggleGroup).

Common mistakes

  • Using for form field submission (use Checkbox instead)
  • Forgetting aria-label on icon-only toggles
  • Using Toggle when ToggleGroup's single-select mode is needed

Accessibility

Radix sets aria-pressed correctly. Icon-only toggles MUST have aria-label. Space/Enter toggles state.

Token budget: 400