Skip to content

Toggle

Button that switches between a pressed and an unpressed state.

Browsers
Chrome 123+Firefox 121+Safari 17.5+
Tier
0
Bundle compressed
295 B
Forced layout budget
0 ms
Axe budget
0
SSR compatible
Yes
Published contract
Test harness

Playground

Toggle

Default

Disabled

API

Toggle

PropTypeDefaultDescription
id*string—Id of the checkbox input that the label points at.
label*ReactNode—Content of the label that toggles the input when clicked.
pressedboolean—Controlled pressed state; supplying it hands the state to the caller.
defaultPressedbooleanfalsePressed state on first render. Uncontrolled, so it works with no JavaScript.
disabledbooleanfalseDisables the input and marks the wrapper with data-disabled.
classNamestring—Class applied to the label element.

Keyboard

KeyAction
Enter / SpaceToggle pressed state when focused

Accessibility

Native <button aria-pressed> (or a hidden checkbox input for the group variant). Pressed state is readable without JavaScript.

Styling hooks

data-statedata-disabled