UI components
Form controls
Form controls allow users to enter information into a page.
Checkboxes
Checkboxes allow users to select one or more options from a visible list.
<fieldset class="oit-fieldset-inputs oit-sans">
<legend class="oit-sr-only">Historical figures 1</legend>
<ul class="oit-unstyled-list">
<li>
<input id="truth" type="checkbox" name="historical-figures-1" value="truth" checked>
<label for="truth">Sojourner Truth</label>
</li>
<li>
<input id="douglass" type="checkbox" name="historical-figures-1" value="douglass">
<label for="douglass">Frederick Douglass</label>
</li>
<li>
<input id="washington" type="checkbox" name="historical-figures-1" value="washington">
<label for="washington">Booker T. Washington</label>
</li>
<li>
<input id="carver" type="checkbox" name="historical-figures-1" disabled>
<label for="carver">George Washington Carver</label>
</li>
</ul>
</fieldset>
Accessibility
If you customize the text inputs, ensure they continue to meet the the accessibility requirements that apply to all form controls.
- Surround a related set of checkboxes with a
<fieldset>
. The<legend>
provides context for the grouping. Do not use fieldset and legend for a single check. - The custom checkboxes here are accessible to screen readers because the default checkboxes are moved off-screen with
position: absolute; left: -999em
. - Each input should have a semantic
id
attribute, and its corresponding label should have the same value in it’sfor
attribute. - The
title
attribute can replace<label>
.
Usability
When to use
- When a user can select any number of choices from a set list.
- When a user needs to choose “yes” or “no” on only one option (use a stand-alone checkbox). For example, to toggle a setting on or off.
- When users need to see all the available options at a glance.
When to consider something different
- If there are too many options to display on a mobile screen.
- If a user can only select one option from a list (use radio buttons instead).
Guidelines
- Users should be able to tap on or click on either the text label or the checkbox to select or deselect an option.
- List options vertically if possible; horizontal listings can make it difficult to tell which label pertains to which checkbox.
- Avoid using negative language in labels as they can be counterintuitive. For example, “I want to receive a promotional email” instead of “I don’t want to receive promotional email.”
- If you customize, make sure selections are adequately spaced for touch screens.