Track, knob, and transform
The switch is a checkbox whose native look is removed: the track is the input background and the knob is a ::after circle. Sliding uses transform: translateX, which animates on the compositor and never causes layout work.
Build an iOS-style pure-CSS toggle switch with your track and knob colors, sizes, and animation speed, and copy the HTML plus CSS.
The knob is a ::after pseudo-element that slides with transform, so the animation stays smooth.
Everything is generated and previewed locally in this browser tab. Nothing is sent to a server.
The switch is a checkbox whose native look is removed: the track is the input background and the knob is a ::after circle. Sliding uses transform: translateX, which animates on the compositor and never causes layout work.
A knob of track height minus padding creates the inset look; the travel distance is width minus height. The generator computes both from your two size inputs so the geometry always lines up.
Keep the on state clearly different from off — hue change, not just brightness. Both states should keep enough contrast with the knob for the switch to read as a control, not a decoration.
It is a real input type="checkbox", so it is focusable, keyboard-togglable with space, and announced by screen readers as a checkbox. Add an aria-label or a visible label when you use it.
If you edited the CSS to slide with left or margin instead of transform, the animation runs on the main thread. Keep the generated translateX approach for smooth 60fps movement.
Yes. Add the disabled attribute; you may want extra CSS like .switch:disabled { opacity: .5; cursor: not-allowed; } to make the state obvious.
Yes — it submits like any checkbox, sending its value when checked. The styling is purely visual.
Pick a category to see every tool in it — then open one and discover related tools.