Skip to content

Forms

Switch

A toggle built on a native checkbox with role="switch".

stableCSS onlyBuilt on <input type="checkbox">hydrateless/switch.css

A toggle switch built on a native checkbox with role="switch". Because it is a real checkbox, it participates in forms, supports :checked, :focus-visible, and the Space key, and is announced correctly by assistive technology. No JavaScript.

Playground

Live

Props

The framework bindings expose these props (and forward the rest to the root element).

PropTypeDefaultDescription
checkedbooleanNot setControlled state; pair with the native `onChange` in React (Vue: `v-model`, Svelte: `bind:checked`).
defaultCheckedbooleanNot setInitial state (uncontrolled).

CSS variables

Override these on any ancestor to theme the component. See the theme studio to preview changes live.

CSS variableUsed for
--hl-primaryTrack color when on.
--hl-borderTrack color when off.

Accessibility

  • role="switch" makes assistive tech announce "on/off" rather than "checked".
  • A native checkbox underneath keeps Space toggling and form submission.

Released under the MIT License.