Checkboxes
About this component
Checkboxes allow users to pick any number of items from a list. This is different from radio buttons, which allow users to pick one option at a time..
Why we use this component
We use this component when we want users to be able to:
- pick one or more items from a list
- toggle between selecting and deselecting an option
If users should only pick one option from a list, you should use the radio buttons component.
Other versions of this component
Checkboxes with hint text
You can add hint text to checkboxes, the same as you can with any other form component.
Small checkboxes
Small checkboxes look smaller but their actual size is the same as normal checkboxes. This keeps them easy for users to click.
Including a ‘none’ option
If ‘none’ is a valid response to a question, include it as an option. Do not expect the user to not select any checkboxes as their response.
You will know that the user has made a specific choice and that they have answered the question. Without the ‘none’ option it might not be clear whether the user has skipped the question or not.
Show the option for ‘none’ last in the options. Separate it from other options in the group with a divider, usually the word ‘or’.
The label for the ‘none’ option should relate to the question and not be the word ‘none’. For example, if the question was ‘Do you receive any of these benefits?’ you could use ‘No, I do not receive any of these benefits’.
You must add an attribute of data-behaviour="exclusive"
to the 'none' option's checkbox. This makes selection of the 'none' option and any other checkboxes exclusive.
Selecting the 'none' option will unselect any other checkboxes. Selecting other checkboxes with the 'none' option selected will unselect the 'none' option.
Add server-side validation to prevent invalid submissions. This is important if a user does not have JavaScript enabled in their browser.
Error messages
The error state for checkboxes marks the entire fieldset.
Website analytics
You can track checkbox items through the original page path and a data attribute identifying the checkbox and its value.
The Design System’s ‘tracking’ script adds this attribute.
Accessibility
We use a custom style for checkboxes. They are larger and easier to use than the standard checkboxes defined by a browser. We also make their focussed and selected states clearer.
You should only stack checkboxes vertically. This makes tabbing through the checkboxes easier to follow. It also makes it easier for screen magnifier users to find all the options.
Feedback, help and support
If you need help or support you can e-mail us at designsystem@gov.scot
There is a problem
Thanks for your feedback