Skip to content
Knsept
Free playbook

Toggle switch

An accessible on/off switch built on a real checkbox with role="switch". Keyboard, touch and screen readers work out of the box.

CSSUI Widgets Updated Oct 23, 2026
Live demo Reduced motion is on, so effects are toned down
<div class="settings">
  <label class="switch-row">
    <span><b>Email updates</b><small>One email when something new ships.</small></span>
    <input class="switch" type="checkbox" role="switch" checked>
  </label>
  <label class="switch-row">
    <span><b>Dark previews</b><small>Show widget demos on a dark background.</small></span>
    <input class="switch" type="checkbox" role="switch">
  </label>
</div>

The switch is a plain <input type="checkbox"> with appearance: none to remove the default box, and the knob is its ::before pseudo-element. Because it's still a real checkbox, everything you'd expect comes free: clicking anywhere on the label toggles it, Space toggles it from the keyboard, and it submits with forms.

role="switch" tells screen readers to announce it as a switch ("on"/"off") rather than a checkbox ("checked"), which matches what people see. The knob's slight overshoot comes from a springy cubic-bezier easing.

With reduced motion on, the knob still slides, just faster.

More from the library

Forms & inputs live

One-time code input

Six boxes for a verification code. Auto-advance, backspace, arrow keys, paste, and SMS autofill all work.

Forms & inputs live

Password strength meter

A live strength bar with a checklist of rules, plus a show/hide toggle. No library, no dark patterns.

Forms & inputs live

Range slider with value bubble

A styled native range input with a filled track and a bubble that follows the thumb. Same look in every browser.