‮Skip to content‬
uiify

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

‮Prop‬‮Type‬‮Default‬‮Description‬
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.‬
defaultPressedbooleanfalse‮Pressed state on first render. Uncontrolled, so it works with no JavaScript.‬
disabledbooleanfalse‮Disables the input and marks the wrapper with data-disabled.‬
classNamestring—‮Class applied to the label element.‬

‮Keyboard‬

‮Key‬‮Action‬
Enter / Space‮Toggle 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