Checkbox
<label class="label"> <input class="checkbox" type="checkbox" checked /> Accept terms and conditions</label><label class="label"> <input class="checkbox" type="checkbox" name="terms" /> Accept terms and conditions</label>States
Section titled “States”<label class="label"> <input class="checkbox" type="checkbox" /> Unchecked</label>
<label class="label"> <input class="checkbox" type="checkbox" checked /> Checked</label>
<label class="label"> <input class="checkbox" type="checkbox" data-indeterminate /> Indeterminate</label>
<label class="label"> <input class="checkbox" type="checkbox" disabled /> Disabled</label>
<label class="label"> <input class="checkbox" type="checkbox" aria-invalid="true" /> Invalid</label>| State | How |
|---|---|
| Checked | the native checked attribute |
| Indeterminate | data-indeterminate on the input |
| Disabled | the native disabled attribute |
| Invalid | aria-invalid="true" |
Indeterminate
Section titled “Indeterminate”The third state exists only as a DOM property — there is no HTML attribute for it, so
server-rendered markup has no way to say it. partialkit closes that gap: put data-indeterminate
on the input and the runtime sets the property.
<input class="checkbox" type="checkbox" data-indeterminate />Toggling the checkbox clears it, the same way a real click resolves the third state.
Use it for a parent checkbox whose children are partly selected — never as a value of its own, since it does not submit.
A summary of what changed, every Monday.
<div class="field" data-orientation="horizontal"> <input class="checkbox" type="checkbox" id="checkbox-newsletter" /> <div class="field-content"> <label class="field-title" for="checkbox-newsletter">Weekly digest</label> <p class="field-description">A summary of what changed, every Monday.</p> </div></div>.field-content keeps the title and description together beside the control, and clicking the
title toggles it because for points at the input.
A set of checkboxes belongs in a <fieldset> with a <legend>, which names the group for every
control inside it. Give them the same name so they submit as one list.
<fieldset class="field-set"> <legend class="field-legend" data-variant="label">Notifications</legend>
<label class="label"> <input class="checkbox" type="checkbox" name="notify" value="deploys" checked /> Deploys </label> <label class="label"> <input class="checkbox" type="checkbox" name="notify" value="incidents" checked /> Incidents </label> <label class="label"> <input class="checkbox" type="checkbox" name="notify" value="digest" /> Weekly digest </label></fieldset>Set dir="rtl" on the page or on any subtree — the control moves to the other side of its label on
its own. See the button page for a live example.
Accessibility
Section titled “Accessibility”- The label is the hit area. Wrapping the input, or
forpointing at itsid, is what makes clicking the text toggle it — and what a screen reader announces. - The box has a larger hit target than it looks, extended beyond the 16px square, so it is reachable on touch without changing the layout.
- Do not use a checkbox for an immediate action. A checkbox is a value in a form. Something that takes effect the moment you touch it is a switch.