Form elements - Select

Use select to let users choose an option from a long list but only use it as a last resort.

WCAG 2.2

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.

Open this default select example in new window
Copy default select code
<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>
Close default select code
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.

Nunjucks arguments for default select
Name Type Required Description
Name id Type string Required true Description Id for each select box.
Name name Type string Required true Description Name property for the select.
Name items Type array Required true Description Array of option items for the select.
Name items[].value Type string Required false Description Value for the option item. Defaults to an empty string.
Name items[].text Type string Required true Description Text for the option item.
Name items[].selected Type boolean Required false Description Sets the option as the selected.
Name items[].disabled Type boolean Required false Description Sets the option item as disabled.
Name items[].attributes Type object Required false Description HTML attributes (for example data attributes) to add to the option.
Name label Type object Required false Description Label text or HTML by specifying value for either text or html keys.
Name hint Type object Required false Description Options for the hint component.
Name errorMessage Type object Required false Description 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`.
Name classes Type string Required false Description Classes to add to the select.
Name attributes Type object Required false Description HTML attributes (for example data attributes) to add to the select.
Copy default select code
{% 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
    }
  ]
}) }}
Close default select code

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.

Information: WCAG 2.2

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