Switches afford a choice between one of two opposing states or options.
<div class="mds-switch">
<label class="mds-switch__label" for="--90912">
<input id="--90912" 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="--14849">
<input id="--14849" 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="--95292">
<input id="--95292" 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="--14069">
<input id="--14069" 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="--23480">
<input id="--23480" 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="--52829">
<input id="--52829" 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="--39643">
<input id="--39643" 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="--74338">
<input id="--74338" 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="--1975">
<input id="--1975" 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. |