Switches afford a choice between one of two opposing states or options.
<div class="mds-switch">
<label class="mds-switch__label" for="--21646">
<input id="--21646" type="checkbox" role="switch" class="mds-switch__input">
<span class="mds-switch__text"> Logic Mode </span>
</label>
</div>
<div class="mds-switch mds-switch--disabled">
<label class="mds-switch__label" for="--75765">
<input id="--75765" type="checkbox" role="switch" class="mds-switch__input" disabled>
<span class="mds-switch__text"> Logic Mode </span>
</label>
</div>
<div class="mds-switch mds-switch--standalone">
<label class="mds-switch__label" for="--93826">
<input id="--93826" type="checkbox" role="switch" class="mds-switch__input">
<span class="mds-switch__text"> Logic Mode </span>
</label>
</div>
<div class="mds-switch mds-switch--disabled mds-switch--standalone">
<label class="mds-switch__label" for="--42791">
<input id="--42791" type="checkbox" role="switch" class="mds-switch__input" disabled>
<span class="mds-switch__text"> Logic Mode </span>
</label>
</div>
<fieldset class="mds-switch__group" role="group">
<legend class="mds-switch__group-label"> Select all days that apply: </legend>
<div class="mds-switch">
<label class="mds-switch__label" for="--93150">
<input id="--93150" type="checkbox" role="switch" class="mds-switch__input">
<span class="mds-switch__text"> Monday </span>
</label>
</div>
<div class="mds-switch">
<label class="mds-switch__label" for="--14800">
<input id="--14800" type="checkbox" role="switch" class="mds-switch__input">
<span class="mds-switch__text"> Tuesday </span>
</label>
</div>
<div class="mds-switch">
<label class="mds-switch__label" for="--63043">
<input id="--63043" type="checkbox" role="switch" class="mds-switch__input">
<span class="mds-switch__text"> Wednesday </span>
</label>
</div>
<div class="mds-switch">
<label class="mds-switch__label" for="--82045">
<input id="--82045" type="checkbox" role="switch" class="mds-switch__input">
<span class="mds-switch__text"> Thursday </span>
</label>
</div>
<div class="mds-switch">
<label class="mds-switch__label" for="--77677">
<input id="--77677" type="checkbox" role="switch" class="mds-switch__input">
<span class="mds-switch__text"> Friday </span>
</label>
</div>
</fieldset>
role="switch"
ARIA attribute to represent “On/Off” rather than checked/unchecked states.role="group"
for grouped switches.spacebar
.aria-label
to an element (i.e., section title) to further enhance accessibility.Class | Applies to | Outcome |
---|---|---|
|
|
At parent level, this applies base-switch styles to an element. |
|
|
Applies hover state. |
|
|
Applies active state. |
|
|
Applies focus state. |
|
|
Applies disabled state. To properly disable interaction with the switch, add |
|
|
Hides label text although text is still readable by screen readers. |
|
|
Semantically structures a group of switches. Always include |
|
|
Apply to a parent wrapper of a fieldset to convert switches layout from vertical to horizontal. |