2.17.0
Checkboxes afford one or more selection from a set of options.
See Forms for guidance on composing full forms.
Use when affording a binary selection.
<label class="mds-form__checkbox" for="checkbox-1">
<input id="checkbox-1" type="checkbox" class="mds-form__checkbox-input" value="accept" />
<span class="mds-form__checkbox-visible-wrap">
<span class="mds-form__checkbox-visual">
<svg class="mds-icon mds-form__checkbox-checked-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#check--s">
</use>
</svg>
<svg class="mds-icon mds-form__checkbox-indeterminate-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#minus--s">
</use>
</svg>
</span>
<span class="mds-form__checkbox-text">
I accept the terms and conditions.
</span>
</span>
</label>
<mds-checkbox id="checkbox-4" value="accept">I accept the terms and conditions.</mds-checkbox>
<label class="mds-form__checkbox mds-form__checkbox--disabled" for="checkbox-7">
<input id="checkbox-7" type="checkbox" class="mds-form__checkbox-input" disabled value="accept" />
<span class="mds-form__checkbox-visible-wrap">
<span class="mds-form__checkbox-visual">
<svg class="mds-icon mds-form__checkbox-checked-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#check--s">
</use>
</svg>
<svg class="mds-icon mds-form__checkbox-indeterminate-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#minus--s">
</use>
</svg>
</span>
<span class="mds-form__checkbox-text">
I accept the terms and conditions.
</span>
</span>
</label>
<mds-checkbox disabled id="checkbox-8" value="accept">I accept the terms and conditions.</mds-checkbox>
<label class="mds-form__checkbox" for="checkbox-9">
<input id="checkbox-9" type="checkbox" class="mds-form__checkbox-input" checked value="accept" />
<span class="mds-form__checkbox-visible-wrap">
<span class="mds-form__checkbox-visual">
<svg class="mds-icon mds-form__checkbox-checked-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#check--s">
</use>
</svg>
<svg class="mds-icon mds-form__checkbox-indeterminate-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#minus--s">
</use>
</svg>
</span>
<span class="mds-form__checkbox-text">
I accept the terms and conditions.
</span>
</span>
</label>
<mds-checkbox checked id="checkbox-13" value="accept">I accept the terms and conditions.</mds-checkbox>
<label class="mds-form__checkbox mds-form__checkbox--disabled" for="checkbox-17">
<input id="checkbox-17" type="checkbox" class="mds-form__checkbox-input" checked disabled value="accept" />
<span class="mds-form__checkbox-visible-wrap">
<span class="mds-form__checkbox-visual">
<svg class="mds-icon mds-form__checkbox-checked-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#check--s">
</use>
</svg>
<svg class="mds-icon mds-form__checkbox-indeterminate-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#minus--s">
</use>
</svg>
</span>
<span class="mds-form__checkbox-text">
I accept the terms and conditions.
</span>
</span>
</label>
<mds-checkbox checked disabled id="checkbox-18" value="accept">I accept the terms and conditions.</mds-checkbox>
Use when enabling selection of an object such as a Card.
<label class="mds-form__checkbox mds-form__checkbox--hide-label" for="checkbox-19">
<input id="checkbox-19" type="checkbox" class="mds-form__checkbox-input" value="no-label" />
<span class="mds-form__checkbox-visible-wrap">
<span class="mds-form__checkbox-visual">
<svg class="mds-icon mds-form__checkbox-checked-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#check--s">
</use>
</svg>
<svg class="mds-icon mds-form__checkbox-indeterminate-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#minus--s">
</use>
</svg>
</span>
<span class="mds-form__checkbox-text">
I accept the terms and conditions
</span>
</span>
</label>
<mds-checkbox hidden-text id="checkbox-24" value="no-label">I accept the terms and conditions.</mds-checkbox>
<label>
element, even if it is hidden from the screen.Use when affording multiple selections from a set of options.
<form class="mds-form mds-form--medium-layout" method="post" action="form/processor">
<div class="mds-form__field-group">
<fieldset class="mds-form__checkbox-group" role="group">
<legend class="mds-form__checkbox-group-label">
Select statistics to view.
</legend>
<label class="mds-form__checkbox" for="statistics-id-65461">
<input id="statistics-id-65461" type="checkbox" class="mds-form__checkbox-input" value="average" />
<span class="mds-form__checkbox-visible-wrap">
<span class="mds-form__checkbox-visual">
<svg class="mds-icon mds-form__checkbox-checked-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#check--s">
</use>
</svg>
<svg class="mds-icon mds-form__checkbox-indeterminate-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#minus--s">
</use>
</svg>
</span>
<span class="mds-form__checkbox-text">
Average
</span>
</span>
</label>
<label class="mds-form__checkbox" for="statistics-id-65461">
<input id="statistics-id-65461" type="checkbox" class="mds-form__checkbox-input" value="minimum" />
<span class="mds-form__checkbox-visible-wrap">
<span class="mds-form__checkbox-visual">
<svg class="mds-icon mds-form__checkbox-checked-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#check--s">
</use>
</svg>
<svg class="mds-icon mds-form__checkbox-indeterminate-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#minus--s">
</use>
</svg>
</span>
<span class="mds-form__checkbox-text">
Minimum
</span>
</span>
</label>
<label class="mds-form__checkbox" for="statistics-id-65461">
<input id="statistics-id-65461" type="checkbox" class="mds-form__checkbox-input" value="maximum" />
<span class="mds-form__checkbox-visible-wrap">
<span class="mds-form__checkbox-visual">
<svg class="mds-icon mds-form__checkbox-checked-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#check--s">
</use>
</svg>
<svg class="mds-icon mds-form__checkbox-indeterminate-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#minus--s">
</use>
</svg>
</span>
<span class="mds-form__checkbox-text">
Maximum
</span>
</span>
</label>
<label class="mds-form__checkbox" for="statistics-id-65461">
<input id="statistics-id-65461" type="checkbox" class="mds-form__checkbox-input" value="median" />
<span class="mds-form__checkbox-visible-wrap">
<span class="mds-form__checkbox-visual">
<svg class="mds-icon mds-form__checkbox-checked-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#check--s">
</use>
</svg>
<svg class="mds-icon mds-form__checkbox-indeterminate-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#minus--s">
</use>
</svg>
</span>
<span class="mds-form__checkbox-text">
Median
</span>
</span>
</label>
</fieldset>
</div>
</form>
<form class="mds-form mds-form--medium-layout" method="post" action="form/processor">
<mds-field-group>
<mds-checkbox-group label="Select statistics to view.">
<mds-checkbox id="checkbox-29" value="average">Average</mds-checkbox>
<mds-checkbox id="checkbox-30" value="minimum">Minimum</mds-checkbox>
<mds-checkbox id="checkbox-31" value="maximum">Maximum</mds-checkbox>
<mds-checkbox id="checkbox-32" value="median">Median</mds-checkbox>
</mds-checkbox-group>
</mds-field-group>
</form>
<form class="mds-form mds-form--medium-layout" method="post" action="form/processor">
<div class="mds-form__field-group mds-form__field-group--horizontal">
<fieldset class="mds-form__checkbox-group" role="group">
<legend class="mds-form__checkbox-group-label">
Select statistics to view.
</legend>
<label class="mds-form__checkbox" for="statistics-id-65461">
<input id="statistics-id-65461" type="checkbox" class="mds-form__checkbox-input" value="average" />
<span class="mds-form__checkbox-visible-wrap">
<span class="mds-form__checkbox-visual">
<svg class="mds-icon mds-form__checkbox-checked-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#check--s">
</use>
</svg>
<svg class="mds-icon mds-form__checkbox-indeterminate-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#minus--s">
</use>
</svg>
</span>
<span class="mds-form__checkbox-text">
Average
</span>
</span>
</label>
<label class="mds-form__checkbox" for="statistics-id-65461">
<input id="statistics-id-65461" type="checkbox" class="mds-form__checkbox-input" value="minimum" />
<span class="mds-form__checkbox-visible-wrap">
<span class="mds-form__checkbox-visual">
<svg class="mds-icon mds-form__checkbox-checked-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#check--s">
</use>
</svg>
<svg class="mds-icon mds-form__checkbox-indeterminate-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#minus--s">
</use>
</svg>
</span>
<span class="mds-form__checkbox-text">
Minimum
</span>
</span>
</label>
<label class="mds-form__checkbox" for="statistics-id-65461">
<input id="statistics-id-65461" type="checkbox" class="mds-form__checkbox-input" value="maximum" />
<span class="mds-form__checkbox-visible-wrap">
<span class="mds-form__checkbox-visual">
<svg class="mds-icon mds-form__checkbox-checked-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#check--s">
</use>
</svg>
<svg class="mds-icon mds-form__checkbox-indeterminate-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#minus--s">
</use>
</svg>
</span>
<span class="mds-form__checkbox-text">
Maximum
</span>
</span>
</label>
<label class="mds-form__checkbox" for="statistics-id-65461">
<input id="statistics-id-65461" type="checkbox" class="mds-form__checkbox-input" value="median" />
<span class="mds-form__checkbox-visible-wrap">
<span class="mds-form__checkbox-visual">
<svg class="mds-icon mds-form__checkbox-checked-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#check--s">
</use>
</svg>
<svg class="mds-icon mds-form__checkbox-indeterminate-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#minus--s">
</use>
</svg>
</span>
<span class="mds-form__checkbox-text">
Median
</span>
</span>
</label>
</fieldset>
</div>
</form>
<form class="mds-form mds-form--medium-layout" method="post" action="form/processor">
<mds-field-group horizontal>
<mds-checkbox-group label="Select statistics to view.">
<mds-checkbox id="checkbox-33" value="average">Average</mds-checkbox>
<mds-checkbox id="checkbox-34" value="minimum">Minimum</mds-checkbox>
<mds-checkbox id="checkbox-35" value="maximum">Maximum</mds-checkbox>
<mds-checkbox id="checkbox-36" value="median">Median</mds-checkbox>
</mds-checkbox-group>
</mds-field-group>
</form>
Use when affording a “Select All” option. After selecting all items, the indeterminate state is triggered once an option is deselected.
<label class="mds-form__checkbox" for="checkbox-37">
<input id="checkbox-37" type="checkbox" class="mds-form__checkbox-input" checked value="indetrminate" />
<span class="mds-form__checkbox-visible-wrap">
<span class="mds-form__checkbox-visual">
<svg class="mds-icon mds-form__checkbox-checked-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#check--s">
</use>
</svg>
<svg class="mds-icon mds-form__checkbox-indeterminate-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#minus--s">
</use>
</svg>
</span>
<span class="mds-form__checkbox-text">
Indeterminate checkbox
</span>
</span>
</label>
<!-- Something like the following Javascript would be required to set an indeterminate state on a checkbox -->
<script>
document.getElementById("checkbox-37").indeterminate = true;
</script>
<mds-checkbox checked indeterminate id="checkbox-38" value="indeterminate">Indeterminate checkbox</mds-checkbox>
Sizing affects checkbox size and text size. The default size is medium, and you can use modifier classes or props to make the checkbox smaller or larger.
<label class="mds-form__checkbox mds-form__checkbox--small" for="small-checkbox">
<input id="small-checkbox" type="checkbox" class="mds-form__checkbox-input" value="small" />
<span class="mds-form__checkbox-visible-wrap">
<span class="mds-form__checkbox-visual">
<svg class="mds-icon mds-form__checkbox-checked-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#check--s">
</use>
</svg>
<svg class="mds-icon mds-form__checkbox-indeterminate-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#minus--s">
</use>
</svg>
</span>
<span class="mds-form__checkbox-text">
Checkbox Label
</span>
</span>
</label>
<br>
<label class="mds-form__checkbox mds-form__checkbox--hide-label mds-form__checkbox--small" for="small-checkbox-without-label">
<input id="small-checkbox-without-label" type="checkbox" class="mds-form__checkbox-input" value="small" />
<span class="mds-form__checkbox-visible-wrap">
<span class="mds-form__checkbox-visual">
<svg class="mds-icon mds-form__checkbox-checked-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#check--s">
</use>
</svg>
<svg class="mds-icon mds-form__checkbox-indeterminate-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#minus--s">
</use>
</svg>
</span>
<span class="mds-form__checkbox-text">
Checkbox Label
</span>
</span>
</label>
<mds-checkbox size="small" id="small-wc-checkbox" value="small">Checkbox Label</mds-checkbox>
<br>
<mds-checkbox hidden-text="true" id="small-checkbox-wc-without-label" value="small">Checkbox Label</mds-checkbox>
mds-form__checkbox-without-label
class in conjunction with checkbox sizing modifier classes to render different sizes of the Without Label variation.:hover
and :active
styles as the primary Button when checked.
Class
|
Applies to
|
Outcome
|
---|---|---|
|
|
Adjusts styling to render a small checkbox. |
|
|
Adjusts styling to render a large checkbox. |
|
|
Hides label text, although screen readers can still access it. |
|
|
Adjusts styling to render a small checkbox group label. |
|
|
Adjusts styling to render a large checkbox group label. |
Checkboxes are comprised of two separate web components, each with a dedicated API:
<mds-checkbox>
elements to present them as a group.
Prop
|
Type
|
Validation
|
Default
|
Description
|
---|---|---|---|---|
|
Boolean |
— |
|
Sets the checked value of the checkbox. |
|
String |
— |
— |
A space-separated list of class names that will be appended to the default |
|
Boolean |
— |
|
If |
|
Boolean |
— |
|
When |
|
String |
Required |
— |
The |
|
Boolean |
— |
|
If |
|
String |
One of: |
|
Alters the size of the checkbox. |
|
String |
Required |
— |
The text for the checkbox. Can also be passed via the default slot. |
|
String |
Required |
— |
The checkbox value. |
hiddenLabel
would be written as hidden-label
.Pass text in between the <mds-checkbox></mds-checkbox>
tags to set the checkbox’s label text. This can be overridden with the text
prop.
Setting size
and checked
via props. Using the default slot for the label text:
<mds-checkbox size="small" checked> I accept </mds-checkbox>
Setting hidden-label
and text
via props:
<mds-checkbox hidden-label="true" text="Portfolio 1"></mds-checkbox>
Prop
|
Type
|
Validation
|
Default
|
Description
|
---|---|---|---|---|
|
String |
— |
Please select an option. |
Sets the checkbox group label’s required indicator |
|
String |
— |
— |
A space-separated list of class names that will be appended to the default |
|
String |
— |
— |
The |
|
String |
Required |
— |
Label for the checkbox group. |
|
Boolean |
— |
|
If |
|
String |
— |
(Optional) |
Use to override the default optional indicator text. |
|
Boolean |
— |
|
If |
|
String |
One of: |
|
Alters the size of the checkbox group label. |
optionalText
would be written as optional-text
.Pass two or more <mds-checkbox>
elements between the <mds-checkbox-group></mds-checkbox-group>
tags to set the content of the checkbox group.
Setting label
and required
via props. Using the default slot for the checkboxes in the group:
<mds-checkbox-group required label="Choose your options.">
<mds-checkbox id="checkbox-option-1" value="option-1"> Option 1 </mds-checkbox>
<mds-checkbox id="checkbox-option-2" value="option-2"> Option 2 </mds-checkbox>
</mds-checkbox-group>
fieldset
and legend
for checkbox groups. See the form structure guidelines in the Forms composition section for more information.