Generate an accessible CSS toggle switch. Set the track size, knob gap, on and off colors, knob color and animation speed, try it in the preview with the mouse or keyboard, and copy HTML and CSS built on a real checkbox — so it works with screen readers, forms and right-to-left layouts. It's free, runs in your browser, and nothing leaves your device.
| Style | Track | Knob gap |
|---|---|---|
| iOS-like | 51 × 31 | 2px |
| Material-like | 52 × 32 | 4px |
| Compact | 36 × 20 | 2px |
A real input gives you keyboard support, form submission and screen-reader announcements for free. A div switch needs JavaScript and ARIA to match.
It tells assistive technology to announce the control as a switch that's on or off, rather than a checkbox that's checked.
Like any checkbox: input.checked in JavaScript, or the field is included in form data when on.
Yes. The knob slides in the opposite direction on pages with dir="rtl".
No. The code is generated in your browser.
The switch is a native checkbox with role="switch", visually hidden rather than removed, followed by a styled span. Because the input is still in the document, it gets keyboard focus, toggles with Space, submits with a form and is announced by screen readers as a switch with its on or off state — none of which a div-based switch provides without extra scripting. The knob is a ::after pseudo-element on the track; :checked moves it with transform: translateX by the track width minus the knob and padding, which the generator calculates from the sizes chosen, and changes the track color. A [dir="rtl"] rule moves the knob the other way on right-to-left pages. :focus-visible draws a ring around the track for keyboard users, :disabled dims it, and a reduced-motion block removes the slide animation. The visible label sits inside the same label element, so clicking the text toggles the switch too.