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 is off.
Usage
Include CSS
Import Tailwind and one full A3S UI style bundle.
Or import only the base CSS, Switch component CSS, and one style pack.
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.
HTML structure
<input type="checkbox" role="switch" class="input">- The switch control. Use native checkbox state: add
checkedfor an initially enabled switch,disabledfor a disabled switch, andaria-invalid="true"for invalid state. data-size="sm"Optional- Renders the smaller switch size.
Examples
Description
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.
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.
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.
Only an organization owner can change this setting.
Invalid
Add aria-invalid="true" to the switch and data-invalid="true" to the field wrapper.
You must accept the terms and conditions to continue.
Size
Use data-size="sm" to render the smaller switch size.
RTL
Switch field layout uses document direction. Set dir="rtl" on the field or an ancestor.
يتم مشاركة التركيز عبر الأجهزة، ويتم إيقاف تشغيله عند مغادرة التطبيق.
