Switches afford a choice between one of two opposing states or options.
<div class="mds-switch">
<label class="mds-switch__label" for="--70358">
<input id="--70358" 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="--55738">
<input id="--55738" 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="--81777">
<input id="--81777" 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="--83223">
<input id="--83223" 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="--96145">
<input id="--96145" 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="--44257">
<input id="--44257" 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="--98728">
<input id="--98728" 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="--65972">
<input id="--65972" 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="--42955">
<input id="--42955" 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. |