Form elements - Dropdown select

Use dropdown select to let users choose from a long list. Only use it as a last resort.

Open this default dropdown select example in new window
Copy default dropdown select code
<div class="hse-form-group">
  <label class="hse-label" for="select-1">
    Label text goes here
  </label>
  <select class="hse-select" id="select-1" name="select-1">
    <option value="1">HSE.IE frontend option 1</option>
    <option value="2" selected>HSE.IE frontend option 2</option>
    <option value="3" disabled>HSE.IE frontend option 3</option>
  </select>
</div>
Close default dropdown 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 dropdown 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 dropdown 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": "HSE.IE frontend option 1"
    },
    {
      "value": 2,
      "text": "HSE.IE frontend option 2",
      "selected": true
    },
    {
      "value": 3,
      "text": "HSE.IE frontend option 3",
      "disabled": true
    }
  ]
}) }}
Close default dropdown select code

When to use a dropdown select

Dropdown select allows users choose from a long list. But only use it as a last resort.

NHS research suggests that some users find dropdown select very difficult to use. Try a different solution, such as radios.

How to use a dropdown select

Before using dropdown select, try asking users questions which will allow you to present them with fewer options. Asking questions means you’re less likely to need to use dropdown select, and can consider using a different solution.

If you use a dropdown select for settings, you can make an option pre-selected by default when users first see it.

If you use a dropdown select for questions, do not pre-select any of the options in case it influences users’ answers.

Updated: August 2023