About this set
Five switch shapes that cover most settings screens: a rounded pill, a square switch with 6px corners, a compact 38 by 22 pixel switch for dense tables and toolbars, a pill whose knob shows a blue tick when it is on, and a long-travel switch with a 74 pixel track for touch layouts where a bigger target helps. Each one is shown on and off. Use the pill as the default, the square one where the rest of the interface has square corners, the compact one where vertical space is tight, and the tick variant when colour alone should not carry the state. Each switch is a real checkbox with role=”switch”, visually hidden inside a label, followed by an empty element that draws the track and the knob. The browser handles clicking, keyboard toggling and form submission, and the CSS only reacts to :checked. The Bootstrap version is the stock .form-switch with the knob redrawn through –bs-form-switch-bg, and the Tailwind version builds the same parts with peer-checked utilities.
What’s included
- Five shapes: pill, square, compact, knob with a tick, long travel
- Native checkbox with role="switch", so it submits with a form
- Off track darkened to meet 3:1 against the page
- Knob slides with a 220 ms transition that switches off under reduced motion
- Plain CSS, Bootstrap .form-switch and Tailwind versions of the same design
Accessibility
Each input has role="switch" and an aria-label, so screen readers announce a named switch with its on or off state. Tab reaches every switch and Space toggles it. Keyboard focus draws a 2px blue outline around the visible track, and all transitions are removed when prefers-reduced-motion is set.
Customise it
In plain CSS change --sw-on, --sw-off and --sw-knob on .sw, and the width, height and translateX values for size. In Bootstrap the same --sw-* variables sit on the .form-switch wrapper; in Tailwind edit the --color-sw-on and --color-sw-off theme colours and the w-, h- and translate-x- utilities.






