Switch
<label class="label"> <input class="switch" type="checkbox" role="switch" checked /> Airplane mode</label><label class="label"> <input class="switch" type="checkbox" role="switch" name="airplane" /> Airplane mode</label><label class="label"> <input class="switch" type="checkbox" role="switch" data-size="sm" checked /> Small</label>
<label class="label"> <input class="switch" type="checkbox" role="switch" checked /> Default</label>data-size="sm" gives the shorter track, for dense rows of settings.
States
Section titled “States”<label class="label"> <input class="switch" type="checkbox" role="switch" /> Off</label>
<label class="label"> <input class="switch" type="checkbox" role="switch" checked /> On</label>
<label class="label"> <input class="switch" type="checkbox" role="switch" disabled /> Disabled</label>A switch usually belongs at the trailing edge of a row, with the explanation on the other side.
Helps us find which features go unused.
<div class="field" data-orientation="horizontal"> <div class="field-content"> <label class="field-title" for="switch-analytics">Share anonymous usage</label> <p class="field-description">Helps us find which features go unused.</p> </div> <input class="switch" type="checkbox" role="switch" id="switch-analytics" checked /></div>Switch or checkbox?
Section titled “Switch or checkbox?”| Switch | Checkbox | |
|---|---|---|
| Takes effect | Immediately | When the form is submitted |
| Reads as | On / off | Checked / unchecked |
| Belongs in | Settings | Forms |
| Needs a Save button | No | Usually |
If the user has to press Save for it to count, it is a checkbox. A switch that only applies later is a broken promise.
Set dir="rtl" on the page or on any subtree — the track and thumb reverse with the reading
direction. See the button page for a live example.
Accessibility
Section titled “Accessibility”- A switch needs a label like any control, wrapping it or with
for. - The label says what it controls, not its state. “Airplane mode”, not “Airplane mode is on” — the state is announced from the control.
- Do not put a switch behind a confirmation. Something that immediately does a dangerous thing wants a button and an alert dialog instead.