Form elements
–
Text input
Use text input to let users enter a single line of text.
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 "text".
|
| 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 text input component. See macro options for label. |
| hint | object | Can be used to add a hint to a text input component. See macro options for hint. |
|
error |
object |
Can be used to add an error message to the text 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 text input component. See macro options for prefix. |
| suffix | object | Can be used to add a suffix to the text 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 text input component – 2, 3, 4, 5, 10, 20 or 30.
|
|
form |
object |
Additional options for the form group containing the text 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.
|
| pattern | string | Attribute to provide a regular expression pattern, used to match allowed character combinations for the input value. |
| placeholder | string | Attribute to provide placeholder text for the input. |
| spellcheck | boolean |
Optional field to enable or disable the spellcheck attribute on the 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 |
If any of prefix, suffix, formGroup.beforeInput or formGroup.afterInput have a value, a wrapping element is added around the input and inserted content. This object allows you to customise that wrapping element.
See macro options for input |
| attributes | object | HTML attributes (for example data attributes) to add to the input. |
| 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 text input component.
See macro options for form |
|
after |
object |
Content to add after the input used by the text 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 |
|---|---|---|
| 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 the text input component
Use the text input component when you need users to enter text that's no longer than a single line, such as their name or phone number.
When not to use the text input component
Do not use this component if you need users to enter longer answers that might span several lines. In this case, use the textarea component.
How to use the text input component
Give the text input a label
Give it a visible label. Do not use placeholder text for a label as it vanishes when users click on the text input.
Align labels above the text inputs they refer to. Labels should be short, direct and written in sentence case. Do not use colons at the end of labels.
If you're asking 1 question on the page
If you are asking just 1 question per page as we recommend, you can set the contents of the <label> as the page heading. This is good practice as it means that screen reader users will only hear the contents once.
Read more about how to make labels and legends headings on the GOV.UK Design System.
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 "text".
|
| 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 text input component. See macro options for label. |
| hint | object | Can be used to add a hint to a text input component. See macro options for hint. |
|
error |
object |
Can be used to add an error message to the text 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 text input component. See macro options for prefix. |
| suffix | object | Can be used to add a suffix to the text 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 text input component – 2, 3, 4, 5, 10, 20 or 30.
|
|
form |
object |
Additional options for the form group containing the text 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.
|
| pattern | string | Attribute to provide a regular expression pattern, used to match allowed character combinations for the input value. |
| placeholder | string | Attribute to provide placeholder text for the input. |
| spellcheck | boolean |
Optional field to enable or disable the spellcheck attribute on the 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 |
If any of prefix, suffix, formGroup.beforeInput or formGroup.afterInput have a value, a wrapping element is added around the input and inserted content. This object allows you to customise that wrapping element.
See macro options for input |
| attributes | object | HTML attributes (for example data attributes) to add to the input. |
| 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 text input component.
See macro options for form |
|
after |
object |
Content to add after the input used by the text 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 |
|---|---|---|
| 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. |
If you're asking more than 1 question on the page
If you're asking more than 1 question on the page, do not set the contents of the <label> as the page heading. Read more about asking multiple questions on question pages.
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 "text".
|
| 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 text input component. See macro options for label. |
| hint | object | Can be used to add a hint to a text input component. See macro options for hint. |
|
error |
object |
Can be used to add an error message to the text 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 text input component. See macro options for prefix. |
| suffix | object | Can be used to add a suffix to the text 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 text input component – 2, 3, 4, 5, 10, 20 or 30.
|
|
form |
object |
Additional options for the form group containing the text 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.
|
| pattern | string | Attribute to provide a regular expression pattern, used to match allowed character combinations for the input value. |
| placeholder | string | Attribute to provide placeholder text for the input. |
| spellcheck | boolean |
Optional field to enable or disable the spellcheck attribute on the 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 |
If any of prefix, suffix, formGroup.beforeInput or formGroup.afterInput have a value, a wrapping element is added around the input and inserted content. This object allows you to customise that wrapping element.
See macro options for input |
| attributes | object | HTML attributes (for example data attributes) to add to the input. |
| 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 text input component.
See macro options for form |
|
after |
object |
Content to add after the input used by the text 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 |
|---|---|---|
| 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. |
Make text inputs the right size
Help users understand what they should enter by making text inputs the right size for the information you want them to give you.
By default, the width of text inputs is fluid and will fit the full width of the container they are placed into.
If you want to make the input smaller, you can either use a fixed width input, or use the width override classes to create a smaller, fluid width input.
Fixed width inputs
Use fixed width inputs for content that has a specific, known length. For example, postcode inputs should be postcode-sized and phone number inputs should be phone number-sized.
On fixed width inputs, the width will remain fixed on all screens unless it is wider than the viewport, in which case it will shrink to fit.
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 "text".
|
| 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 text input component. See macro options for label. |
| hint | object | Can be used to add a hint to a text input component. See macro options for hint. |
|
error |
object |
Can be used to add an error message to the text 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 text input component. See macro options for prefix. |
| suffix | object | Can be used to add a suffix to the text 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 text input component – 2, 3, 4, 5, 10, 20 or 30.
|
|
form |
object |
Additional options for the form group containing the text 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.
|
| pattern | string | Attribute to provide a regular expression pattern, used to match allowed character combinations for the input value. |
| placeholder | string | Attribute to provide placeholder text for the input. |
| spellcheck | boolean |
Optional field to enable or disable the spellcheck attribute on the 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 |
If any of prefix, suffix, formGroup.beforeInput or formGroup.afterInput have a value, a wrapping element is added around the input and inserted content. This object allows you to customise that wrapping element.
See macro options for input |
| attributes | object | HTML attributes (for example data attributes) to add to the input. |
| 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 text input component.
See macro options for form |
|
after |
object |
Content to add after the input used by the text 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 |
|---|---|---|
| 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. |
Fluid width inputs
Use the width override classes to reduce the width of an input in relation to its parent container, for example, to two-thirds.
Fluid width inputs will resize with the viewport.
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 "text".
|
| 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 text input component. See macro options for label. |
| hint | object | Can be used to add a hint to a text input component. See macro options for hint. |
|
error |
object |
Can be used to add an error message to the text 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 text input component. See macro options for prefix. |
| suffix | object | Can be used to add a suffix to the text 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 text input component – 2, 3, 4, 5, 10, 20 or 30.
|
|
form |
object |
Additional options for the form group containing the text 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.
|
| pattern | string | Attribute to provide a regular expression pattern, used to match allowed character combinations for the input value. |
| placeholder | string | Attribute to provide placeholder text for the input. |
| spellcheck | boolean |
Optional field to enable or disable the spellcheck attribute on the 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 |
If any of prefix, suffix, formGroup.beforeInput or formGroup.afterInput have a value, a wrapping element is added around the input and inserted content. This object allows you to customise that wrapping element.
See macro options for input |
| attributes | object | HTML attributes (for example data attributes) to add to the input. |
| 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 text input component.
See macro options for form |
|
after |
object |
Content to add after the input used by the text 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 |
|---|---|---|
| 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. |
Using hint text
You can use hint text to give users help in context, so they understand what they need to enter. For example, use it to tell users where to find information or how you will use their data. Read more about hint text.
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 "text".
|
| 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 text input component. See macro options for label. |
| hint | object | Can be used to add a hint to a text input component. See macro options for hint. |
|
error |
object |
Can be used to add an error message to the text 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 text input component. See macro options for prefix. |
| suffix | object | Can be used to add a suffix to the text 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 text input component – 2, 3, 4, 5, 10, 20 or 30.
|
|
form |
object |
Additional options for the form group containing the text 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.
|
| pattern | string | Attribute to provide a regular expression pattern, used to match allowed character combinations for the input value. |
| placeholder | string | Attribute to provide placeholder text for the input. |
| spellcheck | boolean |
Optional field to enable or disable the spellcheck attribute on the 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 |
If any of prefix, suffix, formGroup.beforeInput or formGroup.afterInput have a value, a wrapping element is added around the input and inserted content. This object allows you to customise that wrapping element.
See macro options for input |
| attributes | object | HTML attributes (for example data attributes) to add to the input. |
| 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 text input component.
See macro options for form |
|
after |
object |
Content to add after the input used by the text 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 |
|---|---|---|
| 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. |
Asking for numbers
Whole numbers
If you're asking the user to enter a whole number, set the inputmode attribute to numeric to use the numeric keypad on devices with on-screen keyboards.
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 "text".
|
| 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 text input component. See macro options for label. |
| hint | object | Can be used to add a hint to a text input component. See macro options for hint. |
|
error |
object |
Can be used to add an error message to the text 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 text input component. See macro options for prefix. |
| suffix | object | Can be used to add a suffix to the text 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 text input component – 2, 3, 4, 5, 10, 20 or 30.
|
|
form |
object |
Additional options for the form group containing the text 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.
|
| pattern | string | Attribute to provide a regular expression pattern, used to match allowed character combinations for the input value. |
| placeholder | string | Attribute to provide placeholder text for the input. |
| spellcheck | boolean |
Optional field to enable or disable the spellcheck attribute on the 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 |
If any of prefix, suffix, formGroup.beforeInput or formGroup.afterInput have a value, a wrapping element is added around the input and inserted content. This object allows you to customise that wrapping element.
See macro options for input |
| attributes | object | HTML attributes (for example data attributes) to add to the input. |
| 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 text input component.
See macro options for form |
|
after |
object |
Content to add after the input used by the text 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 |
|---|---|---|
| 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. |
You should also follow the GOV.UK Design System guidance and turn off HTML5 validation to prevent browsers from validating the pattern attribute.
The GOV.UK Design System has specific guidance on how to ask for:
Decimal numbers
The GOV.UK Design System has guidance on asking for decimal numbers.
Codes and sequences
Help the user visually check the code they've typed is correct by slightly increasing the spacing between characters. Do this by adding the nhsuk-input--code class to the input to make the input text use a monospace font. This is important if you're asking the user to enter a code or sequence they're unlikely to remember, such as an NHS number, booking reference or security code.
You do not need to do this for memorable information, such as phone numbers and postcodes.
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 "text".
|
| 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 text input component. See macro options for label. |
| hint | object | Can be used to add a hint to a text input component. See macro options for hint. |
|
error |
object |
Can be used to add an error message to the text 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 text input component. See macro options for prefix. |
| suffix | object | Can be used to add a suffix to the text 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 text input component – 2, 3, 4, 5, 10, 20 or 30.
|
|
form |
object |
Additional options for the form group containing the text 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.
|
| pattern | string | Attribute to provide a regular expression pattern, used to match allowed character combinations for the input value. |
| placeholder | string | Attribute to provide placeholder text for the input. |
| spellcheck | boolean |
Optional field to enable or disable the spellcheck attribute on the 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 |
If any of prefix, suffix, formGroup.beforeInput or formGroup.afterInput have a value, a wrapping element is added around the input and inserted content. This object allows you to customise that wrapping element.
See macro options for input |
| attributes | object | HTML attributes (for example data attributes) to add to the input. |
| 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 text input component.
See macro options for form |
|
after |
object |
Content to add after the input used by the text 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 |
|---|---|---|
| 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. |
Prefixes and suffixes
Use prefixes and suffixes to help users enter things like currencies and measurements.
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 "text".
|
| 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 text input component. See macro options for label. |
| hint | object | Can be used to add a hint to a text input component. See macro options for hint. |
|
error |
object |
Can be used to add an error message to the text 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 text input component. See macro options for prefix. |
| suffix | object | Can be used to add a suffix to the text 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 text input component – 2, 3, 4, 5, 10, 20 or 30.
|
|
form |
object |
Additional options for the form group containing the text 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.
|
| pattern | string | Attribute to provide a regular expression pattern, used to match allowed character combinations for the input value. |
| placeholder | string | Attribute to provide placeholder text for the input. |
| spellcheck | boolean |
Optional field to enable or disable the spellcheck attribute on the 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 |
If any of prefix, suffix, formGroup.beforeInput or formGroup.afterInput have a value, a wrapping element is added around the input and inserted content. This object allows you to customise that wrapping element.
See macro options for input |
| attributes | object | HTML attributes (for example data attributes) to add to the input. |
| 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 text input component.
See macro options for form |
|
after |
object |
Content to add after the input used by the text 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 |
|---|---|---|
| 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. |
Prefixes and suffixes are useful when there's a commonly understood symbol or abbreviation for the type of information you're asking for. Do not rely on prefixes or suffixes alone, because screen readers will not read them out.
If you need a specific type of information, say so in the input label or hint text as well. For example, put 'Cost, in pounds' in the input label and use the '£' symbol in the prefix.
Position prefixes and suffixes so that they're outside of their input. This is to avoid interfering with some browsers that might insert an icon into the input (for example to show or generate a password).
Some users may miss that the input already has a suffix or prefix, and enter a prefix or suffix into the input. Allow for this in your validation and do not show an error.
Text inputs with a prefix
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 "text".
|
| 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 text input component. See macro options for label. |
| hint | object | Can be used to add a hint to a text input component. See macro options for hint. |
|
error |
object |
Can be used to add an error message to the text 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 text input component. See macro options for prefix. |
| suffix | object | Can be used to add a suffix to the text 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 text input component – 2, 3, 4, 5, 10, 20 or 30.
|
|
form |
object |
Additional options for the form group containing the text 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.
|
| pattern | string | Attribute to provide a regular expression pattern, used to match allowed character combinations for the input value. |
| placeholder | string | Attribute to provide placeholder text for the input. |
| spellcheck | boolean |
Optional field to enable or disable the spellcheck attribute on the 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 |
If any of prefix, suffix, formGroup.beforeInput or formGroup.afterInput have a value, a wrapping element is added around the input and inserted content. This object allows you to customise that wrapping element.
See macro options for input |
| attributes | object | HTML attributes (for example data attributes) to add to the input. |
| 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 text input component.
See macro options for form |
|
after |
object |
Content to add after the input used by the text 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 |
|---|---|---|
| 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. |
Text inputs with a suffix
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 "text".
|
| 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 text input component. See macro options for label. |
| hint | object | Can be used to add a hint to a text input component. See macro options for hint. |
|
error |
object |
Can be used to add an error message to the text 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 text input component. See macro options for prefix. |
| suffix | object | Can be used to add a suffix to the text 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 text input component – 2, 3, 4, 5, 10, 20 or 30.
|
|
form |
object |
Additional options for the form group containing the text 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.
|
| pattern | string | Attribute to provide a regular expression pattern, used to match allowed character combinations for the input value. |
| placeholder | string | Attribute to provide placeholder text for the input. |
| spellcheck | boolean |
Optional field to enable or disable the spellcheck attribute on the 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 |
If any of prefix, suffix, formGroup.beforeInput or formGroup.afterInput have a value, a wrapping element is added around the input and inserted content. This object allows you to customise that wrapping element.
See macro options for input |
| attributes | object | HTML attributes (for example data attributes) to add to the input. |
| 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 text input component.
See macro options for form |
|
after |
object |
Content to add after the input used by the text 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 |
|---|---|---|
| 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. |
Error messages
Style error messages like this.
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 "text".
|
| 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 text input component. See macro options for label. |
| hint | object | Can be used to add a hint to a text input component. See macro options for hint. |
|
error |
object |
Can be used to add an error message to the text 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 text input component. See macro options for prefix. |
| suffix | object | Can be used to add a suffix to the text 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 text input component – 2, 3, 4, 5, 10, 20 or 30.
|
|
form |
object |
Additional options for the form group containing the text 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.
|
| pattern | string | Attribute to provide a regular expression pattern, used to match allowed character combinations for the input value. |
| placeholder | string | Attribute to provide placeholder text for the input. |
| spellcheck | boolean |
Optional field to enable or disable the spellcheck attribute on the 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 |
If any of prefix, suffix, formGroup.beforeInput or formGroup.afterInput have a value, a wrapping element is added around the input and inserted content. This object allows you to customise that wrapping element.
See macro options for input |
| attributes | object | HTML attributes (for example data attributes) to add to the input. |
| 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 text input component.
See macro options for form |
|
after |
object |
Content to add after the input used by the text 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 |
|---|---|---|
| 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. |
If the input has a prefix or a suffix
- HTML code for text input error and prefix and suffix
- Nunjucks code for text input error and prefix and suffix
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 "text".
|
| 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 text input component. See macro options for label. |
| hint | object | Can be used to add a hint to a text input component. See macro options for hint. |
|
error |
object |
Can be used to add an error message to the text 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 text input component. See macro options for prefix. |
| suffix | object | Can be used to add a suffix to the text 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 text input component – 2, 3, 4, 5, 10, 20 or 30.
|
|
form |
object |
Additional options for the form group containing the text 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.
|
| pattern | string | Attribute to provide a regular expression pattern, used to match allowed character combinations for the input value. |
| placeholder | string | Attribute to provide placeholder text for the input. |
| spellcheck | boolean |
Optional field to enable or disable the spellcheck attribute on the 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 |
If any of prefix, suffix, formGroup.beforeInput or formGroup.afterInput have a value, a wrapping element is added around the input and inserted content. This object allows you to customise that wrapping element.
See macro options for input |
| attributes | object | HTML attributes (for example data attributes) to add to the input. |
| 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 text input component.
See macro options for form |
|
after |
object |
Content to add after the input used by the text 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 |
|---|---|---|
| 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. |
Follow:
Do not disable copy and paste
Users often need to copy and paste information into a text input, so do not stop them doing this.
Research
If you've used text input, please share your user research findings.
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: November 2025