Use select to let users choose an option from a long list but only use it as a last resort.
WCAG 2.2 affects this component
To meet new success criteria introduced in the Web Content Accessibility Guidelines (WCAG) 2.2, make sure that users can successfully:
See the full list of design system changes to meet WCAG 2.2.
<div class="nhsuk-form-group">
<label class="nhsuk-label" for="select-1">
Label text goes here
</label>
<select class="nhsuk-select" id="select-1" name="select-1">
<option value="1">NHS.UK frontend option 1</option>
<option value="2" selected>NHS.UK frontend option 2</option>
<option value="3" disabled>NHS.UK frontend option 3</option>
</select>
</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 | Required | Description |
---|---|---|---|
id | string | true | Id for each select box. |
name | string | true | Name property for the select. |
items | array | true | Array of option items for the select. |
items[].value | string | false | Value for the option item. Defaults to an empty string. |
items[].text | string | true | Text for the option item. |
items[].selected | boolean | false | Sets the option as the selected. |
items[].disabled | boolean | false | Sets the option item as disabled. |
items[].attributes | object | false | HTML attributes (for example data attributes) to add to the option. |
label | object | false | Label text or HTML by specifying value for either text or html keys. |
hint | object | false | Options for the hint component. |
errorMessage | object | false | 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`. |
classes | string | false | Classes to add to the select. |
attributes | object | false | HTML attributes (for example data attributes) to add to the select. |
{% from 'select/macro.njk' import select %}
{{ select({
id: "select-1",
name: "select-1",
label: {
text: "Label text goes here"
},
items: [
{
value: 1,
text: "NHS.UK frontend option 1"
},
{
value: 2,
text: "NHS.UK frontend option 2",
selected: true
},
{
value: 3,
text: "NHS.UK frontend option 3",
disabled: true
}
]
}) }}
How to use select
The select component allows users to choose an option from a long list. Before using it, try other questions which will allow you to present users with fewer options. Consider using a different solution, such as radios.
Any input that's designed to let a user select multiple options must offer a way to do so without relying on click and drag movements or keyboard and mouse combination actions. This is to comply with WCAG 2.2 success criterion 2.5.7 Dragging Movements (W3C).
Research
Watch a video about how some users struggle with selects: Alice Bartlett: Burn your select tags.
Help us improve this guidance
Share insights or feedback and take part in the discussion. We use GitHub as a collaboration space. All the information on it is open to the public.
Read more about how to feedback or share insights.
If you have any questions, get in touch with the service manual team.
Updated: April 2024