Switch

Usage

Include CSS

Import Tailwind and one full Basecoat style bundle.

@import "tailwindcss";
@import "basecoat-css/vega.css";

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

@import "tailwindcss";
@import "basecoat-css/base.css";
@import "basecoat-css/components/switch.css";
@import "basecoat-css/styles/vega.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

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.

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