Checkbox
Checkboxes appear as a square shaped UI accompanied by a caption. Checkboxes can be found in tables, forms, or in and around text inputs.
# Anatomy
# Behavior
Users can click a Checkbox to make a choice and click it again to deselect an option. They allow users to select one or more options of something.
# States
Checkboxes support several states: enabled, hover, focus, disabled, invalid, required, and indeterminate.
# Enabled
Checkboxes in their "unchecked" state are considered enabled. They are ready for user interaction.
# Hover
Hover states are activated when the user pauses their pointer over the input.
# Focus
The focus state is a visual affordance that the user has highlighted the input with a pointer, keyboard, or voice.
# Checked
Checked Checkboxes, sometimes referred to as "ticked", display a check to indicate the they are selected.
# Disabled
Disabled inputs are unavailable for interaction and cannot be focused. They can be used when input is disallowed, possibly due to a system state or access restrictions.
Checkboxes are disabled individually. The values of disabled inputs will not be submitted.
# Invalid
Checkboxes present as invalid when a required input is left unchecked or an incompatible choice has been made.
When indicating a validation error, please use a Field Error label to indicate the nature of the error. Color alone is not an accessible way to signify that something has gone wrong.
Unlike Radio Buttons, Checkboxes validate individually, not as a group.
# Required
Unlike other inputs, Odyssey assumes Checkboxes are optional by default.
Individual checkboxes can be set to required. This is useful when a user confirms they have read the terms of service.
# Indeterminate
In the case of nested checkboxes, an indeterminate state may be required.
Note that this state is visual-only and will be submitted as either "checked" or "unchecked" depending on the design of your UI.
| Item | Count | |
|---|---|---|
| Tribbles | 8,514,877 | |
| Tiny flags | 2,780,400 | |
| Moon rocks | 2,344,858 |
# Basic example
<fieldset class="ods-fieldset">
<legend class="ods-input-legend">Field legend label</legend>
<input class="ods-checkbox" type="checkbox" name="example-0" id="label-1" value="value-1" checked>
<label class="ods-checkbox--label" for="label-1">Label 1</label>
<input class="ods-checkbox" type="checkbox" name="example-0" id="label-2" value="value-2">
<label class="ods-checkbox--label" for="label-2">Label 2</label>
<input class="ods-checkbox" type="checkbox" name="example-0" id="label-3" value="value-3">
<label class="ods-checkbox--label" for="label-3">Label 3</label>
</fieldset>
# Checkbox Inline
<fieldset class="ods-fieldset">
<input class="ods-checkbox" type="checkbox" name="example-1" id="example-1" value="terms-accepted" checked required>
<label class="ods-checkbox--label" for="example-1">Inline label</label>
</fieldset>
# Checkbox State: Disabled
<fieldset class="ods-fieldset">
<legend class="ods-input-legend">Field legend label</legend>
<input class="ods-checkbox" type="checkbox" name="example-2" id="example-2-1" value="value-1" checked disabled>
<label class="ods-checkbox--label" for="example-2-1">Label 1</label>
<input class="ods-checkbox" type="checkbox" name="example-2" id="example-2-2" value="value-2" disabled>
<label class="ods-checkbox--label" for="example-2-2">Label 2</label>
<input class="ods-checkbox" type="checkbox" name="example-2" id="example-2-3" value="value-3" disabled>
<label class="ods-checkbox--label" for="example-2-3">Label 3</label>
</fieldset>
# Checkbox State: Error
<fieldset class="ods-fieldset">
<legend class="ods-input-legend">Field legend label</legend>
<input class="ods-checkbox" type="checkbox" name="example-3" id="example-3-1" value="value-1" checked data-invalid>
<label class="ods-checkbox--label" for="example-3-1">Label 1</label>
<input class="ods-checkbox" type="checkbox" name="example-3" id="example-3-2" value="value-2" data-invalid>
<label class="ods-checkbox--label" for="example-3-2">Label 2</label>
<input class="ods-checkbox" type="checkbox" name="example-3" id="example-3-3" value="value-3" data-invalid>
<label class="ods-checkbox--label" for="example-3-3">Label 3</label>
<aside class="ods-field--error" id="checkbox-invalid-error">Invalid error description</aside>
</fieldset>