Skip to content

Switch

An accessible on/off toggle with full keyboard support and zero visual opinion.

Styled with CSS Tailwind

Basic Switch (Uncontrolled)

Renders a native <button> with role="switch" and aria-checked. Click or press Space/Enter to toggle. DefaultChecked seeds the initial state. The switch and its thumb both carry data-state: the CSS version styles the on look with a [data-state="checked"] selector, the Tailwind version with the custom data-state-checked: variant.

Controlled

Drive the state externally with Checked + OnCheckedChange. Clicking either control updates the same state.

Notifications: on

Disabled

Set Disabled="true" to block interaction. The button receives the native disabled attribute and a data-disabled hook: the CSS version styles it with a [data-disabled] selector, the Tailwind version with the data-disabled: variant.

With label

Wrap the switch in a <label> to make the label clickable. Clicking the label text toggles the switch — standard HTML behaviour.

As a non-native element

Set As="div" to render as a div. The component automatically adds role="switch", tabindex="0", and Space/Enter keyboard handling so the switch remains fully accessible.

Form Submission

Set Name to render an adjacent <input type="hidden"> so the switch participates in plain form posts. The hidden input is only present when the switch is checked, mirroring native checkbox behaviour.

An unhandled error has occurred. Reload 🗙