Skip to Main Content

Checkboxes

Checkboxes let users select any number of options from a single list. A single checkbox lets a user turn an option on or off.

Use when:

  • User needs to make a choice or select an option.
  • User needs to indicate that they’ve completed a mandatory action.

Interactive component

Select a checkbox:

Disabled checkbox:

Select a checkbox:

This is where error message copy goes.

Library integration

Use the codes below to add this component to your project. Download the latest version of the library to easily implement our full range of components.

Angular

Step 1. Install

Execute the following command to install this component.

npm i [NPM-PLACE-HOLDER]/ds-checkbox

Step 2. Import

Import the following into your app.module.ts file.

import { DsCheckboxModule } from 'ds-checkbox';

Code snippet

<div role="group" aria-labelledby="checkbox-names foo">
    <p id="checkbox-names">Select a checkbox:</p>
    <cpc-ds-checkbox 
        *ngFor="let country of countries; let i=index" 
        formArrayName="selectedCountries" 
        id="country_{{i}}" 
        [text]="country.name" 
        [value]="country.value" 
        [checked]="i !== 2 ? false : true" 
        [disabled]="i === 3 ? true : false" 
        (change)="onCheckboxChange($event)">
    </cpc-ds-checkbox> 
    <div id="foo" class="ds-error">You must select an option</div>
</div>
Properties
Name Type Default Description
id string checkbox-id

id for the checkbox.

id is the same as the name of the checkbox.

text string Checkbox text here

The checkbox label.

value string Checkbox value

The checkbox value.

checked boolean false

Set the checkbox to checked by using “true”. Use "false" to set the checkbox to not checked.

disabled boolean false

Disable the checkbox using “true”.

Enable the checkbox using “false”.

(change) Method  

Call a method if you want to capture value to do an action

(change)="onCheckboxChange($event)"

HTML

Step 1: Import CSS

Import the following in your theme or page.

<link type="text/css" href="[CSS-PLACE-HOLDER]" rel="stylesheet">

Step 2: Import JS

<script src="[JS-PLACE-HOLDER]"></script>

Code snippet

<div role="group" aria-labelledby="checkbox-names fooCheckbox">
  <p class="checkbox" id="checkbox-names">Select a checkbox:</p>
  <div class="checkbox-container">
    <input id="oneCheckbox" class="by-keyboard" type="checkbox">
    <label for="oneCheckbox">One</label>
  </div>
 <div class="checkbox-container">
   <input id="twoCheckbox" class="by-keyboard" type="checkbox">
   <label for="twoCheckbox">Two</label>
  </div>
</div>

General guidelines

A checkbox allows the user to select options without deselecting others. It includes a checkbox icon and a label describing the selection. If the objective is to have the user make one selection, consider using radio buttons.

Positioning

Checkboxes are arranged like lists. Labels for checkbox items always appear to the right of the checkbox.

  • Stack checkbox items vertically. Horizontally arranged checkboxes are difficult to scan.

Responsive design

If checkbox copy is long and likely to wrap on smaller screens, make sure the copy wraps under the first letter of copy, not the checkbox button. When copy wraps, vertically align checkboxes with the first line of copy.

Interaction

States

The entire checkbox and label area is interactive. Checkboxes can have the following states:


  1. Default:
    In this state, a checkbox can be selected by clicking on it.
  2. Selected:
    In this state, a checkbox can be deselected by clicking on it.
  3. Focus:
    In this state, a checkbox will be surrounded by a blue box and activated by pressing spacebar. This state is critical for users that do not navigate your design by mouse.
  4. Disabled:
    In this state checkbox items cannot be selected, deselected, or activate a focus state.

Unselected

Unselected

Selected

Selected

Disabled

Disabled
  • Don’t preselect a checkbox unless you’re confident most users would make that selection.

Feedback

Error messages

When there is an error, the message is placed under the last checkbox item.

Error messages

Accessibility considerations

Keyboard accessibility

Checkbox focus states allow users to navigate checkbox options without a mouse. To provide visibility and context, the focus state should span the entire line, not just the checkbox itself.

The user can navigate checkbox options with tab and toggle between checked and unchecked states using the space bar.

Screen readers

Screen readers should announce the element as a checkbox, its associated label and its state.

With the same header, use <div role=”group”> to group checkboxes. Screen readers will announce the group of checkboxes according to the label you specify.

  • Though titling checkbox groups using headers or bold text is not necessary for screen readers, remember these elements are particularly useful for visual scanning.

Design specs

For all screen sizes.

For all screen sizes

General guidelines

A checkbox allows the user to select options without deselecting others. It includes a checkbox and a label describing the selection. If the objective is to have the user make one selection, consider using radio buttons.

Checkboxes are interactive and allow the user to select or deselect with a click. Content appears to the right of checkbox.

When writing for checkboxes, error messages let the user know what’s needed to proceed to complete the task. The error message appears under the last checkbox item.

  Guidelines Examples
Recommended length Use as needed to complete the thought but try to keep it to one line
Line wrap Minimize but not recommended; checkbox item should wrap under itself and not under the bullet
Phrasing Short phrases that explain each item
Case Sentence case

Dos and don’ts

Upper and lower case

Use sentence case. It helps with legibility.

Information architecture

Keep the copy short for each checkbox item so it’s clear and not cluttered.

Positive wording

Use positive, active wording on checkbox labels to be clear about what will happen if the user selects that checkbox. Avoid negations in wording for on, off, and opt-in checkboxes because they’re confusing to the user.

Code Samples

Basic

Note that this component may require additional styling.

Angular

<mat-checkbox> provides the same functionality as a native <input type="checkbox"> enhanced with Material Design styling and animations.

Note that this component may require additional styling.



Mendix

Checkboxes are an out-of-the-box functionality.

You simply need to select the Checkbox option from the toolbox on the right.

The styles for Checkboxes should be automatically applied along with the styles for their error states.

The Mendix toolkit can be found here.

Best practices

  • A checkbox allows for 1 or more selected values.
  • Each checkbox should be preceded by a label containing a descriptive value.
  • Clicking the label will select the associated checkbox.

Guidelines

Keyboard interaction

When the checkbox has focus:

  • Space: Changes the state of the checkbox (checked or not checked)
  • Tab: Focus moves to the next focusable element on the page
  • Shift + Tab: Focus moves to the previous focusable element on the page

Focus remains on the checkbox once its state is changed.

ARIA properties

The checkbox component can have the following ARIA properties:

  • There is no need to add the role attribute if using native <input type=”checkbox”/>.
  • The aria-checked state indication property can be set to "true" when checked and "false" when not checked.
  • The container can have the role of “group” when checkboxes are grouped together.
  • The group label and group error text are associated with the container using the aria-labelledby property. This property takes the ID of the group label and group error text as input.

Testing

When testing a checkbox, the tester must ensure:

  • The checkbox is fully keyboard operable
  • Indications for focused and the hovered states are clear and prominent
  • State change (checked/not checked) is clear and doesn't rely on colour alone
  • The checkbox doesn't cause an instant change and that the user can review the change and save the settings before they take effect
  • The checkbox has the role of “checkbox”
  • The screen reader announces the checkbox label, role, and state (checked/not checked)
  • The screen reader announces the group label and error text (if any) when entering a checkbox group

Related content