Switches afford a choice between one of two opposing states or options.
<div class="mds-switch">
<label class="mds-switch__label" for="--22422">
<input id="--22422" 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="--78453">
<input id="--78453" 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="--95324">
<input id="--95324" 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="--4338">
<input id="--4338" 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="--3455">
<input id="--3455" 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="--16225">
<input id="--16225" 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="--89476">
<input id="--89476" 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="--45201">
<input id="--45201" 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="--19724">
<input id="--19724" 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. |