Skip to content

iOS Style Toggle Switch

Pure CSS iOS style toggle switches built on real checkboxes, in a grouped settings list with three sizes, five colors and a disabled state.

Also known as: ios toggle switch, on off switch, checkbox toggle, settings toggle

iOS Style Toggle Switch live demo

Open in new tab

Pure CSS code (HTML, CSS)

An iOS style toggle switch made with pure CSS on top of a native checkbox, shown inside a grouped settings list with colored row icons. It comes in three sizes and five colors, includes a disabled state and the springy thumb that stretches while pressed. Use it for preferences, notification settings, feature flags or any on/off option.

How it works

The root section.ist-settings contains ul.ist-group lists. Each row is a label.ist-row that wraps an optional .ist-icon, the .ist-text, a real input.ist-input with type="checkbox" and role="switch", and a decorative span.ist-switch right after it. Because the whole row is a label, clicking anywhere on it toggles the checkbox.

The checkbox is hidden with a visually-hidden pattern, not display: none, so it keeps keyboard focus and is read by screen readers. .ist-switch is the track and .ist-switch::after is the white thumb. The adjacent sibling selector .ist-input:checked + .ist-switch fills the track with --ist-on and moves the thumb with translateX(calc(var(--ist-w) - var(--ist-h))), so the travel distance always matches the size. While a row is pressed (:active) the thumb widens slightly, as on iOS. There is no JavaScript; the checked value is submitted with a form like any checkbox once you add a name.

Customization

  • .ist-switch--blue, .ist-switch--orange, .ist-switch--pink and .ist-switch--purple: set --ist-on, the track color when checked. Without a modifier the switch is iOS green.
  • .ist-switch--sm and .ist-switch--lg: change --ist-w and --ist-h, the track width and height; the thumb and its travel scale automatically.
  • --ist-gap on .ist-switch: the space between the thumb and the track edge.
  • --ist-off on .ist-settings: the track color when the switch is off.
  • --ist-speed: duration of the slide and color change, e.g. 0.15s for a snappier feel.
  • --ist-focus: the color of the keyboard focus outline drawn around the track.
  • Add disabled to an .ist-input to lock it; the track fades and the row shows a not-allowed cursor.
  • Remove the .ist-icon span from a row for a plain text list, as in the Sizes group.

Use cases

  • Preference pages: a grouped settings list with colored row icons uses switches for each option
  • Notification settings: users turn each alert type on or off with a springy thumb
  • Feature flags: five colors and three sizes help mark different kinds of switches
  • Forms: a real checkbox sits underneath, so it submits and works with the keyboard

Accessibility

Each switch is a native checkbox with role="switch", so assistive technology announces it as a switch with an on or off state, and the wrapping label gives it an accessible name. Space toggles it from the keyboard. The visual track is aria-hidden, and keyboard focus shows a 3px outline around it via .ist-input:focus-visible + .ist-switch. The on state is shown by thumb position as well as color. Transitions are removed under prefers-reduced-motion: reduce.

Usage notes

Keep the .ist-switch span directly after its input, since the styling depends on the + selector. The :has() rule only changes the cursor on disabled rows and can be dropped for older browsers.

iOS Style Toggle Switch at a glance

Framework
Pure CSS
Code
HTML, CSS
JavaScript
Not needed, CSS only
Dependencies
None
Layout
Responsive, works on mobile
Category
Toggles & Switches
License
Free for personal and commercial use

Questions about this template

Can I use the iOS Style Toggle Switch code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

There is nothing to install. Paste the HTML where the component should appear and add the CSS to your stylesheet. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. It is built with HTML and CSS only, so there is no JavaScript to load.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

No dependencies. Pure HTML, CSS and JavaScript.

iOS Style Toggle Switch – free Pure CSS toggle & switch template
iOS Style Toggle Switch · free Pure CSS toggle & switch template

More Toggles & Switches

Settings Toggles with Description – free Tailwind CSS toggle & switch template

Settings Toggles with Description

Tailwind CSS settings panel with accessible switches, label descriptions, a locked required option, restore defaults and an auto-save status message.

Day/Night Toggle – free Pure CSS toggle & switch template

Day/Night Toggle

Animated pure CSS day and night toggle switch where the sun turns into a cratered moon, clouds drift away and stars appear.

Toggler Button Demos – free Bootstrap 6 toggle & switch template

Toggler Button Demos

Four Bootstrap 6 Toggler demos on a dark panel: a favorite heart, a read-more expander, a light/dark theme preview and a grid/list view switch, all with data attributes.

Settings Panel with Switches – free Bootstrap 6 toggle & switch template

Settings Panel with Switches

Bootstrap 6 notification settings panel with switches grouped in cards, master switches per group, a pause-all toggle, unsaved-change tracking and a simulated save.

Neumorphic Toggle Switch – free Pure CSS toggle & switch template

Neumorphic Toggle Switch

Pure CSS neumorphic toggle switches with inset shadow tracks, raised knobs and glowing indicators, built on accessible native checkboxes.

Toggle Switches with Labels – free Bootstrap 6 toggle & switch template

Toggle Switches with Labels

Dark Bootstrap 6 settings panel with .switch toggles in three sizes, labels with descriptions, disabled states and a simulated auto-save status.