Switch
An on/off switch for settings. Tap it or drag its thumb across, and give it variant="glass" for each platform's own switch.
Installation
Usage
- This example also uses Label.
- A tap toggles it, and so does dragging the thumb across. It lands on the side you let go nearer, as on iOS.
- It taps the phone lightly as it flips, with
LynxHaptics. Settingcheckedfrom code doesn't. - A drag starts only once your finger moves sideways, so a scroll that starts on the switch scrolls the page. A sideways drag doesn't scroll it.
- The default switch is 44 by 24 pixels: the primary color when on, the input color when off.
Glass
Each platform's own switch:
On iOS 26 the thumb turns into a Liquid Glass lens while you touch it, bigger than the track, and turns solid again when you let go. It's the one place glass sits on content: Apple keeps glass for the layer above content, except on sliders and switches, and only while they're touched.
What each platform draws:
- iOS draws it green when on, as UIKit does whatever your app's tint color. Its colors follow your app's color scheme, which
provideIconTheme()sets. - Material uses the theme's colors:
primarywhen on,secondarywith amuted-foregroundoutline when off.
Tint
tint colors the track while the switch is on, in every look, as UIKit's onTintColor does: a color written out, or a theme variable. Without it, each look keeps its own: the system green on iOS, the theme's primary color elsewhere. Material's pressed state layer takes it too.
Disabled
A disabled switch dims and ignores taps and drags.
Listen without a signal
changed emits the new state after each tap or drag that changes it.
Forms
checked is a model(), so the switch works with every Angular forms API:
UiSwitch implements Signal Forms' FormCheckboxControl. Each tap or drag marks the field touched, so its error can show. Reactive and template-driven forms bind to its checked model directly, as Angular 22 does for any component with one. See Forms.
API
UiSwitch
UiSwitch also has a public toggle() method, which does nothing while disabled.
Accessibility
- A screen reader reads it as a button with its label and an "On" or "Off" value, in the words of
provideAccessibilityWords()when the app gives its own. Android's reads it as a switch. Give it anaccessibility-label, since the label beside it is a separate element. - Reduce Motion: the thumb jumps across instead of sliding, and turns to glass and back without growing.
- Reduce Transparency: iOS makes its own lens opaque. On Android and the web, the solid thumb grows instead of turning to glass.
