bit Bheadless

Switch

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

Implementation: 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.

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.

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 🗙