Switches afford a choice between one of two opposing states or options.
<div class="mds-switch">
<label class="mds-switch__label" for="--35808">
<input id="--35808" 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="--13205">
<input id="--13205" type="checkbox" role="switch" class="mds-switch__input" disabled>
<span class="mds-switch__text"> Logic Mode </span>
</label>
</div>
Use when the purpose of a switch is clearly implied by its proximity to other content and controls.
<div class="mds-switch mds-switch--hide-label">
<label class="mds-switch__label" for="--38006">
<input id="--38006" 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--hide-label">
<label class="mds-switch__label" for="--24994">
<input id="--24994" 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"> Client Configuration Options </legend>
<div class="mds-switch">
<label class="mds-switch__label" for="--59226">
<input id="--59226" type="checkbox" role="switch" class="mds-switch__input">
<span class="mds-switch__text"> Display Overview/Investment </span>
</label>
</div>
<div class="mds-switch">
<label class="mds-switch__label" for="--6271">
<input id="--6271" type="checkbox" role="switch" class="mds-switch__input">
<span class="mds-switch__text"> Display Account Details </span>
</label>
</div>
<div class="mds-switch">
<label class="mds-switch__label" for="--86618">
<input id="--86618" type="checkbox" role="switch" class="mds-switch__input">
<span class="mds-switch__text"> Display Benchmark Returns </span>
</label>
</div>
<div class="mds-switch">
<label class="mds-switch__label" for="--29483">
<input id="--29483" type="checkbox" role="switch" class="mds-switch__input">
<span class="mds-switch__text"> Allow Clients to Generate Reports </span>
</label>
</div>
<div class="mds-switch">
<label class="mds-switch__label" for="--83227">
<input id="--83227" type="checkbox" role="switch" class="mds-switch__input">
<span class="mds-switch__text"> Display Document Manager </span>
</label>
</div>
</fieldset>
Sizing affects the switch size, text size, and internal spacing. The default size is medium, and you can use a modifier class to make the switch smaller (mds-switch--small
) or larger (mds-switch--large
).
<div class="mds-switch mds-switch--small">
<label class="mds-switch__label" for="--34350">
<input id="--34350" type="checkbox" role="switch" class="mds-switch__input" checked>
<span class="mds-switch__text"> Logic Mode </span>
</label>
</div>
<br/>
<div class="mds-switch mds-switch--small mds-switch--hide-label">
<label class="mds-switch__label" for="--44891">
<input id="--44891" type="checkbox" role="switch" class="mds-switch__input" checked>
<span class="mds-switch__text"> Logic Mode </span>
</label>
</div>
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. |
|
|
Adjusts styling to render a small switch. |
|
|
Adjusts styling to render a large switch. |
|
|
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. |