Task path / input to outcome
How to design a pure-CSS switch
- 01
Size the track
Set Track width between 44 and 128 px and Track height between 24 and 64 px. The width must exceed the height by at least 8 px so the thumb has room to travel. The 64 by 34 px default mirrors the proportions of most mobile switches.
- 02
Fit the thumb
Choose a Thumb size from 16 to 56 px. It must sit inside the track — no larger than the track height minus 4 px — or the status flips to CHECK VALUES with the exact rule that failed.
- 03
Color both states
Pick Inactive track for the off position and Active track for the on position. The thumb itself stays white with a small soft shadow, so both track colors only need to contrast with white.
- 04
Preview the transition
Toggle Show active state to watch the thumb slide and the track recolor at the real 180 ms ease timing. The padding around the thumb is computed as half the leftover track height, so the fit stays even at any size you choose.
- 05
Copy or download the CSS
Press Copy CSS or Download .css to save toolars-switch.css. The white thumb slides the computed travel distance between states, and the export includes focus and reduced-motion handling from the start. The output panel shows the live byte count, so you can see how compact the component stays.
- 06
Assemble the markup
Place a checkbox input followed by a .switch-track element inside a .switch wrapper, in exactly that order — the sibling selector depends on it. The input shrinks to an invisible 1 px box but stays focusable, and focus draws a 3 px outline in your Active track color.