CSS Toggle Switch Generator
An on/off switch built from a checkbox.
The native checkbox stays in the label so the control is keyboard accessible. The track and knob are drawn with a span. Checked state uses the sibling selector.
Frequently asked questions
Where is the checkbox?
It is visually hidden and still focusable. The span is only the drawing.
Can the knob be a different color?
The copied knob is white. Change .switch span::after if you want another color.