Switch

A control that allows the user to toggle between checked and not checked.

Usage

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

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

Checked state

Use native HTML state. Add checked for an initially enabled switch, or read and update the element's checked property in JavaScript.

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

Invalid state

Set aria-invalid="true" on the switch and, when using field, set data-invalid="true" on the field wrapper.

Choose whether marketing emails are enabled.

Examples

Basic

Description

Receive emails about new products, features, and more.

Choice Card

Wrap a .field in a native <label> when the whole card should toggle the switch.

Disabled

Invalid

Choose whether marketing emails are enabled.

Size

RTL

Switch field layout uses document direction. Set dir="rtl" on a parent to render right-to-left.