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--l">
<h1 class="govuk-fieldset__heading">
Which types of waste do you transport?
</h1>
</legend>
<div id="waste-hint" class="govuk-hint">
Select all that apply.
</div>
<div class="govuk-checkboxes">
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="waste" name="waste" type="checkbox" value="carcasses">
<label class="govuk-label govuk-checkboxes__label" for="waste">
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>
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work; these are marked as "Required" in the option description.
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.
Name | Type | Description |
---|---|---|
describedBy | string |
One or more element IDs to add to the input aria-describedby attribute without a fieldset, used to provide additional descriptive information for screenreader users.
|
fieldset | object | Options for the fieldset component (e.g. legend). See fieldset. |
hint | object | Options for the hint component (e.g. text). See hint. |
errorMessage | object |
Options for the error message component. The error message component will not display if you use a falsy value for errorMessage , for example false or null .
See errorMessage.
|
formGroup | object | Options for the form-group wrapper See formGroup. |
idPrefix | string | String to prefix id for each checkbox item if no id is specified on each item. If not passed, fall back to using the name option instead. |
name | string | Required. Name attribute for all checkbox items. |
items | array | Required. Array of checkbox items objects. See items. |
classes | string | Classes to add to the checkboxes container. |
attributes | object | HTML attributes (for example data attributes) to add to the anchor tag. |
Name | Type | Description |
---|---|---|
classes | string | Classes to add to the form group (e.g. to show error state for the whole group) |
Name | Type | Description |
---|---|---|
text | string |
Required.
If html is set, this is not required. Text to use within each checkbox item label. If html is provided, the text argument will be ignored.
|
html | string |
Required.
If text is set, this is not required. HTML to use within each checkbox item label. If html is provided, the text argument will be ignored.
|
id | string |
Specific id attribute for the checkbox item. If omitted, then component global idPrefix option will be applied.
|
name | string |
Specific name for the checkbox item. If omitted, then component global name string will be applied.
|
value | string | Required. Value for the checkbox input. |
label | object | Provide attributes and classes to each checkbox item label. See label. |
hint | object | Provide hint to each checkbox item. See hint. |
checked | boolean | If true, checkbox will be checked. |
conditional | boolean | If true, content provided will be revealed when the item is checked. |
conditional.html | string | Provide content for the conditional reveal. |
disabled | boolean | If true, checkbox will be disabled. |
attributes | object | HTML attributes (for example data attributes) to add to the checkbox input tag. |
Name | Type | Description |
---|---|---|
text | string | Required. If `html` is set, this is not required. Text to use within the hint. If `html` is provided, the `text` argument will be ignored. |
html | string | Required. If `text` is set, this is not required. HTML to use within the hint. If `html` is provided, the `text` argument will be ignored. |
id | string | Optional id attribute to add to the hint span tag. |
classes | string | Classes to add to the hint span tag. |
attributes | object | HTML attributes (for example data attributes) to add to the hint span tag. |
Name | Type | Description |
---|---|---|
text | string | Required. If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` argument will be ignored. |
html | string | Required. If `text` is set, this is not required. HTML to use within the label. If `html` is provided, the `text` argument will be ignored. |
for | string | The value of the for attribute, the id of the input the label is associated with. |
isPageHeading | boolean | Whether the label also acts as the heading for the page. |
classes | string | Classes to add to the label tag. |
attributes | object | HTML attributes (for example data attributes) to add to the label tag. |
{% from "govuk/components/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--l"
}
},
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
Group checkboxes 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’.
Do not pre-select checkbox options as this makes it more likely that users will:
- not realise they’ve missed a question
- submit the wrong answer
Order checkbox options alphabetically by default.
In some cases, it can be helpful to order them from most-to-least common options. For example, you could order options for ‘What is your nationality?’ based on population size.
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--l">
<h1 class="govuk-fieldset__heading">
Which types of waste do you transport?
</h1>
</legend>
<div id="waste-hint" class="govuk-hint">
Select all that apply.
</div>
<div class="govuk-checkboxes">
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="waste" name="waste" type="checkbox" value="carcasses">
<label class="govuk-label govuk-checkboxes__label" for="waste">
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>
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work; these are marked as "Required" in the option description.
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.
Name | Type | Description |
---|---|---|
describedBy | string |
One or more element IDs to add to the input aria-describedby attribute without a fieldset, used to provide additional descriptive information for screenreader users.
|
fieldset | object | Options for the fieldset component (e.g. legend). See fieldset. |
hint | object | Options for the hint component (e.g. text). See hint. |
errorMessage | object |
Options for the error message component. The error message component will not display if you use a falsy value for errorMessage , for example false or null .
See errorMessage.
|
formGroup | object | Options for the form-group wrapper See formGroup. |
idPrefix | string | String to prefix id for each checkbox item if no id is specified on each item. If not passed, fall back to using the name option instead. |
name | string | Required. Name attribute for all checkbox items. |
items | array | Required. Array of checkbox items objects. See items. |
classes | string | Classes to add to the checkboxes container. |
attributes | object | HTML attributes (for example data attributes) to add to the anchor tag. |
Name | Type | Description |
---|---|---|
classes | string | Classes to add to the form group (e.g. to show error state for the whole group) |
Name | Type | Description |
---|---|---|
text | string |
Required.
If html is set, this is not required. Text to use within each checkbox item label. If html is provided, the text argument will be ignored.
|
html | string |
Required.
If text is set, this is not required. HTML to use within each checkbox item label. If html is provided, the text argument will be ignored.
|
id | string |
Specific id attribute for the checkbox item. If omitted, then component global idPrefix option will be applied.
|
name | string |
Specific name for the checkbox item. If omitted, then component global name string will be applied.
|
value | string | Required. Value for the checkbox input. |
label | object | Provide attributes and classes to each checkbox item label. See label. |
hint | object | Provide hint to each checkbox item. See hint. |
checked | boolean | If true, checkbox will be checked. |
conditional | boolean | If true, content provided will be revealed when the item is checked. |
conditional.html | string | Provide content for the conditional reveal. |
disabled | boolean | If true, checkbox will be disabled. |
attributes | object | HTML attributes (for example data attributes) to add to the checkbox input tag. |
Name | Type | Description |
---|---|---|
text | string | Required. If `html` is set, this is not required. Text to use within the hint. If `html` is provided, the `text` argument will be ignored. |
html | string | Required. If `text` is set, this is not required. HTML to use within the hint. If `html` is provided, the `text` argument will be ignored. |
id | string | Optional id attribute to add to the hint span tag. |
classes | string | Classes to add to the hint span tag. |
attributes | object | HTML attributes (for example data attributes) to add to the hint span tag. |
Name | Type | Description |
---|---|---|
text | string | Required. If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` argument will be ignored. |
html | string | Required. If `text` is set, this is not required. HTML to use within the label. If `html` is provided, the `text` argument will be ignored. |
for | string | The value of the for attribute, the id of the input the label is associated with. |
isPageHeading | boolean | Whether the label also acts as the heading for the page. |
classes | string | Classes to add to the label tag. |
attributes | object | HTML attributes (for example data attributes) to add to the label tag. |
{% from "govuk/components/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--l"
}
},
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--l">
<h1 class="govuk-fieldset__heading">
What is your nationality?
</h1>
</legend>
<div id="nationality-hint" class="govuk-hint">
If you have dual nationality, select all options that are relevant to you.
</div>
<div class="govuk-checkboxes">
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="nationality" name="nationality" type="checkbox" value="british" aria-describedby="nationality-item-hint">
<label class="govuk-label govuk-checkboxes__label" for="nationality">
British
</label>
<div id="nationality-item-hint" class="govuk-hint govuk-checkboxes__hint">
including English, Scottish, Welsh and Northern Irish
</div>
</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>
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work; these are marked as "Required" in the option description.
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.
Name | Type | Description |
---|---|---|
describedBy | string |
One or more element IDs to add to the input aria-describedby attribute without a fieldset, used to provide additional descriptive information for screenreader users.
|
fieldset | object | Options for the fieldset component (e.g. legend). See fieldset. |
hint | object | Options for the hint component (e.g. text). See hint. |
errorMessage | object |
Options for the error message component. The error message component will not display if you use a falsy value for errorMessage , for example false or null .
See errorMessage.
|
formGroup | object | Options for the form-group wrapper See formGroup. |
idPrefix | string | String to prefix id for each checkbox item if no id is specified on each item. If not passed, fall back to using the name option instead. |
name | string | Required. Name attribute for all checkbox items. |
items | array | Required. Array of checkbox items objects. See items. |
classes | string | Classes to add to the checkboxes container. |
attributes | object | HTML attributes (for example data attributes) to add to the anchor tag. |
Name | Type | Description |
---|---|---|
classes | string | Classes to add to the form group (e.g. to show error state for the whole group) |
Name | Type | Description |
---|---|---|
text | string |
Required.
If html is set, this is not required. Text to use within each checkbox item label. If html is provided, the text argument will be ignored.
|
html | string |
Required.
If text is set, this is not required. HTML to use within each checkbox item label. If html is provided, the text argument will be ignored.
|
id | string |
Specific id attribute for the checkbox item. If omitted, then component global idPrefix option will be applied.
|
name | string |
Specific name for the checkbox item. If omitted, then component global name string will be applied.
|
value | string | Required. Value for the checkbox input. |
label | object | Provide attributes and classes to each checkbox item label. See label. |
hint | object | Provide hint to each checkbox item. See hint. |
checked | boolean | If true, checkbox will be checked. |
conditional | boolean | If true, content provided will be revealed when the item is checked. |
conditional.html | string | Provide content for the conditional reveal. |
disabled | boolean | If true, checkbox will be disabled. |
attributes | object | HTML attributes (for example data attributes) to add to the checkbox input tag. |
Name | Type | Description |
---|---|---|
text | string | Required. If `html` is set, this is not required. Text to use within the hint. If `html` is provided, the `text` argument will be ignored. |
html | string | Required. If `text` is set, this is not required. HTML to use within the hint. If `html` is provided, the `text` argument will be ignored. |
id | string | Optional id attribute to add to the hint span tag. |
classes | string | Classes to add to the hint span tag. |
attributes | object | HTML attributes (for example data attributes) to add to the hint span tag. |
Name | Type | Description |
---|---|---|
text | string | Required. If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` argument will be ignored. |
html | string | Required. If `text` is set, this is not required. HTML to use within the label. If `html` is provided, the `text` argument will be ignored. |
for | string | The value of the for attribute, the id of the input the label is associated with. |
isPageHeading | boolean | Whether the label also acts as the heading for the page. |
classes | string | Classes to add to the label tag. |
attributes | object | HTML attributes (for example data attributes) to add to the label tag. |
{% from "govuk/components/checkboxes/macro.njk" import govukCheckboxes %}
{{ govukCheckboxes({
idPrefix: "nationality",
name: "nationality",
fieldset: {
legend: {
text: "What is your nationality?",
isPageHeading: true,
classes: "govuk-fieldset__legend--l"
}
},
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="contact-hint">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--l">
<h1 class="govuk-fieldset__heading">
How would you like to be contacted?
</h1>
</legend>
<div id="contact-hint" class="govuk-hint">
Select all options that are relevant to you.
</div>
<div class="govuk-checkboxes" data-module="govuk-checkboxes">
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="contact" name="contact" type="checkbox" value="email" data-aria-controls="conditional-contact">
<label class="govuk-label govuk-checkboxes__label" for="contact">
Email
</label>
</div>
<div class="govuk-checkboxes__conditional govuk-checkboxes__conditional--hidden" id="conditional-contact">
<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" spellcheck="false"></div>
</div>
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="contact-2" name="contact" type="checkbox" value="phone" data-aria-controls="conditional-contact-2">
<label class="govuk-label govuk-checkboxes__label" for="contact-2">
Phone
</label>
</div>
<div class="govuk-checkboxes__conditional govuk-checkboxes__conditional--hidden" id="conditional-contact-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="contact-3" name="contact" type="checkbox" value="text message" data-aria-controls="conditional-contact-3">
<label class="govuk-label govuk-checkboxes__label" for="contact-3">
Text message
</label>
</div>
<div class="govuk-checkboxes__conditional govuk-checkboxes__conditional--hidden" id="conditional-contact-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>
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work; these are marked as "Required" in the option description.
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.
Name | Type | Description |
---|---|---|
describedBy | string |
One or more element IDs to add to the input aria-describedby attribute without a fieldset, used to provide additional descriptive information for screenreader users.
|
fieldset | object | Options for the fieldset component (e.g. legend). See fieldset. |
hint | object | Options for the hint component (e.g. text). See hint. |
errorMessage | object |
Options for the error message component. The error message component will not display if you use a falsy value for errorMessage , for example false or null .
See errorMessage.
|
formGroup | object | Options for the form-group wrapper See formGroup. |
idPrefix | string | String to prefix id for each checkbox item if no id is specified on each item. If not passed, fall back to using the name option instead. |
name | string | Required. Name attribute for all checkbox items. |
items | array | Required. Array of checkbox items objects. See items. |
classes | string | Classes to add to the checkboxes container. |
attributes | object | HTML attributes (for example data attributes) to add to the anchor tag. |
Name | Type | Description |
---|---|---|
classes | string | Classes to add to the form group (e.g. to show error state for the whole group) |
Name | Type | Description |
---|---|---|
text | string |
Required.
If html is set, this is not required. Text to use within each checkbox item label. If html is provided, the text argument will be ignored.
|
html | string |
Required.
If text is set, this is not required. HTML to use within each checkbox item label. If html is provided, the text argument will be ignored.
|
id | string |
Specific id attribute for the checkbox item. If omitted, then component global idPrefix option will be applied.
|
name | string |
Specific name for the checkbox item. If omitted, then component global name string will be applied.
|
value | string | Required. Value for the checkbox input. |
label | object | Provide attributes and classes to each checkbox item label. See label. |
hint | object | Provide hint to each checkbox item. See hint. |
checked | boolean | If true, checkbox will be checked. |
conditional | boolean | If true, content provided will be revealed when the item is checked. |
conditional.html | string | Provide content for the conditional reveal. |
disabled | boolean | If true, checkbox will be disabled. |
attributes | object | HTML attributes (for example data attributes) to add to the checkbox input tag. |
Name | Type | Description |
---|---|---|
text | string | Required. If `html` is set, this is not required. Text to use within the hint. If `html` is provided, the `text` argument will be ignored. |
html | string | Required. If `text` is set, this is not required. HTML to use within the hint. If `html` is provided, the `text` argument will be ignored. |
id | string | Optional id attribute to add to the hint span tag. |
classes | string | Classes to add to the hint span tag. |
attributes | object | HTML attributes (for example data attributes) to add to the hint span tag. |
Name | Type | Description |
---|---|---|
text | string | Required. If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` argument will be ignored. |
html | string | Required. If `text` is set, this is not required. HTML to use within the label. If `html` is provided, the `text` argument will be ignored. |
for | string | The value of the for attribute, the id of the input the label is associated with. |
isPageHeading | boolean | Whether the label also acts as the heading for the page. |
classes | string | Classes to add to the label tag. |
attributes | object | HTML attributes (for example data attributes) to add to the label tag. |
{% from "govuk/components/checkboxes/macro.njk" import govukCheckboxes %}
{% from "govuk/components/input/macro.njk" import govukInput %}
{% set emailHtml %}
{{ govukInput({
id: "contact-by-email",
name: "contact-by-email",
type: "email",
spellcheck: false,
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: "contact",
name: "contact",
fieldset: {
legend: {
text: "How would you like to be contacted?",
isPageHeading: true,
classes: "govuk-fieldset__legend--l"
}
},
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.
Known issues
Users are not always notified when conditionally revealed content is expanded or collapsed. This fails WCAG 2.1 success criterion 4.1.2 Name, Role, Value. We plan to fix this issue by the end of March 2021.
Smaller checkboxes
Use standard-sized checkboxes in nearly all cases. However, smaller versions work well on pages where it’s helpful to make them less visually prominent.
For example, on a page of search results, the primary user need is to see the results. Using smaller checkboxes lets users see and change search filters without distracting them from the main content.
<div class="govuk-form-group">
<fieldset class="govuk-fieldset">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--m">
<h1 class="govuk-fieldset__heading">
Organisation
</h1>
</legend>
<div class="govuk-checkboxes govuk-checkboxes--small">
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="organisation" name="organisation" type="checkbox" value="hmrc">
<label class="govuk-label govuk-checkboxes__label" for="organisation">
HM Revenue and Customs (HMRC)
</label>
</div>
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="organisation-2" name="organisation" type="checkbox" value="employment-tribunal">
<label class="govuk-label govuk-checkboxes__label" for="organisation-2">
Employment Tribunal
</label>
</div>
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="organisation-3" name="organisation" type="checkbox" value="MOD">
<label class="govuk-label govuk-checkboxes__label" for="organisation-3">
Ministry of Defence
</label>
</div>
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="organisation-4" name="organisation" type="checkbox" value="DfT">
<label class="govuk-label govuk-checkboxes__label" for="organisation-4">
Department for Transport
</label>
</div>
</div>
</fieldset>
</div>
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work; these are marked as "Required" in the option description.
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.
Name | Type | Description |
---|---|---|
describedBy | string |
One or more element IDs to add to the input aria-describedby attribute without a fieldset, used to provide additional descriptive information for screenreader users.
|
fieldset | object | Options for the fieldset component (e.g. legend). See fieldset. |
hint | object | Options for the hint component (e.g. text). See hint. |
errorMessage | object |
Options for the error message component. The error message component will not display if you use a falsy value for errorMessage , for example false or null .
See errorMessage.
|
formGroup | object | Options for the form-group wrapper See formGroup. |
idPrefix | string | String to prefix id for each checkbox item if no id is specified on each item. If not passed, fall back to using the name option instead. |
name | string | Required. Name attribute for all checkbox items. |
items | array | Required. Array of checkbox items objects. See items. |
classes | string | Classes to add to the checkboxes container. |
attributes | object | HTML attributes (for example data attributes) to add to the anchor tag. |
Name | Type | Description |
---|---|---|
classes | string | Classes to add to the form group (e.g. to show error state for the whole group) |
Name | Type | Description |
---|---|---|
text | string |
Required.
If html is set, this is not required. Text to use within each checkbox item label. If html is provided, the text argument will be ignored.
|
html | string |
Required.
If text is set, this is not required. HTML to use within each checkbox item label. If html is provided, the text argument will be ignored.
|
id | string |
Specific id attribute for the checkbox item. If omitted, then component global idPrefix option will be applied.
|
name | string |
Specific name for the checkbox item. If omitted, then component global name string will be applied.
|
value | string | Required. Value for the checkbox input. |
label | object | Provide attributes and classes to each checkbox item label. See label. |
hint | object | Provide hint to each checkbox item. See hint. |
checked | boolean | If true, checkbox will be checked. |
conditional | boolean | If true, content provided will be revealed when the item is checked. |
conditional.html | string | Provide content for the conditional reveal. |
disabled | boolean | If true, checkbox will be disabled. |
attributes | object | HTML attributes (for example data attributes) to add to the checkbox input tag. |
Name | Type | Description |
---|---|---|
text | string | Required. If `html` is set, this is not required. Text to use within the hint. If `html` is provided, the `text` argument will be ignored. |
html | string | Required. If `text` is set, this is not required. HTML to use within the hint. If `html` is provided, the `text` argument will be ignored. |
id | string | Optional id attribute to add to the hint span tag. |
classes | string | Classes to add to the hint span tag. |
attributes | object | HTML attributes (for example data attributes) to add to the hint span tag. |
Name | Type | Description |
---|---|---|
text | string | Required. If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` argument will be ignored. |
html | string | Required. If `text` is set, this is not required. HTML to use within the label. If `html` is provided, the `text` argument will be ignored. |
for | string | The value of the for attribute, the id of the input the label is associated with. |
isPageHeading | boolean | Whether the label also acts as the heading for the page. |
classes | string | Classes to add to the label tag. |
attributes | object | HTML attributes (for example data attributes) to add to the label tag. |
{% from "govuk/components/checkboxes/macro.njk" import govukCheckboxes %}
{{ govukCheckboxes({
idPrefix: "organisation",
name: "organisation",
classes: "govuk-checkboxes--small",
fieldset: {
legend: {
text: "Organisation",
isPageHeading: true,
classes: "govuk-fieldset__legend--m"
}
},
items: [
{
value: "hmrc",
text: "HM Revenue and Customs (HMRC)"
},
{
value: "employment-tribunal",
text: "Employment Tribunal"
},
{
value: "MOD",
text: "Ministry of Defence"
},
{
value: "DfT",
text: "Department for Transport"
}
]
}) }}
Small checkboxes can work well on information dense screens in services designed for repeat use, like caseworking systems.
In services like these, the risk that they will not be noticed is lower because users return to the screen multiple times.
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--l">
<h1 class="govuk-fieldset__heading">
What is your nationality?
</h1>
</legend>
<div id="nationality-hint" class="govuk-hint">
If you have dual nationality, select all options that are relevant to you.
</div>
<span id="nationality-error" class="govuk-error-message">
<span class="govuk-visually-hidden">Error:</span> 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" name="nationality" type="checkbox" value="british" aria-describedby="nationality-item-hint">
<label class="govuk-label govuk-checkboxes__label" for="nationality">
British
</label>
<div id="nationality-item-hint" class="govuk-hint govuk-checkboxes__hint">
including English, Scottish, Welsh and Northern Irish
</div>
</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>
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work; these are marked as "Required" in the option description.
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.
Name | Type | Description |
---|---|---|
describedBy | string |
One or more element IDs to add to the input aria-describedby attribute without a fieldset, used to provide additional descriptive information for screenreader users.
|
fieldset | object | Options for the fieldset component (e.g. legend). See fieldset. |
hint | object | Options for the hint component (e.g. text). See hint. |
errorMessage | object |
Options for the error message component. The error message component will not display if you use a falsy value for errorMessage , for example false or null .
See errorMessage.
|
formGroup | object | Options for the form-group wrapper See formGroup. |
idPrefix | string | String to prefix id for each checkbox item if no id is specified on each item. If not passed, fall back to using the name option instead. |
name | string | Required. Name attribute for all checkbox items. |
items | array | Required. Array of checkbox items objects. See items. |
classes | string | Classes to add to the checkboxes container. |
attributes | object | HTML attributes (for example data attributes) to add to the anchor tag. |
Name | Type | Description |
---|---|---|
classes | string | Classes to add to the form group (e.g. to show error state for the whole group) |
Name | Type | Description |
---|---|---|
text | string |
Required.
If html is set, this is not required. Text to use within each checkbox item label. If html is provided, the text argument will be ignored.
|
html | string |
Required.
If text is set, this is not required. HTML to use within each checkbox item label. If html is provided, the text argument will be ignored.
|
id | string |
Specific id attribute for the checkbox item. If omitted, then component global idPrefix option will be applied.
|
name | string |
Specific name for the checkbox item. If omitted, then component global name string will be applied.
|
value | string | Required. Value for the checkbox input. |
label | object | Provide attributes and classes to each checkbox item label. See label. |
hint | object | Provide hint to each checkbox item. See hint. |
checked | boolean | If true, checkbox will be checked. |
conditional | boolean | If true, content provided will be revealed when the item is checked. |
conditional.html | string | Provide content for the conditional reveal. |
disabled | boolean | If true, checkbox will be disabled. |
attributes | object | HTML attributes (for example data attributes) to add to the checkbox input tag. |
Name | Type | Description |
---|---|---|
text | string | Required. If `html` is set, this is not required. Text to use within the hint. If `html` is provided, the `text` argument will be ignored. |
html | string | Required. If `text` is set, this is not required. HTML to use within the hint. If `html` is provided, the `text` argument will be ignored. |
id | string | Optional id attribute to add to the hint span tag. |
classes | string | Classes to add to the hint span tag. |
attributes | object | HTML attributes (for example data attributes) to add to the hint span tag. |
Name | Type | Description |
---|---|---|
text | string | Required. If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` argument will be ignored. |
html | string | Required. If `text` is set, this is not required. HTML to use within the label. If `html` is provided, the `text` argument will be ignored. |
for | string | The value of the for attribute, the id of the input the label is associated with. |
isPageHeading | boolean | Whether the label also acts as the heading for the page. |
classes | string | Classes to add to the label tag. |
attributes | object | HTML attributes (for example data attributes) to add to the label tag. |
{% from "govuk/components/checkboxes/macro.njk" import govukCheckboxes %}
{{ govukCheckboxes({
idPrefix: "nationality",
name: "nationality",
fieldset: {
legend: {
text: "What is your nationality?",
isPageHeading: true,
classes: "govuk-fieldset__legend--l"
}
},
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.
Help improve this page
To help make sure that this page is useful, relevant and up to date, you can:
- share your research or feedback on GitHub
- propose a change – read more about how to propose changes in GitHub
Need help?
If you’ve got a question about the GOV.UK Design System, contact the team.