For AI agents: the complete documentation index is available at https://a3s-lab.github.io/UI/v0.4.1/en/llms.txt, the full documentation bundle is available at https://a3s-lab.github.io/UI/v0.4.1/en/llms-full.txt, and this page is available as Markdown at https://a3s-lab.github.io/UI/v0.4.1/en/components/switch.md.

Switch

Switch immediately toggles an independent setting on or off and is not intended for a choice that takes effect only after form submission. When a remote update can fail, keep the control interactive, announce the pending or rejected outcome, and restore the previous value on rejection.

Airplane Mode

Airplane Mode is off.

Usage

Include CSS

Import Tailwind and one full A3S UI style bundle.

@import "tailwindcss";
@import "@a3s-lab/ui/a3s.css";

Or import only the base CSS, Switch component CSS, and one style pack.

@import "tailwindcss";
@import "@a3s-lab/ui/base.css";
@import "@a3s-lab/ui/components/switch.css";
@import "@a3s-lab/ui/styles/a3s.css";

Using CDN or bundler imports? See the Installation page.

Add your switch HTML

Add class="input" and role="switch" to a native checkbox. Use a native <label> or aria-label for accessible naming.

<input type="checkbox" role="switch" class="input" />

HTML structure

<input type="checkbox" role="switch" class="input">
The switch control. Use native checkbox state: add checked for an initially enabled switch, disabled for a disabled switch, and aria-invalid="true" for invalid state.
data-size="sm" Optional
Renders the smaller switch size.

Examples

Description

Live preview

Focus is shared across devices, and turns off when you leave the app.

Choice card

Use a wrapping <label> when the whole card should toggle the switch.

Live preview

Remote accept and reject

Hosts own persistence. These fixtures prove the UI keeps an accepted change and restores the previous value when a remote update is rejected.

Sync focus settings

This fixture always rejects the remote update and restores the previous value.

Ready to sync.

This fixture always accepts the remote update.

Ready to sync.

Disabled

Add disabled to the switch and data-disabled="true" to the field wrapper when the surrounding field should use disabled styling. Keep the label and reason visible.

Live preview

Only an organization owner can change this setting.

Invalid

Add aria-invalid="true" to the switch and data-invalid="true" to the field wrapper.

Live preview

You must accept the terms and conditions to continue.

Size

Use data-size="sm" to render the smaller switch size.

Live preview

RTL

Switch field layout uses document direction. Set dir="rtl" on the field or an ancestor.

Live preview

يتم مشاركة التركيز عبر الأجهزة، ويتم إيقاف تشغيله عند مغادرة التطبيق.