Checkbox
BetaFormsOpen in the workshop
Independent yes/no choices, and row selection in tables.
.xg-check > input[type=checkbox] + text · .xg-check__hint · :indeterminateExample and markup
Live, from xg-ui.css and xg-ui.js. Switch the brand and mode on the example itself, or for the whole site in the header.
Markup
<fieldset class="xg-fieldset">
<legend class="xg-label">Ad formats</legend>
<label class="xg-check">
<input type="checkbox" checked>Banner</label>
<label class="xg-check">
<input type="checkbox" checked>Video</label>
<label class="xg-check">
<input type="checkbox">Native<span class="xg-check__hint">Needs a native template</span>
</label>
<label class="xg-check">
<input type="checkbox" disabled>Audio (not on your plan)</label>
</fieldset>States
Hover, focus and pressed are forced here with .is-hover, .is-focus and .is-active so they can be seen side by side; in a product they come from :hover, :focus-visible and :active.
| State | Checkbox |
|---|---|
| Unchecked | |
| Checked | |
| Indeterminate | |
| Disabled | |
| Disabled checked |
When to use it
Use it for
several options that can all be true; agreeing to terms; selecting rows.
Not for
a setting that applies immediately (use Switch); one of several (use Radio).
Rules
- Label to the right, clickable. Positive phrasing (“Send weekly report”, not “Don’t send…”).
- The select-all checkbox in a table header shows indeterminate when some rows are selected.
Accessibility
- Native input; check mark contrast 3:1 on the control fill (primary-on-control).
- Group related checkboxes in a <fieldset> with a <legend>.
Every color pair this component uses is measured for both brands in light and dark on the Accessibility page.
Related
Also in Forms: Input, Textarea, Select, Radio, Switch, Segmented control, Search field, Date-range picker, Form layout. Used in the patterns Onboarding and sign-up.
Status Beta: usable; class names may still change in a minor release, with a note (see Releasing).