A switch is used to enable or disable a mode, feature or function. Toggle switches have an immediate effect on the system.
Use labels such as “on” and “off” or “enable” and “disable” to communicate the state of the toggle switch. To interact with a toggle switch, the user can click the state label or alternately press the spacebar.
<label class="luci-switch" for="luci-switch-96152">
<input class="luci-switch__input" id="luci-switch-96152" name="luci-switch-96152-name" type="checkbox" />
<span class="luci-switch__label">
<span class="luci-switch__text">Default (Off)</span>
<span class="luci-switch__text-checked">Default (On)</span>
</span>
<span aria-hidden="true" class="luci-switch__visual"></span>
</label>
<label class="luci-switch luci-switch--label-left" for="luci-switch-63301">
<input class="luci-switch__input" id="luci-switch-63301" name="luci-switch-63301-name" type="checkbox" />
<span class="luci-switch__label">
<span class="luci-switch__text">Default (Off)</span>
<span class="luci-switch__text-checked">Default (On)</span>
</span>
<span aria-hidden="true" class="luci-switch__visual"></span>
</label>
A small switch should only be used in data tables / grids as illustrated below.
Folder | Recent Version | Add to Restore Queue |
---|---|---|
vFolder-16 | Dec 31, 2018 11:59 PM | |
vFolder-16 | Dec 31, 2018 11:59 PM | |
vFolder-16 | Dec 31, 2018 11:59 PM |
<label class="luci-switch luci-switch--compressed" for="luci-switch-21019">
<input class="luci-switch__input" id="luci-switch-21019" name="luci-switch-21019-name" type="checkbox" />
<span class="luci-switch__label">
<span class="luci-switch__text">Label (Off)</span>
<span class="luci-switch__text-checked">Label (On)</span>
</span>
<span aria-hidden="true" class="luci-switch__visual"></span>
</label>
<label class="luci-switch luci-switch--compressed luci-switch--label-hidden" for="luci-switch-6984">
<input class="luci-switch__input" id="luci-switch-6984" name="luci-switch-6984-name" type="checkbox" />
<span class="luci-switch__label">
<span class="luci-switch__text">Label (Off)</span>
<span class="luci-switch__text-checked">Label (On)</span>
</span>
<span aria-hidden="true" class="luci-switch__visual"></span>
</label>
Toggle switches can be grouped, similar to how checkboxes and radio buttons can be grouped. Group toggle switches should be wrapped in a fieldset
element with right labels for each switch.
<fieldset class="luci-switch__group">
<label class="luci-switch" for="default-25718">
<input class="luci-switch__input" id="default-25718" name="default-25718-name" type="checkbox" checked />
<span class="luci-switch__label">
<span class="luci-switch__text">Switch Label (Off)</span>
<span class="luci-switch__text-checked">Switch Label (On)</span>
</span>
<span aria-hidden="true" class="luci-switch__visual"></span>
</label>
<label class="luci-switch" for="default-63454">
<input class="luci-switch__input" id="default-63454" name="default-63454-name" type="checkbox" />
<span class="luci-switch__label">
<span class="luci-switch__text">Switch Label (Off)</span>
<span class="luci-switch__text-checked">Switch Label (On)</span>
</span>
<span aria-hidden="true" class="luci-switch__visual"></span>
</label>
<label class="luci-switch" for="default-4856">
<input class="luci-switch__input" id="default-4856" name="default-4856-name" type="checkbox" checked />
<span class="luci-switch__label">
<span class="luci-switch__text">Switch Label (Off)</span>
<span class="luci-switch__text-checked">Switch Label (On)</span>
</span>
<span aria-hidden="true" class="luci-switch__visual"></span>
</label>
<label class="luci-switch" for="default-8143">
<input class="luci-switch__input" id="default-8143" name="default-8143-name" type="checkbox" />
<span class="luci-switch__label">
<span class="luci-switch__text">Switch Label (Off)</span>
<span class="luci-switch__text-checked">Switch Label (On)</span>
</span>
<span aria-hidden="true" class="luci-switch__visual"></span>
</label>
</fieldset>
.luci-switch__label
element isn't present, the checkbox input
element should have an aria-label
attribute with a descriptive value..luci-switch__text
and .luci-switch__text-checked
is determined via CSS in order to reflect the current state of the switch. The .luci-switch__text-checked
element is optional and contains the label for the on/checked state. Class | Applies to | Outcome |
---|---|---|
|
|
Positions the label to the left of the switch toggle visual element. |
|
|
Accessibly hides the label so it’s still readable by assistive technologies. |
|
|
Reduces the size of the switch toggle visual element, decreases the font size of the label and compresses the spacing between elements. |
|
|
Displays switch as |