Switches

A switch is used to enable or disable a mode, feature or function. Toggle switches have an immediate effect on the system.

Standard Switch

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 Right (Default)

Copied to clipboard
<label class="luci-switch" for="luci-switch-72832">
    <input class="luci-switch__input" id="luci-switch-72832" name="luci-switch-72832-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 Left

Copied to clipboard
<label class="luci-switch luci-switch--label-left" for="luci-switch-46940">
    <input class="luci-switch__input" id="luci-switch-46940" name="luci-switch-46940-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>

Small Switch

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

With Label

Copied to clipboard
<label class="luci-switch luci-switch--compressed" for="luci-switch-27644">
    <input class="luci-switch__input" id="luci-switch-27644" name="luci-switch-27644-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>

Without Label

Copied to clipboard
<label class="luci-switch luci-switch--compressed luci-switch--label-hidden" for="luci-switch-40388">
    <input class="luci-switch__input" id="luci-switch-40388" name="luci-switch-40388-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 Switch Group

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.

Toggle Switch Group Stacked

Copied to clipboard
<fieldset class="luci-switch__group">
    <label class="luci-switch" for="default-22355">
        <input class="luci-switch__input" id="default-22355" name="default-22355-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-62382">
        <input class="luci-switch__input" id="default-62382" name="default-62382-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-36033">
        <input class="luci-switch__input" id="default-36033" name="default-36033-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-67177">
        <input class="luci-switch__input" id="default-67177" name="default-67177-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>

Do’s and Don’ts

Do

  • Use a toggle switch if a physical switch could perform a similar function. For example a light switch.
  • Use a toggle switch if the change to the system will be immediate.
  • Include a label for your toggle switch.

Don’t

  • Do not use a toggle switch if a “submit” or “save” is required to change the system.
  • Do not use for progressive disclosure (e.g., to reveal or other associated inputs). Use checkboxes or radio buttons instead.

Accessibility

  • When the .luci-switch__label element isn't present, the checkbox input element should have an aria-label attribute with a descriptive value.
  • The visibility of the .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 Reference

Class Applies to Outcome

.luci-switch--label-left

.luci-switch

Positions the label to the left of the switch toggle visual element.

.luci-switch--label-hidden

.luci-switch

Accessibly hides the label so it’s still readable by assistive technologies.

.luci-switch--compressed

.luci-switch

Reduces the size of the switch toggle visual element, decreases the font size of the label and compresses the spacing between elements.

.luci-switch--inline

.luci-switch

Displays switch as inline-flex.