Form elements
–
Search input
Use a search input to help users find something specific by entering a word, phrase or characters.
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.
| Name | Type | Description |
|---|---|---|
| id | string |
The ID of the input. Defaults to the value of name.
|
| name | string | Required. The name of the input, which is submitted with the form data. |
| value | string | Optional initial value of the input. |
| disabled | boolean |
If true, input will be disabled.
|
|
described |
string |
One or more element IDs to add to the aria-describedby attribute, used to provide additional descriptive information for screenreader users.
|
| label | object | Required. The label used by the search input component. See macro options for label. |
| hint | object | Can be used to add a hint to a search input component. See macro options for hint. |
|
error |
object |
Can be used to add an error message to the search input 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 error |
| prefix | object | Can be used to add a prefix to the search input component. See macro options for prefix. |
| suffix | object | Can be used to add a suffix to the search input component. See macro options for suffix. |
| code | boolean |
If set to true, use a monospace font for codes or sequences.
|
| width | integer |
Optional fixed width for the search input component – 2, 3, 4, 5, 10, 20 or 30.
|
| large | boolean |
If set to true, larger input size will be used.
|
|
form |
object |
Additional options for the form group containing the search input component.
See macro options for form |
| classes | string | Classes to add to the input. |
| autocomplete | string |
Attribute to meet WCAG success criterion 1.3.5: Identify input purpose, for instance "bday-day". See the Autofill section in the HTML standard for a full list of attributes that can be used. Default is "off".
|
| pattern | string | Attribute to provide a regular expression pattern, used to match allowed character combinations for the input value. |
|
input |
object |
Additional options for the wrapping element containing the search input component.
See macro options for input |
| attributes | object | HTML attributes (for example data attributes) to add to the input. |
| button | object | Optional object allowing customisation of the search button. See button macro options using button component macro. |
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
Required. If html is set, this is not required. Text to use within the prefix. If html is provided, the text option will be ignored.
|
| html | string |
Required.
Required. If text is set, this is not required. HTML to use within the prefix. If html is provided, the text option will be ignored.
|
| classes | string | Classes to add to the prefix. |
| attributes | object | HTML attributes (for example data attributes) to add to the prefix element. |
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
If html is set, this is not required. Text to use within the suffix. If html is provided, the text option will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML to use within the suffix. If html is provided, the text option will be ignored.
|
| classes | string | Classes to add to the suffix element. |
| attributes | object | HTML attributes (for example data attributes) to add to the suffix element. |
| Name | Type | Description |
|---|---|---|
| classes | string | Classes to add to the form group (for example to show error state for the whole group). |
| attributes | object | HTML attributes (for example data attributes) to add to the form group. |
|
before |
object |
Content to add before the input used by the search input component.
See macro options for form |
|
after |
object |
Content to add after the input used by the search input component.
See macro options for form |
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
Text to add before the input. If html is provided, the text option will be ignored.
|
| html | string |
Required.
HTML to add before the input. If html is provided, the text option will be ignored.
|
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
Text to add after the input. If html is provided, the text option will be ignored.
|
| html | string |
Required.
HTML to add after the input. If html is provided, the text option will be ignored.
|
| Name | Type | Description |
|---|---|---|
| classes | string | Classes to add to the wrapping element. |
| attributes | object | HTML attributes (for example data attributes) to add to the wrapping element. |
| Name | Type | Description |
|---|---|---|
| variant | string |
Optional variant of search button – "brand", "login", "reverse", "secondary", "secondary-solid" or "warning".
|
| classes | string | Classes to add to the search button. |
|
aria |
string | Button text exposed to assistive technologies, like screen readers, when only an icon is used. |
| icon | object | Can be used to add an icon to the search button. See macro options for button icon. |
| Name | Type | Description |
|---|---|---|
| name | string |
Required.
Icon name for the button – for example, "search", "arrow-right", "plus" or "minus".
|
| html | string |
Required.
HTML to use for the icon, as an alternative to the name option. If html is provided, the name option will be ignored.
|
| placement | string |
Required.
Placement of the icon within the button – "start" or "end".
|
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the label. |
| text | 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.
|
| html | 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.
|
| caller | nunjucks-block |
Not strictly a parameter but Nunjucks code convention. Using a call block enables you to call a macro with all the text inside the tag. This is helpful if you want to pass a lot of content into a macro. To use it, you will need to wrap the entire label component in a call block.
|
| for | string |
The value of the for attribute, the ID of the input the label is associated with.
|
|
is |
boolean | Whether the label also acts as the heading for the page. |
| size | string |
Size of the label – "s", "m", "l" or "xl".
|
| classes | string | Classes to add to the label tag. |
| attributes | object | HTML attributes (for example data attributes) to add to the label tag. |
When to use search input
Use the search input component to help users find a topic, person, task, place or other type of record when navigation alone is not practical.
You can enable search in the header component. Use this to provide a global search.
When not to use search input
Do not rely on search in place of a well-structured information architecture and navigation.
How to use search input
When a user types into the input, a cross icon button appears which allows users to clear the input. This is an enhancement for browsers that support it. Some browsers such as Firefox will not show it.
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.
| Name | Type | Description |
|---|---|---|
| id | string |
The ID of the input. Defaults to the value of name.
|
| name | string | Required. The name of the input, which is submitted with the form data. |
| value | string | Optional initial value of the input. |
| disabled | boolean |
If true, input will be disabled.
|
|
described |
string |
One or more element IDs to add to the aria-describedby attribute, used to provide additional descriptive information for screenreader users.
|
| label | object | Required. The label used by the search input component. See macro options for label. |
| hint | object | Can be used to add a hint to a search input component. See macro options for hint. |
|
error |
object |
Can be used to add an error message to the search input 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 error |
| prefix | object | Can be used to add a prefix to the search input component. See macro options for prefix. |
| suffix | object | Can be used to add a suffix to the search input component. See macro options for suffix. |
| code | boolean |
If set to true, use a monospace font for codes or sequences.
|
| width | integer |
Optional fixed width for the search input component – 2, 3, 4, 5, 10, 20 or 30.
|
| large | boolean |
If set to true, larger input size will be used.
|
|
form |
object |
Additional options for the form group containing the search input component.
See macro options for form |
| classes | string | Classes to add to the input. |
| autocomplete | string |
Attribute to meet WCAG success criterion 1.3.5: Identify input purpose, for instance "bday-day". See the Autofill section in the HTML standard for a full list of attributes that can be used. Default is "off".
|
| pattern | string | Attribute to provide a regular expression pattern, used to match allowed character combinations for the input value. |
|
input |
object |
Additional options for the wrapping element containing the search input component.
See macro options for input |
| attributes | object | HTML attributes (for example data attributes) to add to the input. |
| button | object | Optional object allowing customisation of the search button. See button macro options using button component macro. |
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
Required. If html is set, this is not required. Text to use within the prefix. If html is provided, the text option will be ignored.
|
| html | string |
Required.
Required. If text is set, this is not required. HTML to use within the prefix. If html is provided, the text option will be ignored.
|
| classes | string | Classes to add to the prefix. |
| attributes | object | HTML attributes (for example data attributes) to add to the prefix element. |
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
If html is set, this is not required. Text to use within the suffix. If html is provided, the text option will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML to use within the suffix. If html is provided, the text option will be ignored.
|
| classes | string | Classes to add to the suffix element. |
| attributes | object | HTML attributes (for example data attributes) to add to the suffix element. |
| Name | Type | Description |
|---|---|---|
| classes | string | Classes to add to the form group (for example to show error state for the whole group). |
| attributes | object | HTML attributes (for example data attributes) to add to the form group. |
|
before |
object |
Content to add before the input used by the search input component.
See macro options for form |
|
after |
object |
Content to add after the input used by the search input component.
See macro options for form |
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
Text to add before the input. If html is provided, the text option will be ignored.
|
| html | string |
Required.
HTML to add before the input. If html is provided, the text option will be ignored.
|
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
Text to add after the input. If html is provided, the text option will be ignored.
|
| html | string |
Required.
HTML to add after the input. If html is provided, the text option will be ignored.
|
| Name | Type | Description |
|---|---|---|
| classes | string | Classes to add to the wrapping element. |
| attributes | object | HTML attributes (for example data attributes) to add to the wrapping element. |
| Name | Type | Description |
|---|---|---|
| variant | string |
Optional variant of search button – "brand", "login", "reverse", "secondary", "secondary-solid" or "warning".
|
| classes | string | Classes to add to the search button. |
|
aria |
string | Button text exposed to assistive technologies, like screen readers, when only an icon is used. |
| icon | object | Can be used to add an icon to the search button. See macro options for button icon. |
| Name | Type | Description |
|---|---|---|
| name | string |
Required.
Icon name for the button – for example, "search", "arrow-right", "plus" or "minus".
|
| html | string |
Required.
HTML to use for the icon, as an alternative to the name option. If html is provided, the name option will be ignored.
|
| placement | string |
Required.
Placement of the icon within the button – "start" or "end".
|
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the label. |
| text | 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.
|
| html | 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.
|
| caller | nunjucks-block |
Not strictly a parameter but Nunjucks code convention. Using a call block enables you to call a macro with all the text inside the tag. This is helpful if you want to pass a lot of content into a macro. To use it, you will need to wrap the entire label component in a call block.
|
| for | string |
The value of the for attribute, the ID of the input the label is associated with.
|
|
is |
boolean | Whether the label also acts as the heading for the page. |
| size | string |
Size of the label – "s", "m", "l" or "xl".
|
| classes | string | Classes to add to the label tag. |
| attributes | object | HTML attributes (for example data attributes) to add to the label tag. |
The search button can include a text label, for example "Find".
Depending on the hierarchy of the page, the search input can use a secondary button.
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.
| Name | Type | Description |
|---|---|---|
| id | string |
The ID of the input. Defaults to the value of name.
|
| name | string | Required. The name of the input, which is submitted with the form data. |
| value | string | Optional initial value of the input. |
| disabled | boolean |
If true, input will be disabled.
|
|
described |
string |
One or more element IDs to add to the aria-describedby attribute, used to provide additional descriptive information for screenreader users.
|
| label | object | Required. The label used by the search input component. See macro options for label. |
| hint | object | Can be used to add a hint to a search input component. See macro options for hint. |
|
error |
object |
Can be used to add an error message to the search input 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 error |
| prefix | object | Can be used to add a prefix to the search input component. See macro options for prefix. |
| suffix | object | Can be used to add a suffix to the search input component. See macro options for suffix. |
| code | boolean |
If set to true, use a monospace font for codes or sequences.
|
| width | integer |
Optional fixed width for the search input component – 2, 3, 4, 5, 10, 20 or 30.
|
| large | boolean |
If set to true, larger input size will be used.
|
|
form |
object |
Additional options for the form group containing the search input component.
See macro options for form |
| classes | string | Classes to add to the input. |
| autocomplete | string |
Attribute to meet WCAG success criterion 1.3.5: Identify input purpose, for instance "bday-day". See the Autofill section in the HTML standard for a full list of attributes that can be used. Default is "off".
|
| pattern | string | Attribute to provide a regular expression pattern, used to match allowed character combinations for the input value. |
|
input |
object |
Additional options for the wrapping element containing the search input component.
See macro options for input |
| attributes | object | HTML attributes (for example data attributes) to add to the input. |
| button | object | Optional object allowing customisation of the search button. See button macro options using button component macro. |
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
Required. If html is set, this is not required. Text to use within the prefix. If html is provided, the text option will be ignored.
|
| html | string |
Required.
Required. If text is set, this is not required. HTML to use within the prefix. If html is provided, the text option will be ignored.
|
| classes | string | Classes to add to the prefix. |
| attributes | object | HTML attributes (for example data attributes) to add to the prefix element. |
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
If html is set, this is not required. Text to use within the suffix. If html is provided, the text option will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML to use within the suffix. If html is provided, the text option will be ignored.
|
| classes | string | Classes to add to the suffix element. |
| attributes | object | HTML attributes (for example data attributes) to add to the suffix element. |
| Name | Type | Description |
|---|---|---|
| classes | string | Classes to add to the form group (for example to show error state for the whole group). |
| attributes | object | HTML attributes (for example data attributes) to add to the form group. |
|
before |
object |
Content to add before the input used by the search input component.
See macro options for form |
|
after |
object |
Content to add after the input used by the search input component.
See macro options for form |
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
Text to add before the input. If html is provided, the text option will be ignored.
|
| html | string |
Required.
HTML to add before the input. If html is provided, the text option will be ignored.
|
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
Text to add after the input. If html is provided, the text option will be ignored.
|
| html | string |
Required.
HTML to add after the input. If html is provided, the text option will be ignored.
|
| Name | Type | Description |
|---|---|---|
| classes | string | Classes to add to the wrapping element. |
| attributes | object | HTML attributes (for example data attributes) to add to the wrapping element. |
| Name | Type | Description |
|---|---|---|
| variant | string |
Optional variant of search button – "brand", "login", "reverse", "secondary", "secondary-solid" or "warning".
|
| classes | string | Classes to add to the search button. |
|
aria |
string | Button text exposed to assistive technologies, like screen readers, when only an icon is used. |
| icon | object | Can be used to add an icon to the search button. See macro options for button icon. |
| Name | Type | Description |
|---|---|---|
| name | string |
Required.
Icon name for the button – for example, "search", "arrow-right", "plus" or "minus".
|
| html | string |
Required.
HTML to use for the icon, as an alternative to the name option. If html is provided, the name option will be ignored.
|
| placement | string |
Required.
Placement of the icon within the button – "start" or "end".
|
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the label. |
| text | 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.
|
| html | 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.
|
| caller | nunjucks-block |
Not strictly a parameter but Nunjucks code convention. Using a call block enables you to call a macro with all the text inside the tag. This is helpful if you want to pass a lot of content into a macro. To use it, you will need to wrap the entire label component in a call block.
|
| for | string |
The value of the for attribute, the ID of the input the label is associated with.
|
|
is |
boolean | Whether the label also acts as the heading for the page. |
| size | string |
Size of the label – "s", "m", "l" or "xl".
|
| classes | string | Classes to add to the label tag. |
| attributes | object | HTML attributes (for example data attributes) to add to the label tag. |
The search input can be large, depending on the context of the page. For example, you can use a large input on a dedicated search page.
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.
| Name | Type | Description |
|---|---|---|
| id | string |
The ID of the input. Defaults to the value of name.
|
| name | string | Required. The name of the input, which is submitted with the form data. |
| value | string | Optional initial value of the input. |
| disabled | boolean |
If true, input will be disabled.
|
|
described |
string |
One or more element IDs to add to the aria-describedby attribute, used to provide additional descriptive information for screenreader users.
|
| label | object | Required. The label used by the search input component. See macro options for label. |
| hint | object | Can be used to add a hint to a search input component. See macro options for hint. |
|
error |
object |
Can be used to add an error message to the search input 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 error |
| prefix | object | Can be used to add a prefix to the search input component. See macro options for prefix. |
| suffix | object | Can be used to add a suffix to the search input component. See macro options for suffix. |
| code | boolean |
If set to true, use a monospace font for codes or sequences.
|
| width | integer |
Optional fixed width for the search input component – 2, 3, 4, 5, 10, 20 or 30.
|
| large | boolean |
If set to true, larger input size will be used.
|
|
form |
object |
Additional options for the form group containing the search input component.
See macro options for form |
| classes | string | Classes to add to the input. |
| autocomplete | string |
Attribute to meet WCAG success criterion 1.3.5: Identify input purpose, for instance "bday-day". See the Autofill section in the HTML standard for a full list of attributes that can be used. Default is "off".
|
| pattern | string | Attribute to provide a regular expression pattern, used to match allowed character combinations for the input value. |
|
input |
object |
Additional options for the wrapping element containing the search input component.
See macro options for input |
| attributes | object | HTML attributes (for example data attributes) to add to the input. |
| button | object | Optional object allowing customisation of the search button. See button macro options using button component macro. |
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
Required. If html is set, this is not required. Text to use within the prefix. If html is provided, the text option will be ignored.
|
| html | string |
Required.
Required. If text is set, this is not required. HTML to use within the prefix. If html is provided, the text option will be ignored.
|
| classes | string | Classes to add to the prefix. |
| attributes | object | HTML attributes (for example data attributes) to add to the prefix element. |
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
If html is set, this is not required. Text to use within the suffix. If html is provided, the text option will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML to use within the suffix. If html is provided, the text option will be ignored.
|
| classes | string | Classes to add to the suffix element. |
| attributes | object | HTML attributes (for example data attributes) to add to the suffix element. |
| Name | Type | Description |
|---|---|---|
| classes | string | Classes to add to the form group (for example to show error state for the whole group). |
| attributes | object | HTML attributes (for example data attributes) to add to the form group. |
|
before |
object |
Content to add before the input used by the search input component.
See macro options for form |
|
after |
object |
Content to add after the input used by the search input component.
See macro options for form |
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
Text to add before the input. If html is provided, the text option will be ignored.
|
| html | string |
Required.
HTML to add before the input. If html is provided, the text option will be ignored.
|
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
Text to add after the input. If html is provided, the text option will be ignored.
|
| html | string |
Required.
HTML to add after the input. If html is provided, the text option will be ignored.
|
| Name | Type | Description |
|---|---|---|
| classes | string | Classes to add to the wrapping element. |
| attributes | object | HTML attributes (for example data attributes) to add to the wrapping element. |
| Name | Type | Description |
|---|---|---|
| variant | string |
Optional variant of search button – "brand", "login", "reverse", "secondary", "secondary-solid" or "warning".
|
| classes | string | Classes to add to the search button. |
|
aria |
string | Button text exposed to assistive technologies, like screen readers, when only an icon is used. |
| icon | object | Can be used to add an icon to the search button. See macro options for button icon. |
| Name | Type | Description |
|---|---|---|
| name | string |
Required.
Icon name for the button – for example, "search", "arrow-right", "plus" or "minus".
|
| html | string |
Required.
HTML to use for the icon, as an alternative to the name option. If html is provided, the name option will be ignored.
|
| placement | string |
Required.
Placement of the icon within the button – "start" or "end".
|
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the label. |
| text | 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.
|
| html | 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.
|
| caller | nunjucks-block |
Not strictly a parameter but Nunjucks code convention. Using a call block enables you to call a macro with all the text inside the tag. This is helpful if you want to pass a lot of content into a macro. To use it, you will need to wrap the entire label component in a call block.
|
| for | string |
The value of the for attribute, the ID of the input the label is associated with.
|
|
is |
boolean | Whether the label also acts as the heading for the page. |
| size | string |
Size of the label – "s", "m", "l" or "xl".
|
| classes | string | Classes to add to the label tag. |
| attributes | object | HTML attributes (for example data attributes) to add to the label tag. |
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.
Feed back or share insights on GitHubRead more about how to feed back or share insights.
If you have any questions, get in touch with the service manual team.
Updated: June 2026