โœฆ StealThis .dev

iOS-style Toggle Switch

A smooth iOS-inspired toggle switch built with CSS. Supports checked state, disabled state, label association, and a custom color accent. Zero JavaScript.

Open in Lab
css checkbox css-variables
Targets: HTML React Native

Expo Snack

Code

iOS-style Toggle Switch

A polished toggle switch that mirrors the iOS UISwitch aesthetic, built entirely with CSS โ€” no JavaScript required. Uses a hidden <input type="checkbox"> and a styled <label> for full native semantics and accessibility.

How it works

The actual <input type="checkbox"> is visually hidden but focusable. The <label> renders the track and thumb using ::before and ::after pseudo-elements. The :checked state drives color and thumb position via CSS transitions.

States

  • Off โ€” grey track, thumb on the left
  • On โ€” accent-colored track, thumb slides right with cubic-bezier spring feel
  • Disabled โ€” reduced opacity, cursor: not-allowed
  • Focus-visible โ€” accessible focus ring

Customization

Change --toggle-color CSS variable to recolor the active state instantly.

When to use it

  • Settings panels
  • Feature flags and preferences
  • Dark mode toggles