Switch
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.
Disabled
Add disabled to the switch and data-disabled="true" to the field wrapper when the surrounding field should use disabled styling.
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.
يتم مشاركة التركيز عبر الأجهزة، ويتم إيقاف تشغيله عند مغادرة التطبيق.