Checkboxes
Let users select one or more options by using the checkboxes component.
<div class="govuk-form-group">
<fieldset class="govuk-fieldset" aria-describedby="waste-hint">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--xl">
<h1 class="govuk-fieldset__heading">
Which types of waste do you transport?
</h1>
</legend>
<span id="waste-hint" class="govuk-hint">
Select all that apply.
</span>
<div class="govuk-checkboxes">
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="waste-1" name="waste" type="checkbox" value="carcasses">
<label class="govuk-label govuk-checkboxes__label" for="waste-1">
Waste from animal carcasses
</label>
</div>
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="waste-2" name="waste" type="checkbox" value="mines">
<label class="govuk-label govuk-checkboxes__label" for="waste-2">
Waste from mines or quarries
</label>
</div>
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="waste-3" name="waste" type="checkbox" value="farm">
<label class="govuk-label govuk-checkboxes__label" for="waste-3">
Farm or agricultural waste
</label>
</div>
</div>
</fieldset>
</div>
{% from "checkboxes/macro.njk" import govukCheckboxes %}
{{ govukCheckboxes({
idPrefix: "waste",
name: "waste",
fieldset: {
legend: {
text: "Which types of waste do you transport?",
isPageHeading: true,
classes: "govuk-fieldset__legend--xl"
}
},
hint: {
text: "Select all that apply."
},
items: [
{
value: "carcasses",
text: "Waste from animal carcasses"
},
{
value: "mines",
text: "Waste from mines or quarries"
},
{
value: "farm",
text: "Farm or agricultural waste"
}
]
}) }}
When to use this component
Use the checkboxes component when you need to help users:
- select multiple options from a list
- toggle a single option on or off
When not to use this component
Do not use the checkboxes component if users can only choose one option from a selection. In this case, use the radios component.
How it works
Checkboxes are grouped together in a <fieldset> with a <legend> that describes them, as shown in the examples on this page. This is usually a question, like ‘How would you like to be contacted?’.
If you are asking just one question per page as recommended, you can set the contents of the <legend> as the page heading. This is good practice as it means that users of screen readers will only hear the contents once.
Read more about why and how to set legends as headings.
Always position checkboxes to the left of their labels. This makes them easier to find, especially for users of screen magnifiers.
Unlike with radios, users can select multiple options from a list of checkboxes. Do not assume that users will know how many options they can select based on the visual difference between radios and checkboxes alone.
If needed, add a hint explaining this, for example, ‘Select all that apply’.
There are 2 ways to use the checkboxes component. You can use HTML or, if you’re using Nunjucks or the GOV.UK Prototype Kit, you can use the Nunjucks macro.
<div class="govuk-form-group">
<fieldset class="govuk-fieldset" aria-describedby="waste-hint">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--xl">
<h1 class="govuk-fieldset__heading">
Which types of waste do you transport?
</h1>
</legend>
<span id="waste-hint" class="govuk-hint">
Select all that apply.
</span>
<div class="govuk-checkboxes">
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="waste-1" name="waste" type="checkbox" value="carcasses">
<label class="govuk-label govuk-checkboxes__label" for="waste-1">
Waste from animal carcasses
</label>
</div>
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="waste-2" name="waste" type="checkbox" value="mines">
<label class="govuk-label govuk-checkboxes__label" for="waste-2">
Waste from mines or quarries
</label>
</div>
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="waste-3" name="waste" type="checkbox" value="farm">
<label class="govuk-label govuk-checkboxes__label" for="waste-3">
Farm or agricultural waste
</label>
</div>
</div>
</fieldset>
</div>
{% from "checkboxes/macro.njk" import govukCheckboxes %}
{{ govukCheckboxes({
idPrefix: "waste",
name: "waste",
fieldset: {
legend: {
text: "Which types of waste do you transport?",
isPageHeading: true,
classes: "govuk-fieldset__legend--xl"
}
},
hint: {
text: "Select all that apply."
},
items: [
{
value: "carcasses",
text: "Waste from animal carcasses"
},
{
value: "mines",
text: "Waste from mines or quarries"
},
{
value: "farm",
text: "Farm or agricultural waste"
}
]
}) }}
Checkbox items with hints
You can add hints to checkbox items to provide additional information about the options.
<div class="govuk-form-group">
<fieldset class="govuk-fieldset" aria-describedby="nationality-hint">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--xl">
<h1 class="govuk-fieldset__heading">
What is your nationality?
</h1>
</legend>
<span id="nationality-hint" class="govuk-hint">
If you have dual nationality, select all options that are relevant to you.
</span>
<div class="govuk-checkboxes">
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="nationality-1" name="nationality" type="checkbox" value="british" aria-describedby="nationality-1-item-hint">
<label class="govuk-label govuk-checkboxes__label" for="nationality-1">
British
</label>
<span id="nationality-1-item-hint" class="govuk-hint govuk-checkboxes__hint">
including English, Scottish, Welsh and Northern Irish
</span>
</div>
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="nationality-2" name="nationality" type="checkbox" value="irish">
<label class="govuk-label govuk-checkboxes__label" for="nationality-2">
Irish
</label>
</div>
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="nationality-3" name="nationality" type="checkbox" value="other">
<label class="govuk-label govuk-checkboxes__label" for="nationality-3">
Citizen of another country
</label>
</div>
</div>
</fieldset>
</div>
{% from "checkboxes/macro.njk" import govukCheckboxes %}
{{ govukCheckboxes({
idPrefix: "nationality",
name: "nationality",
fieldset: {
legend: {
text: "What is your nationality?",
isPageHeading: true,
classes: "govuk-fieldset__legend--xl"
}
},
hint: {
text: "If you have dual nationality, select all options that are relevant to you."
},
items: [
{
value: "british",
text: "British",
hint: {
text: "including English, Scottish, Welsh and Northern Irish"
}
},
{
value: "irish",
text: "Irish"
},
{
value: "other",
text: "Citizen of another country"
}
]
}) }}
Conditionally revealing content
You can add conditionally revealing content to checkboxes, so users only see content when it’s relevant to them. For example, you could reveal a phone number input only when a user chooses to be contacted by phone.
<div class="govuk-form-group">
<fieldset class="govuk-fieldset" aria-describedby="citizenship-conditional-hint">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--xl">
<h1 class="govuk-fieldset__heading">
How would you like to be contacted?
</h1>
</legend>
<span id="citizenship-conditional-hint" class="govuk-hint">
Select all options that are relevant to you.
</span>
<div class="govuk-checkboxes" data-module="checkboxes">
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="citizenship-conditional-1" name="citizen" type="checkbox" value="email" data-aria-controls="conditional-citizenship-conditional-1">
<label class="govuk-label govuk-checkboxes__label" for="citizenship-conditional-1">
Email
</label>
</div>
<div class="govuk-checkboxes__conditional govuk-checkboxes__conditional--hidden" id="conditional-citizenship-conditional-1">
<div class="govuk-form-group">
<label class="govuk-label" for="contact-by-email">
Email address
</label>
<input class="govuk-input govuk-!-width-one-third" id="contact-by-email" name="contact-by-email" type="email">
</div>
</div>
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="citizenship-conditional-2" name="citizen" type="checkbox" value="phone" data-aria-controls="conditional-citizenship-conditional-2">
<label class="govuk-label govuk-checkboxes__label" for="citizenship-conditional-2">
Phone
</label>
</div>
<div class="govuk-checkboxes__conditional govuk-checkboxes__conditional--hidden" id="conditional-citizenship-conditional-2">
<div class="govuk-form-group">
<label class="govuk-label" for="contact-by-phone">
Phone number
</label>
<input class="govuk-input govuk-!-width-one-third" id="contact-by-phone" name="contact-by-phone" type="tel">
</div>
</div>
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="citizenship-conditional-3" name="citizen" type="checkbox" value="text message" data-aria-controls="conditional-citizenship-conditional-3">
<label class="govuk-label govuk-checkboxes__label" for="citizenship-conditional-3">
Text message
</label>
</div>
<div class="govuk-checkboxes__conditional govuk-checkboxes__conditional--hidden" id="conditional-citizenship-conditional-3">
<div class="govuk-form-group">
<label class="govuk-label" for="contact-by-text">
Mobile phone number
</label>
<input class="govuk-input govuk-!-width-one-third" id="contact-by-text" name="contact-by-text" type="tel">
</div>
</div>
</div>
</fieldset>
</div>
{% from "checkboxes/macro.njk" import govukCheckboxes %}
{% from "input/macro.njk" import govukInput %}
{% set emailHtml %}
{{ govukInput({
id: "contact-by-email",
name: "contact-by-email",
type: "email",
classes: "govuk-!-width-one-third",
label: {
text: "Email address"
}
}) }}
{% endset -%}
{% set phoneHtml %}
{{ govukInput({
id: "contact-by-phone",
name: "contact-by-phone",
type: "tel",
classes: "govuk-!-width-one-third",
label: {
text: "Phone number"
}
}) }}
{% endset -%}
{% set textHtml %}
{{ govukInput({
id: "contact-by-text",
name: "contact-by-text",
type: "tel",
classes: "govuk-!-width-one-third",
label: {
text: "Mobile phone number"
}
}) }}
{% endset -%}
{{ govukCheckboxes({
idPrefix: "citizenship-conditional",
name: "citizen",
fieldset: {
legend: {
text: "How would you like to be contacted?",
isPageHeading: true,
classes: "govuk-fieldset__legend--xl"
}
},
hint: {
text: "Select all options that are relevant to you."
},
items: [
{
value: "email",
text: "Email",
conditional: {
html: emailHtml
}
},
{
value: "phone",
text: "Phone",
conditional: {
html: phoneHtml
}
},
{
value: "text message",
text: "Text message",
conditional: {
html: textHtml
}
}
]
}) }}
Keep it simple - if you need to add a lot of content, consider showing it on the next page in the process instead.
Error messages
Error messages should be styled like this:
<div class="govuk-form-group govuk-form-group--error">
<fieldset class="govuk-fieldset" aria-describedby="nationality-hint nationality-error">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--xl">
<h1 class="govuk-fieldset__heading">
What is your nationality?
</h1>
</legend>
<span id="nationality-hint" class="govuk-hint">
If you have dual nationality, select all options that are relevant to you.
</span>
<span id="nationality-error" class="govuk-error-message">
Select if you are British, Irish or a citizen of a different country
</span>
<div class="govuk-checkboxes">
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="nationality-1" name="nationality" type="checkbox" value="british" aria-describedby="nationality-1-item-hint">
<label class="govuk-label govuk-checkboxes__label" for="nationality-1">
British
</label>
<span id="nationality-1-item-hint" class="govuk-hint govuk-checkboxes__hint">
including English, Scottish, Welsh and Northern Irish
</span>
</div>
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="nationality-2" name="nationality" type="checkbox" value="irish">
<label class="govuk-label govuk-checkboxes__label" for="nationality-2">
Irish
</label>
</div>
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="nationality-3" name="nationality" type="checkbox" value="other">
<label class="govuk-label govuk-checkboxes__label" for="nationality-3">
Citizen of another country
</label>
</div>
</div>
</fieldset>
</div>
{% from "checkboxes/macro.njk" import govukCheckboxes %}
{{ govukCheckboxes({
idPrefix: "nationality",
name: "nationality",
fieldset: {
legend: {
text: "What is your nationality?",
isPageHeading: true,
classes: "govuk-fieldset__legend--xl"
}
},
hint: {
text: "If you have dual nationality, select all options that are relevant to you."
},
errorMessage: {
text: "Select if you are British, Irish or a citizen of a different country"
},
items: [
{
value: "british",
text: "British",
hint: {
text: "including English, Scottish, Welsh and Northern Irish"
}
},
{
value: "irish",
text: "Irish"
},
{
value: "other",
text: "Citizen of another country"
}
]
}) }}
Make sure errors follow the guidance in error message and have specific error messages for specific error states.
If nothing is selected and the question has options in it
Say ‘Select if [whatever it is]’.
For example, ‘Select if you are British, Irish or a citizen of a different country’.
If nothing is selected and the question does not have options in it
Say ‘Select [whatever it is]’.
For example, ‘Select your nationality or nationalities’.
Research on this component
Read a blog post about updates to the radios and checkboxes components.
Get in touch
If you’ve got a question, idea or suggestion share it in #govuk-design-system on cross-government Slack (open in app) or email the Design System team on govuk-design-system-support@digital.cabinet-office.gov.uk