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. |
| type | string |
Type of input control, for example, an email input control. Defaults to "search".
|
| inputmode | string |
Optional value for the inputmode attribute.
|
| 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 label macro options using label component macro. |
| 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".
|
| placeholder | string | Attribute to provide placeholder text for the search input. |
| spellcheck | boolean |
Optional field to enable or disable the spellcheck attribute on the search input.
|
| autocapitalize | string | Optional field to enable or disable autocapitalisation of user input. See the Autocapitalization section in the HTML standard for a full list of values that can be used. |
|
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 an option but supports the call block as an alternative to the html option. To use it, you will need to wrap the entire label component in a call block.
|
|
visually |
string | A visually hidden suffix added to the label. |
| caption | object | Optional caption for the label. See caption macro options using caption component macro. |
| for | string |
The label for attribute, the ID of the input the label is associated with.
|
| heading | object | Whether the label also acts as a heading. See heading macro options using heading component macro. |
|
is |
boolean |
Deprecated in 10.6.1 (see GitHub).
Replaced by the heading option.
|
| 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. |
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the label heading. |
| text | string |
Required.
If html is set, this is not required. Text to use within the label as a heading. 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 as a heading. If html is provided, the text option will be ignored.
|
|
visually |
string | A visually hidden suffix added to the label as a heading. |
| caption | object | Optional caption for the label as a heading. See caption macro options using caption component macro. |
| size | string |
Size of the label as a heading – "s", "m", "l" or "xl".
|
| level | integer |
Optional label heading level. Defaults to 1.
|
| attributes | object | HTML attributes (for example data attributes) to add to the label heading. |
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the caption. |
| element | string |
HTML element for the caption – for example, "span", "p", "h2" or "h3". Defaults to "span".
|
| text | string |
Required.
If html is set, this is not required. Text to use within the caption. 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 caption. If html is provided, the text option will be ignored.
|
| caller | nunjucks-block |
Not strictly an option but supports the call block as an alternative to the html option. To use it, you will need to wrap the entire caption component in a call block.
|
| placement | string |
Required.
Placement of the caption relative to the heading – "before", "after", "start" or "end".
|
| size | string |
Size of the caption – "m", "l", "xl" or "xxl".
|
| classes | string | Classes to add to the caption. |
| attributes | object | HTML attributes (for example data attributes) to add to the caption. |
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.
Consider using sorting or filtering alongside or instead of search.
How to use search input
Use hint text to give users help in context. Read more about hint text.
Cross icon
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 do 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. |
| type | string |
Type of input control, for example, an email input control. Defaults to "search".
|
| inputmode | string |
Optional value for the inputmode attribute.
|
| 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 label macro options using label component macro. |
| 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".
|
| placeholder | string | Attribute to provide placeholder text for the search input. |
| spellcheck | boolean |
Optional field to enable or disable the spellcheck attribute on the search input.
|
| autocapitalize | string | Optional field to enable or disable autocapitalisation of user input. See the Autocapitalization section in the HTML standard for a full list of values that can be used. |
|
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 an option but supports the call block as an alternative to the html option. To use it, you will need to wrap the entire label component in a call block.
|
|
visually |
string | A visually hidden suffix added to the label. |
| caption | object | Optional caption for the label. See caption macro options using caption component macro. |
| for | string |
The label for attribute, the ID of the input the label is associated with.
|
| heading | object | Whether the label also acts as a heading. See heading macro options using heading component macro. |
|
is |
boolean |
Deprecated in 10.6.1 (see GitHub).
Replaced by the heading option.
|
| 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. |
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the label heading. |
| text | string |
Required.
If html is set, this is not required. Text to use within the label as a heading. 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 as a heading. If html is provided, the text option will be ignored.
|
|
visually |
string | A visually hidden suffix added to the label as a heading. |
| caption | object | Optional caption for the label as a heading. See caption macro options using caption component macro. |
| size | string |
Size of the label as a heading – "s", "m", "l" or "xl".
|
| level | integer |
Optional label heading level. Defaults to 1.
|
| attributes | object | HTML attributes (for example data attributes) to add to the label heading. |
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the caption. |
| element | string |
HTML element for the caption – for example, "span", "p", "h2" or "h3". Defaults to "span".
|
| text | string |
Required.
If html is set, this is not required. Text to use within the caption. 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 caption. If html is provided, the text option will be ignored.
|
| caller | nunjucks-block |
Not strictly an option but supports the call block as an alternative to the html option. To use it, you will need to wrap the entire caption component in a call block.
|
| placement | string |
Required.
Placement of the caption relative to the heading – "before", "after", "start" or "end".
|
| size | string |
Size of the caption – "m", "l", "xl" or "xxl".
|
| classes | string | Classes to add to the caption. |
| attributes | object | HTML attributes (for example data attributes) to add to the caption. |
Text label
The search button can include a text label. For example, you can use "Find" to:
- differentiate it from other searches in the same service
- communicate that this will match only 1 result and take you directly to 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. |
| type | string |
Type of input control, for example, an email input control. Defaults to "search".
|
| inputmode | string |
Optional value for the inputmode attribute.
|
| 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 label macro options using label component macro. |
| 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".
|
| placeholder | string | Attribute to provide placeholder text for the search input. |
| spellcheck | boolean |
Optional field to enable or disable the spellcheck attribute on the search input.
|
| autocapitalize | string | Optional field to enable or disable autocapitalisation of user input. See the Autocapitalization section in the HTML standard for a full list of values that can be used. |
|
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 an option but supports the call block as an alternative to the html option. To use it, you will need to wrap the entire label component in a call block.
|
|
visually |
string | A visually hidden suffix added to the label. |
| caption | object | Optional caption for the label. See caption macro options using caption component macro. |
| for | string |
The label for attribute, the ID of the input the label is associated with.
|
| heading | object | Whether the label also acts as a heading. See heading macro options using heading component macro. |
|
is |
boolean |
Deprecated in 10.6.1 (see GitHub).
Replaced by the heading option.
|
| 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. |
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the label heading. |
| text | string |
Required.
If html is set, this is not required. Text to use within the label as a heading. 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 as a heading. If html is provided, the text option will be ignored.
|
|
visually |
string | A visually hidden suffix added to the label as a heading. |
| caption | object | Optional caption for the label as a heading. See caption macro options using caption component macro. |
| size | string |
Size of the label as a heading – "s", "m", "l" or "xl".
|
| level | integer |
Optional label heading level. Defaults to 1.
|
| attributes | object | HTML attributes (for example data attributes) to add to the label heading. |
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the caption. |
| element | string |
HTML element for the caption – for example, "span", "p", "h2" or "h3". Defaults to "span".
|
| text | string |
Required.
If html is set, this is not required. Text to use within the caption. 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 caption. If html is provided, the text option will be ignored.
|
| caller | nunjucks-block |
Not strictly an option but supports the call block as an alternative to the html option. To use it, you will need to wrap the entire caption component in a call block.
|
| placement | string |
Required.
Placement of the caption relative to the heading – "before", "after", "start" or "end".
|
| size | string |
Size of the caption – "m", "l", "xl" or "xxl".
|
| classes | string | Classes to add to the caption. |
| attributes | object | HTML attributes (for example data attributes) to add to the caption. |
Secondary button
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. |
| type | string |
Type of input control, for example, an email input control. Defaults to "search".
|
| inputmode | string |
Optional value for the inputmode attribute.
|
| 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 label macro options using label component macro. |
| 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".
|
| placeholder | string | Attribute to provide placeholder text for the search input. |
| spellcheck | boolean |
Optional field to enable or disable the spellcheck attribute on the search input.
|
| autocapitalize | string | Optional field to enable or disable autocapitalisation of user input. See the Autocapitalization section in the HTML standard for a full list of values that can be used. |
|
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 an option but supports the call block as an alternative to the html option. To use it, you will need to wrap the entire label component in a call block.
|
|
visually |
string | A visually hidden suffix added to the label. |
| caption | object | Optional caption for the label. See caption macro options using caption component macro. |
| for | string |
The label for attribute, the ID of the input the label is associated with.
|
| heading | object | Whether the label also acts as a heading. See heading macro options using heading component macro. |
|
is |
boolean |
Deprecated in 10.6.1 (see GitHub).
Replaced by the heading option.
|
| 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. |
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the label heading. |
| text | string |
Required.
If html is set, this is not required. Text to use within the label as a heading. 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 as a heading. If html is provided, the text option will be ignored.
|
|
visually |
string | A visually hidden suffix added to the label as a heading. |
| caption | object | Optional caption for the label as a heading. See caption macro options using caption component macro. |
| size | string |
Size of the label as a heading – "s", "m", "l" or "xl".
|
| level | integer |
Optional label heading level. Defaults to 1.
|
| attributes | object | HTML attributes (for example data attributes) to add to the label heading. |
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the caption. |
| element | string |
HTML element for the caption – for example, "span", "p", "h2" or "h3". Defaults to "span".
|
| text | string |
Required.
If html is set, this is not required. Text to use within the caption. 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 caption. If html is provided, the text option will be ignored.
|
| caller | nunjucks-block |
Not strictly an option but supports the call block as an alternative to the html option. To use it, you will need to wrap the entire caption component in a call block.
|
| placement | string |
Required.
Placement of the caption relative to the heading – "before", "after", "start" or "end".
|
| size | string |
Size of the caption – "m", "l", "xl" or "xxl".
|
| classes | string | Classes to add to the caption. |
| attributes | object | HTML attributes (for example data attributes) to add to the caption. |
Large search input
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. |
| type | string |
Type of input control, for example, an email input control. Defaults to "search".
|
| inputmode | string |
Optional value for the inputmode attribute.
|
| 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 label macro options using label component macro. |
| 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".
|
| placeholder | string | Attribute to provide placeholder text for the search input. |
| spellcheck | boolean |
Optional field to enable or disable the spellcheck attribute on the search input.
|
| autocapitalize | string | Optional field to enable or disable autocapitalisation of user input. See the Autocapitalization section in the HTML standard for a full list of values that can be used. |
|
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 an option but supports the call block as an alternative to the html option. To use it, you will need to wrap the entire label component in a call block.
|
|
visually |
string | A visually hidden suffix added to the label. |
| caption | object | Optional caption for the label. See caption macro options using caption component macro. |
| for | string |
The label for attribute, the ID of the input the label is associated with.
|
| heading | object | Whether the label also acts as a heading. See heading macro options using heading component macro. |
|
is |
boolean |
Deprecated in 10.6.1 (see GitHub).
Replaced by the heading option.
|
| 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. |
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the label heading. |
| text | string |
Required.
If html is set, this is not required. Text to use within the label as a heading. 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 as a heading. If html is provided, the text option will be ignored.
|
|
visually |
string | A visually hidden suffix added to the label as a heading. |
| caption | object | Optional caption for the label as a heading. See caption macro options using caption component macro. |
| size | string |
Size of the label as a heading – "s", "m", "l" or "xl".
|
| level | integer |
Optional label heading level. Defaults to 1.
|
| attributes | object | HTML attributes (for example data attributes) to add to the label heading. |
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the caption. |
| element | string |
HTML element for the caption – for example, "span", "p", "h2" or "h3". Defaults to "span".
|
| text | string |
Required.
If html is set, this is not required. Text to use within the caption. 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 caption. If html is provided, the text option will be ignored.
|
| caller | nunjucks-block |
Not strictly an option but supports the call block as an alternative to the html option. To use it, you will need to wrap the entire caption component in a call block.
|
| placement | string |
Required.
Placement of the caption relative to the heading – "before", "after", "start" or "end".
|
| size | string |
Size of the caption – "m", "l", "xl" or "xxl".
|
| classes | string | Classes to add to the caption. |
| attributes | object | HTML attributes (for example data attributes) to add to the caption. |
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.
Updates to this page
Updated: November 2026