Checkbox
Enables users to select (or deselect) a single option in response to a question.
Examples
Usage
Use the checkbox component when you need to help users toggle a single option on or off.
Do:
- place the checkbox to the left of its label for accessibility
- provide a clear, concise label that describes the action or agreement
- if needed, provide a short hint below the label to clarify what the checkbox does
keep hint text to a single sentence without full stop - use it to check if the user agrees to something specific, like accepting the terms and conditions or choosing to join a service
- position any links to terms and conditions or related content before the checkbox, rather than placing them inside the label
Avoid:
- using a single checkbox when the user must choose one option from a list, use radio buttons instead
- triggering immediate actions with a checkbox, use a button for that
- pre-selecting the checkbox unless there is a strong, user-centred reason
- placing links inside checkbox labels, as this can cause usability and accessibility issues, particularly for touchscreen users
- placing links in hint text, as screen readers may not announce them properly
Parameters for turas-checkbox
- asp-for - Binds the checkbox to a model property
- checkbox-label - Sets the label text for the checkbox
- hide-required-marker - Hides the required marker if the checkbox is required
- heading-label - Sets a heading label for the checkbox
- guidance-text - Provides additional guidance text for the checkbox
- additional-classes - Allows for custom CSS classes to be added to the checkbox
- asp-is-disabled - Disables the checkbox if set to true
- hide-heading-label - Hides the heading label for the checkbox
- hide-validation-message - Hides the validation message for the checkbox
Close without saving
Are you sure you want to close without saving?
Any information you have entered will be lost!
Testing
Check that the checkbox:
- can be used with a keyboard only, using Tab to enter or leave the checkbox, Space to select an option with no keyboard traps
- shows a visible focus state on the checkbox that has keyboard focus
- focus moves logically in and out of the checkbox
- screen readers announce the question, each option and which option is selected
- hint text or instructions are read out by screen readers
- error messages are announced by screen readers and associated with the checkbox
- selecting an option does not automatically submit the form, move focus or take users to another page
- users are told when they must select an option
- remains usable at 400% zoom and supports reflow without horizontal scrolling
- makes it clear when selecting an option will reveal additional fields
- users can select an option by clicking or tapping its label
Developer considerations
When using the checkbox component in your form:
- always associate the checkbox with a visible <label> using for and id
- use the native <input type="checkbox"> element where possible
- ensure the checkbox has an accessible name using a visible label
- ensure each checkbox has a meaningful value
- avoid pre-selecting the checkbox unless there is a clear user benefit and it does not create a risk of unintended choices
- ensure custom checkbox components maintain native checkbox behaviour
- write error messages that explain what went wrong and how to fix it
- ensure the control works without JavaScript where possible
- ensure a visible focus state that meets contrast requirements
- ensure the component remains usable when text is resized and content reflows
- ensure sufficient touch target size and spacing, with a target size of at least 24 × 24 CSS pixels
Required fields
If your form contains fields that users must complete:
- clearly indicate when the checkbox or group is required by using a visual indicator such as an asterisk
- do not rely on the visual indicator alone (for example, an asterisk) to communicate that a field is required and include the help text “Required fields are marked with an asterisk *” at the top of every page of the form
- ensure the required state of the checkbox or group is programmatically available to assistive technologies using aria-required="true"
Conditional behaviour
If your checkbox reveals additional content based on a user's selection:
- only reveal content when it is logically dependent on the selection
- do not automatically move focus when content is revealed
- place revealed content directly after the checkbox that controls it in the DOM
- hide the content from all users, including assistive technology users, until it is needed
- ensure hidden fields are not focusable
- when revealed, ensure the content is reachable in the natural tab order
- consider adding hint text to explain that additional fields may appear
- use the Turas conditional reveal pattern so the new content is available to screen readers