iOS Toggle Switch
FeaturedA pure-CSS iOS-style toggle with a hidden checkbox, smooth slide, and accessible focus ring.
- lines of CSS
- 37lines of CSS
- dependencies
- 0dependencies
- browser, for years
- Everybrowser, for years
- motion only on interaction
- Hovermotion only on interaction
Vue, Svelte, styled-components and Tailwind exports are part of Pro. HTML, CSS and React are free forever.
.fx-toggle {
position: relative;
display: inline-block;
width: 52px;
height: 30px;
}
.fx-toggle input {
opacity: 0;
width: 0;
height: 0;
}
.fx-toggle-slider {
position: absolute;
inset: 0;
cursor: pointer;
background: #cbd5e1;
border-radius: 999px;
transition: background 0.3s ease;
}
.fx-toggle-slider::before {
content: '';
position: absolute;
height: 22px;
width: 22px;
left: 4px;
bottom: 4px;
background: #fff;
border-radius: 50%;
transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
.fx-toggle input:checked + .fx-toggle-slider { background: #10b981; }
.fx-toggle input:checked + .fx-toggle-slider::before { transform: translateX(22px); }
.fx-toggle input:focus-visible + .fx-toggle-slider {
outline: 2px solid #10b981;
outline-offset: 2px;
}<label class="fx-toggle">
<input type="checkbox" />
<span class="fx-toggle-slider"></span>
</label>What do I do with this?
- Put
toggle-ios.cssanywhere your page already loads CSS from — in Next.js that isapp/globals.css, or any stylesheet with a<link>in your HTML. - Then put the class on the element you want it on:
<button class="fx-toggle">. The CSS does nothing until a class name in it matches something on the page.
- Link the stylesheet, then paste the markup wherever you need it.
npx hoverlab add toggle-iosWhat's included
- The markup and the stylesheet, in whichever framework you pick
- No runtime dependencies
Works with
- React
- Vue
- Svelte
- Tailwind
- styled-components
- Plain CSS
npx hoverlab add toggle-ios
Or over MCP, from your editor's agent — no account needed.
License
Free to read, copy and install, for personal and non-commercial projects. Shipping it in client work or a paid product needs Pro ($79 once). The source lands in your repo and stops being ours — no attribution, nothing to upgrade.
Motion safety
Static estimate, read from the CSS
- Reduced motion
- Brief motion, no guard
Animates briefly or on interaction. Only looping motion gets a guard in this catalog; copy the one from the Insights tab if this ships on a critical path.
- What it animates
- Repaints
Animates
background. No reflow, but the browser repaints every frame, which is fine for one element and costly across many. - Flashing (WCAG 2.3.1)
- No flashing found
No repeating change in opacity, colour or brightness large enough to count as a flash.
- Layout shift (CLS)
- No shift expected
Nothing it animates moves or resizes the box in flow. A category from the CSS, not a measurement for this effect.
Every row is read from the shipped CSS. Only a figure marked measured came from a browser. Customizing the speed changes the timing, so recheck a customized copy. How it is computed
38 more effects in Inputs & Hover
All of them free to read, copy and install — no account, no locked tiles, no watermarked preview. The whole catalog is open, and so are the API and the CLI.
Browse Inputs & HoverShipping one commercially
Copying the code is free. Putting it in client work or a paid product is what Pro is for — the licence, not the access.
- A commercial licence for everything in the catalog
- Unlimited bundle exports, in Vue, Svelte and Tailwind
- One payment — no subscription, nothing to renew
7 variations of iOS Toggle Switch
Finished looks, each one a position in the customizer above. Copy any of them, or open it and keep moving the sliders.