--- url: "https://design-system.service.gov.uk/components/select/" titulek: "Select – GOV.UK Design System" h1: "Select" popis: "Help users select an item from a list" jazyk: "en" kanonicka: "https://design-system.service.gov.uk/components/select/" drobecky: ["Home", "Components"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 01:21:57" znaku: 25721 slov: 3941 kodovani: "utf-8" sha256: "63c3ead411e15c795ab1e60df4bf37903db08ce2bc7fed55a3b86f7af4d53ab1" --- # Select - HTML - Nunjucks HTML ```
``` Nunjucks 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. Deprecated options are marked as “Deprecated”. 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](https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting). Primary options string ID for the select box. Defaults to the value of `name`. string **Required.** Name property for the select. array **Required.** The items within the select component. See macro options for items. string Value for the option which should be selected. Use this as an alternative to setting the `selected` option on each individual item. boolean If `true`, select box will be disabled. Use the `disabled` option on each individual item to only disable certain options. string One or more element IDs to add to the `aria-describedby` attribute, used to provide additional descriptive information for screenreader users. object **Required.** The label used by the select component. See macro options for label. object Can be used to add a hint to the select component. See macro options for hint. object Can be used to add an error message to the select component. The error message component will not display if you use a falsy value for `errorMessage`, for example `false` or `null`. [See macro options for errorMessage](/components/error-message/#options-error-message-example). object Additional options for the form group containing the select component. See macro options for formGroup. string Classes to add to the select. object HTML attributes (for example data attributes) to add to the select. Options for `items` array objects string Value for the option. If this is omitted, the value is taken from the text content of the option element. string **Required.** Text for the option item. boolean Whether the option should be selected when the page loads. Takes precedence over the top-level `value` option. boolean Sets the option item as disabled. object HTML attributes (for example data attributes) to add to the option. Options for `formGroup` object string Classes to add to the form group (for example to show error state for the whole group). object HTML attributes (for example data attributes) to add to the form group. object Content to add before the select used by the select component. See macro options for formGroup beforeInput. object Content to add after the select used by the select component. See macro options for formGroup afterInput. Options for formGroup `beforeInput` object string **Required.** Text to add before the select. If `html` is provided, the `text` option will be ignored. string **Required.** HTML to add before the select. If `html` is provided, the `text` option will be ignored. Options for formGroup `afterInput` object string **Required.** Text to add after the select. If `html` is provided, the `text` option will be ignored. string **Required.** HTML to add after the select. If `html` is provided, the `text` option will be ignored. Options for `label` component string **Required.** If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` option will be ignored. string **Required.** If `text` is set, this is not required. HTML to use within the label. If `html` is provided, the `text` option will be ignored. string The value of the `for` attribute, the ID of the input the label is associated with. boolean Whether the label also acts as the heading for the page. string Classes to add to the label tag. object HTML attributes (for example data attributes) to add to the label tag. Options for `hint` component string **Required.** If `html` is set, this is not required. Text to use within the hint. If `html` is provided, the `text` option will be ignored. string **Required.** If `text` is set, this is not required. HTML to use within the hint. If `html` is provided, the `text` option will be ignored. string Optional ID attribute to add to the hint span tag. string Classes to add to the hint span tag. object HTML attributes (for example data attributes) to add to the hint span tag. ``` {% from "govuk/components/select/macro.njk" import govukSelect %} {{ govukSelect({ id: "sort", name: "sort", label: { text: "Sort by" }, items: [ { value: "published", text: "Recently published" }, { value: "updated", text: "Recently updated", selected: true }, { value: "views", text: "Most views" }, { value: "comments", text: "Most comments" } ] }) }} ``` ## When to use this component The select component should only be used as a last resort in public-facing services because research shows that some users find selects very difficult to use. ## When not to use this component The select component allows users to choose an option from a long list. Before using the select component, 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 the select component, and can consider using a different solution, such as a [Radios component](/components/radios/). ## How it works If you use the component for settings, you can make an option pre-selected by default when users first see it. If you use the component for questions, you should not pre-select any of the options in case it influences users’ answers. There are 2 ways to use the select component. You can use HTML or, if you’re using [Nunjucks](https://mozilla.github.io/nunjucks/) or the [GOV.UK Prototype Kit](https://prototype-kit.service.gov.uk), you can use the Nunjucks macro. - HTML - Nunjucks HTML ```
``` Nunjucks 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. Deprecated options are marked as “Deprecated”. 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](https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting). Primary options string ID for the select box. Defaults to the value of `name`. string **Required.** Name property for the select. array **Required.** The items within the select component. See macro options for items. string Value for the option which should be selected. Use this as an alternative to setting the `selected` option on each individual item. boolean If `true`, select box will be disabled. Use the `disabled` option on each individual item to only disable certain options. string One or more element IDs to add to the `aria-describedby` attribute, used to provide additional descriptive information for screenreader users. object **Required.** The label used by the select component. See macro options for label. object Can be used to add a hint to the select component. See macro options for hint. object Can be used to add an error message to the select component. The error message component will not display if you use a falsy value for `errorMessage`, for example `false` or `null`. [See macro options for errorMessage](/components/error-message/#options-error-message-example). object Additional options for the form group containing the select component. See macro options for formGroup. string Classes to add to the select. object HTML attributes (for example data attributes) to add to the select. Options for `items` array objects string Value for the option. If this is omitted, the value is taken from the text content of the option element. string **Required.** Text for the option item. boolean Whether the option should be selected when the page loads. Takes precedence over the top-level `value` option. boolean Sets the option item as disabled. object HTML attributes (for example data attributes) to add to the option. Options for `formGroup` object string Classes to add to the form group (for example to show error state for the whole group). object HTML attributes (for example data attributes) to add to the form group. object Content to add before the select used by the select component. See macro options for formGroup beforeInput. object Content to add after the select used by the select component. See macro options for formGroup afterInput. Options for formGroup `beforeInput` object string **Required.** Text to add before the select. If `html` is provided, the `text` option will be ignored. string **Required.** HTML to add before the select. If `html` is provided, the `text` option will be ignored. Options for formGroup `afterInput` object string **Required.** Text to add after the select. If `html` is provided, the `text` option will be ignored. string **Required.** HTML to add after the select. If `html` is provided, the `text` option will be ignored. Options for `label` component string **Required.** If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` option will be ignored. string **Required.** If `text` is set, this is not required. HTML to use within the label. If `html` is provided, the `text` option will be ignored. string The value of the `for` attribute, the ID of the input the label is associated with. boolean Whether the label also acts as the heading for the page. string Classes to add to the label tag. object HTML attributes (for example data attributes) to add to the label tag. Options for `hint` component string **Required.** If `html` is set, this is not required. Text to use within the hint. If `html` is provided, the `text` option will be ignored. string **Required.** If `text` is set, this is not required. HTML to use within the hint. If `html` is provided, the `text` option will be ignored. string Optional ID attribute to add to the hint span tag. string Classes to add to the hint span tag. object HTML attributes (for example data attributes) to add to the hint span tag. ``` {% from "govuk/components/select/macro.njk" import govukSelect %} {{ govukSelect({ id: "sort", name: "sort", label: { text: "Sort by" }, items: [ { value: "published", text: "Recently published" }, { value: "updated", text: "Recently updated", selected: true }, { value: "views", text: "Most views" }, { value: "comments", text: "Most comments" } ] }) }} ``` ### Select with hint You can add hint text to help the user understand the options and choose one of them. Keep hint text to a single short sentence, without any full stops. Do not use links in hint text. While screen readers will read out the link text, they usually do not tell users the text is a link. - HTML - Nunjucks HTML ```
This can be different to where you went before
``` Nunjucks 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. Deprecated options are marked as “Deprecated”. 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](https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting). Primary options string ID for the select box. Defaults to the value of `name`. string **Required.** Name property for the select. array **Required.** The items within the select component. See macro options for items. string Value for the option which should be selected. Use this as an alternative to setting the `selected` option on each individual item. boolean If `true`, select box will be disabled. Use the `disabled` option on each individual item to only disable certain options. string One or more element IDs to add to the `aria-describedby` attribute, used to provide additional descriptive information for screenreader users. object **Required.** The label used by the select component. See macro options for label. object Can be used to add a hint to the select component. See macro options for hint. object Can be used to add an error message to the select component. The error message component will not display if you use a falsy value for `errorMessage`, for example `false` or `null`. [See macro options for errorMessage](/components/error-message/#options-error-message-example). object Additional options for the form group containing the select component. See macro options for formGroup. string Classes to add to the select. object HTML attributes (for example data attributes) to add to the select. Options for `items` array objects string Value for the option. If this is omitted, the value is taken from the text content of the option element. string **Required.** Text for the option item. boolean Whether the option should be selected when the page loads. Takes precedence over the top-level `value` option. boolean Sets the option item as disabled. object HTML attributes (for example data attributes) to add to the option. Options for `formGroup` object string Classes to add to the form group (for example to show error state for the whole group). object HTML attributes (for example data attributes) to add to the form group. object Content to add before the select used by the select component. See macro options for formGroup beforeInput. object Content to add after the select used by the select component. See macro options for formGroup afterInput. Options for formGroup `beforeInput` object string **Required.** Text to add before the select. If `html` is provided, the `text` option will be ignored. string **Required.** HTML to add before the select. If `html` is provided, the `text` option will be ignored. Options for formGroup `afterInput` object string **Required.** Text to add after the select. If `html` is provided, the `text` option will be ignored. string **Required.** HTML to add after the select. If `html` is provided, the `text` option will be ignored. Options for `label` component string **Required.** If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` option will be ignored. string **Required.** If `text` is set, this is not required. HTML to use within the label. If `html` is provided, the `text` option will be ignored. string The value of the `for` attribute, the ID of the input the label is associated with. boolean Whether the label also acts as the heading for the page. string Classes to add to the label tag. object HTML attributes (for example data attributes) to add to the label tag. Options for `hint` component string **Required.** If `html` is set, this is not required. Text to use within the hint. If `html` is provided, the `text` option will be ignored. string **Required.** If `text` is set, this is not required. HTML to use within the hint. If `html` is provided, the `text` option will be ignored. string Optional ID attribute to add to the hint span tag. string Classes to add to the hint span tag. object HTML attributes (for example data attributes) to add to the hint span tag. ``` {% from "govuk/components/select/macro.njk" import govukSelect %} {{ govukSelect({ id: "location", name: "location", label: { text: "Choose location" }, hint: { text: "This can be different to where you went before" }, items: [ { value: "choose", text: "Choose location", selected: true }, { value: "eastmidlands", text: "East Midlands" }, { value: "eastofengland", text: "East of England" }, { value: "london", text: "London" }, { value: "northeast", text: "North East" }, { value: "northwest", text: "North West" }, { value: "southeast", text: "South East" }, { value: "southwest", text: "South West" }, { value: "westmidlands", text: "West Midlands" }, { value: "yorkshire", text: "Yorkshire and the Humber" } ] }) }} ``` ### Error messages Display an error message if the user has not selected an option. Style error messages as shown in the example: - HTML - Nunjucks HTML ```
This can be different to where you went before

Error: Select a location

``` Nunjucks 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. Deprecated options are marked as “Deprecated”. 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](https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting). Primary options string ID for the select box. Defaults to the value of `name`. string **Required.** Name property for the select. array **Required.** The items within the select component. See macro options for items. string Value for the option which should be selected. Use this as an alternative to setting the `selected` option on each individual item. boolean If `true`, select box will be disabled. Use the `disabled` option on each individual item to only disable certain options. string One or more element IDs to add to the `aria-describedby` attribute, used to provide additional descriptive information for screenreader users. object **Required.** The label used by the select component. See macro options for label. object Can be used to add a hint to the select component. See macro options for hint. object Can be used to add an error message to the select component. The error message component will not display if you use a falsy value for `errorMessage`, for example `false` or `null`. [See macro options for errorMessage](/components/error-message/#options-error-message-example). object Additional options for the form group containing the select component. See macro options for formGroup. string Classes to add to the select. object HTML attributes (for example data attributes) to add to the select. Options for `items` array objects string Value for the option. If this is omitted, the value is taken from the text content of the option element. string **Required.** Text for the option item. boolean Whether the option should be selected when the page loads. Takes precedence over the top-level `value` option. boolean Sets the option item as disabled. object HTML attributes (for example data attributes) to add to the option. Options for `formGroup` object string Classes to add to the form group (for example to show error state for the whole group). object HTML attributes (for example data attributes) to add to the form group. object Content to add before the select used by the select component. See macro options for formGroup beforeInput. object Content to add after the select used by the select component. See macro options for formGroup afterInput. Options for formGroup `beforeInput` object string **Required.** Text to add before the select. If `html` is provided, the `text` option will be ignored. string **Required.** HTML to add before the select. If `html` is provided, the `text` option will be ignored. Options for formGroup `afterInput` object string **Required.** Text to add after the select. If `html` is provided, the `text` option will be ignored. string **Required.** HTML to add after the select. If `html` is provided, the `text` option will be ignored. Options for `label` component string **Required.** If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` option will be ignored. string **Required.** If `text` is set, this is not required. HTML to use within the label. If `html` is provided, the `text` option will be ignored. string The value of the `for` attribute, the ID of the input the label is associated with. boolean Whether the label also acts as the heading for the page. string Classes to add to the label tag. object HTML attributes (for example data attributes) to add to the label tag. Options for `hint` component string **Required.** If `html` is set, this is not required. Text to use within the hint. If `html` is provided, the `text` option will be ignored. string **Required.** If `text` is set, this is not required. HTML to use within the hint. If `html` is provided, the `text` option will be ignored. string Optional ID attribute to add to the hint span tag. string Classes to add to the hint span tag. object HTML attributes (for example data attributes) to add to the hint span tag. ``` {% from "govuk/components/select/macro.njk" import govukSelect %} {{ govukSelect({ id: "location", name: "location", label: { text: "Choose location" }, hint: { text: "This can be different to where you went before" }, errorMessage: { text: "Select a location" }, items: [ { value: "choose", text: "Choose location", selected: true }, { value: "eastmidlands", text: "East Midlands" }, { value: "eastofengland", text: "East of England" }, { value: "london", text: "London" }, { value: "northeast", text: "North East" }, { value: "northwest", text: "North West" }, { value: "southeast", text: "South East" }, { value: "southwest", text: "South West" }, { value: "westmidlands", text: "West Midlands" }, { value: "yorkshire", text: "Yorkshire and the Humber" } ] }) }} ``` ### Avoid adding functionality to allow selecting multiple options The select component does not support selecting multiple options, [as there’s a history of poor usability and assistive technology support for `