> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# 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

```bash
npx @blotch/dolan add switch
```

```typescript
import { UiSwitch } from '../components/ui/switch';
```

:::tip
This also adds [Glass](/dolan/glass.md), which draws the glass variant's lens, and [Icon](/dolan/icon.md), whose copy of the theme colors gives the iOS colors their dark mode.
:::

## Usage

```typescript title="src/app/app.ts"
import { Component, signal } from '@angular/core';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';
import { UiLabel } from '../components/ui/label';
import { UiSwitch } from '../components/ui/switch';

@Component({
  selector: 'app-root',
  imports: [LYNX_ELEMENTS, UiLabel, UiSwitch],
  template: `
    <view class="flex flex-row items-center justify-between">
      <ui-label>Bluetooth</ui-label>
      <ui-switch [(checked)]="bluetooth" accessibility-label="Bluetooth" />
    </view>
  `,
})
export class App {
  protected readonly bluetooth = signal(false);
}
```

- This example also uses [Label](/dolan/label.md).
- **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`](/api/angular-lynx/device/haptics.md). Setting `checked` from 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:

```angular-html
<ui-switch variant="glass" [(checked)]="wifi" accessibility-label="Wi-Fi" />
```

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:

| Platform                                          | Switch                                                                            |
| ------------------------------------------------- | --------------------------------------------------------------------------------- |
| iOS 26 and later                                  | iOS 26's 63 × 28pt switch, whose thumb turns to glass while touched               |
| iOS 15 to 25                                      | The classic 51 × 31pt switch, whose thumb stretches while touched                 |
| Android                                           | A Material 3 switch: 52 × 32dp, outlined when off, its handle grows while pressed |
| Android, with [`provideGlass()`](/dolan/glass.md) | iOS 26's switch, with Android's glass                                             |
| [Web preview](/guide/glossary.md#web-preview)     | iOS 26's switch, with the glass drawn by WebGL                                    |

- **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()`](/dolan/icon.md#dark-mode) sets.
- **Material uses the theme's colors:** `primary` when on, `secondary` with a `muted-foreground` outline 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.

```html
<ui-switch
  variant="glass"
  tint="var(--brand)"
  [(checked)]="wifi"
  accessibility-label="Wi-Fi"
/>
```

### Disabled

```angular-html
<view class="flex flex-row gap-3">
  <ui-switch disabled />
  <ui-switch disabled [checked]="true" />
</view>
```

A disabled switch dims and ignores taps and drags.

### Listen without a signal

```angular-html
<ui-switch (changed)="onNotifications($event)" />
```

`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:

```angular-html
<ui-switch [formControl]="wifi" />
<ui-switch [(ngModel)]="wifi" />
<ui-switch [formField]="settings.wifi" />
```

`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](/guide/forms.md).

## API

### UiSwitch

| Input                 | Type                   | Default     | Description                                                |
| --------------------- | ---------------------- | ----------- | ---------------------------------------------------------- |
| `checked`             | `boolean`              | `false`     | Whether it's on. Supports `[(checked)]`.                   |
| `disabled`            | `boolean`              | `false`     | Dims the switch and ignores taps and drags.                |
| `variant`             | `'default' \| 'glass'` | `'default'` | `'glass'` draws each platform's own switch.                |
| `tint`                | `string`               | —           | The track's color while it's on, such as `'var(--brand)'`. |
| `accessibility-label` | `string`               | —           | What a screen reader calls it, such as `'Wi-Fi'`.          |
| `class`               | `string`               | `''`        | Extra Tailwind classes for the switch.                     |

| Output          | Type      | Description                                                           |
| --------------- | --------- | --------------------------------------------------------------------- |
| `changed`       | `boolean` | Emits the new state after a tap or drag changes it.                   |
| `checkedChange` | `boolean` | Emits the new state, for `[(checked)]`.                               |
| `touch`         | `void`    | Emits after each tap or drag, for forms: the field counts as touched. |

`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()`](/guide/accessibility.md#say-states-in-your-apps-language) when the app gives its own. Android's reads it as a switch. Give it an `accessibility-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.

## Related

- [Slider](/dolan/slider.md): a value in a range, whose thumb turns to glass too
- [Checkbox](/dolan/checkbox.md): for agreeing or picking options in a form
- [Toggle](/dolan/toggle.md): a button that stays pressed
- [Glass](/dolan/glass.md): the Liquid Glass the lens draws
- [Label](/dolan/label.md)
