When autocomplete results are available use up and down arrows to review and enter to select. Touch device users, explore by touch or with swipe gestures.
<divclass="govuk-form-group"><h1class="govuk-label-wrapper"><labelclass="govuk-label govuk-label--l"for="event-name">
What is the name of the event?
</label></h1><inputclass="govuk-input"id="event-name"name="eventName"type="text"></div>
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work; these are marked as “Required” in the option description.
If you’re using Nunjucks macros in production with “html” options, or ones ending with “html”, you must sanitise the HTML to protect against cross-site scripting exploits.
Primary options
Name
Type
Description
id
string
Required.
The ID of the input.
name
string
Required.
The name of the input, which is submitted with the form data.
type
string
Type of input control to render, for example, a password input control. Defaults to "text".
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 errorMessage.
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 autocapitalization for a full list of values that can be used.
inputWrapper
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 inputWrapper.
attributes
object
HTML attributes (for example data attributes) to add to the input.
Options for prefix object
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.
Options for suffix object
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.
Options for formGroup object
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.
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.
Options for formGroup afterInput object
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.
Options for inputWrapper object
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.
Options for label component
Name
Type
Description
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.
for
string
The value of the for attribute, the ID of the input the label is associated with.
isPageHeading
boolean
Whether the label also acts as the heading for the page.
classes
string
Classes to add to the label tag.
attributes
object
HTML attributes (for example data attributes) to add to the label tag.
Options for hint component
Name
Type
Description
text
string
Required.
If html is set, this is not required. Text to use within the hint. If html is provided, the text option will be ignored.
html
string
Required.
If text is set, this is not required. HTML to use within the hint. If html is provided, the text option will be ignored.
id
string
Optional ID attribute to add to the hint span tag.
classes
string
Classes to add to the hint span tag.
attributes
object
HTML attributes (for example data attributes) to add to the hint span tag.
{% from"govuk/components/input/macro.njk"import govukInput %}
{{ govukInput({
label: {
text: "What is the name of the event?",
classes: "govuk-label--l",
isPageHeading: true
},
id: "event-name",
name: "eventName"
}) }}
When to use this component
Use the text input component when you need to let users enter text that’s no longer than a single line, such as their name or phone number.
When not to use this component
Do not use the text input component if you need to let users enter longer answers that might span multiple lines. In this case, you should use the Textarea component.
How it works
All text inputs must have labels, and in most cases the label should be visible.
You should align labels above the text input they refer to. They should be short, direct and written in sentence case. Do not use colons at the end of labels.
Avoid placeholder text
Do not use placeholder text in place of a label, or for hints or examples, as:
it vanishes when the user starts typing, which can cause problems for users with memory conditions or when reviewing answers
If you’re asking just one question per page as recommended, you can set the contents of the <label> as the page heading. This is good practice as it means that users of screen readers will only hear the contents once.
There are 2 ways to use the text input component. You can use HTML or, if you’re using Nunjucks or the GOV.UK Prototype Kit, you can use the Nunjucks macro.
<divclass="govuk-form-group"><h1class="govuk-label-wrapper"><labelclass="govuk-label govuk-label--l"for="event-name">
What is the name of the event?
</label></h1><inputclass="govuk-input"id="event-name"name="eventName"type="text"></div>
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work; these are marked as “Required” in the option description.
If you’re using Nunjucks macros in production with “html” options, or ones ending with “html”, you must sanitise the HTML to protect against cross-site scripting exploits.
Primary options
Name
Type
Description
id
string
Required.
The ID of the input.
name
string
Required.
The name of the input, which is submitted with the form data.
type
string
Type of input control to render, for example, a password input control. Defaults to "text".
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 errorMessage.
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 autocapitalization for a full list of values that can be used.
inputWrapper
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 inputWrapper.
attributes
object
HTML attributes (for example data attributes) to add to the input.
Options for prefix object
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.
Options for suffix object
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.
Options for formGroup object
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.
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.
Options for formGroup afterInput object
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.
Options for inputWrapper object
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.
Options for label component
Name
Type
Description
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.
for
string
The value of the for attribute, the ID of the input the label is associated with.
isPageHeading
boolean
Whether the label also acts as the heading for the page.
classes
string
Classes to add to the label tag.
attributes
object
HTML attributes (for example data attributes) to add to the label tag.
Options for hint component
Name
Type
Description
text
string
Required.
If html is set, this is not required. Text to use within the hint. If html is provided, the text option will be ignored.
html
string
Required.
If text is set, this is not required. HTML to use within the hint. If html is provided, the text option will be ignored.
id
string
Optional ID attribute to add to the hint span tag.
classes
string
Classes to add to the hint span tag.
attributes
object
HTML attributes (for example data attributes) to add to the hint span tag.
{% from"govuk/components/input/macro.njk"import govukInput %}
{{ govukInput({
label: {
text: "What is the name of the event?",
classes: "govuk-label--l",
isPageHeading: true
},
id: "event-name",
name: "eventName"
}) }}
If you’re asking more than one question on the page
If you’re asking more than one 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.
<divclass="govuk-form-group"><labelclass="govuk-label"for="event-name">
What is the name of the event?
</label><inputclass="govuk-input"id="event-name"name="eventName"type="text"></div>
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work; these are marked as “Required” in the option description.
If you’re using Nunjucks macros in production with “html” options, or ones ending with “html”, you must sanitise the HTML to protect against cross-site scripting exploits.
Primary options
Name
Type
Description
id
string
Required.
The ID of the input.
name
string
Required.
The name of the input, which is submitted with the form data.
type
string
Type of input control to render, for example, a password input control. Defaults to "text".
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 errorMessage.
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 autocapitalization for a full list of values that can be used.
inputWrapper
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 inputWrapper.
attributes
object
HTML attributes (for example data attributes) to add to the input.
Options for prefix object
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.
Options for suffix object
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.
Options for formGroup object
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.
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.
Options for formGroup afterInput object
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.
Options for inputWrapper object
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.
Options for label component
Name
Type
Description
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.
for
string
The value of the for attribute, the ID of the input the label is associated with.
isPageHeading
boolean
Whether the label also acts as the heading for the page.
classes
string
Classes to add to the label tag.
attributes
object
HTML attributes (for example data attributes) to add to the label tag.
Options for hint component
Name
Type
Description
text
string
Required.
If html is set, this is not required. Text to use within the hint. If html is provided, the text option will be ignored.
html
string
Required.
If text is set, this is not required. HTML to use within the hint. If html is provided, the text option will be ignored.
id
string
Optional ID attribute to add to the hint span tag.
classes
string
Classes to add to the hint span tag.
attributes
object
HTML attributes (for example data attributes) to add to the hint span tag.
{% from"govuk/components/input/macro.njk"import govukInput %}
{{ govukInput({
label: {
text: "What is the name of the event?"
},
id: "event-name",
name: "eventName"
}) }}
Use appropriately-sized text inputs
Help users understand what they should enter by making text inputs the right size for the content they’re intended for.
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. Postcode inputs should be postcode-sized, phone number inputs should be phone number-sized.
The widths are designed for specific character lengths and to be consistent across a range of browsers. They include extra padding to fit icons that some browsers might insert into the input (for example to show or generate a password).
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.
<divclass="govuk-form-group"><labelclass="govuk-label"for="width-20">
20 character width
</label><inputclass="govuk-input govuk-input--width-20"id="width-20"name="width20"type="text"></div><divclass="govuk-form-group"><labelclass="govuk-label"for="width-10">
10 character width
</label><inputclass="govuk-input govuk-input--width-10"id="width-10"name="width10"type="text"></div><divclass="govuk-form-group"><labelclass="govuk-label"for="width-5">
5 character width
</label><inputclass="govuk-input govuk-input--width-5"id="width-5"name="width5"type="text"></div><divclass="govuk-form-group"><labelclass="govuk-label"for="width-4">
4 character width
</label><inputclass="govuk-input govuk-input--width-4"id="width-4"name="width4"type="text"></div><divclass="govuk-form-group"><labelclass="govuk-label"for="width-3">
3 character width
</label><inputclass="govuk-input govuk-input--width-3"id="width-3"name="width3"type="text"></div><divclass="govuk-form-group"><labelclass="govuk-label"for="width-2">
2 character width
</label><inputclass="govuk-input govuk-input--width-2"id="width-2"name="width2"type="text"></div>
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work; these are marked as “Required” in the option description.
If you’re using Nunjucks macros in production with “html” options, or ones ending with “html”, you must sanitise the HTML to protect against cross-site scripting exploits.
Primary options
Name
Type
Description
id
string
Required.
The ID of the input.
name
string
Required.
The name of the input, which is submitted with the form data.
type
string
Type of input control to render, for example, a password input control. Defaults to "text".
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 errorMessage.
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 autocapitalization for a full list of values that can be used.
inputWrapper
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 inputWrapper.
attributes
object
HTML attributes (for example data attributes) to add to the input.
Options for prefix object
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.
Options for suffix object
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.
Options for formGroup object
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.
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work; these are marked as “Required” in the option description.
If you’re using Nunjucks macros in production with “html” options, or ones ending with “html”, you must sanitise the HTML to protect against cross-site scripting exploits.
Primary options
Name
Type
Description
id
string
Required.
The ID of the input.
name
string
Required.
The name of the input, which is submitted with the form data.
type
string
Type of input control to render, for example, a password input control. Defaults to "text".
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 errorMessage.
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 autocapitalization for a full list of values that can be used.
inputWrapper
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 inputWrapper.
attributes
object
HTML attributes (for example data attributes) to add to the input.
Options for prefix object
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.
Options for suffix object
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.
Options for formGroup object
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.
Use hint text for help that’s relevant to the majority of users, like how their information will be used, or where to find it.
Keep hint text to a single short sentence, without any full stops.
Do not use links in hint text. While screen readers will read out the link text when describing the field, they usually do not tell users the text is a link.
<divclass="govuk-form-group"><h1class="govuk-label-wrapper"><labelclass="govuk-label govuk-label--l"for="event-name">
What is the name of the event?
</label></h1><divid="event-name-hint"class="govuk-hint">
The name you’ll use on promotional material
</div><inputclass="govuk-input"id="event-name"name="eventName"type="text"aria-describedby="event-name-hint"></div>
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work; these are marked as “Required” in the option description.
If you’re using Nunjucks macros in production with “html” options, or ones ending with “html”, you must sanitise the HTML to protect against cross-site scripting exploits.
Primary options
Name
Type
Description
id
string
Required.
The ID of the input.
name
string
Required.
The name of the input, which is submitted with the form data.
type
string
Type of input control to render, for example, a password input control. Defaults to "text".
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 errorMessage.
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 autocapitalization for a full list of values that can be used.
inputWrapper
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 inputWrapper.
attributes
object
HTML attributes (for example data attributes) to add to the input.
Options for prefix object
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.
Options for suffix object
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.
Options for formGroup object
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.
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.
Options for formGroup afterInput object
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.
Options for inputWrapper object
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.
Options for label component
Name
Type
Description
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.
for
string
The value of the for attribute, the ID of the input the label is associated with.
isPageHeading
boolean
Whether the label also acts as the heading for the page.
classes
string
Classes to add to the label tag.
attributes
object
HTML attributes (for example data attributes) to add to the label tag.
Options for hint component
Name
Type
Description
text
string
Required.
If html is set, this is not required. Text to use within the hint. If html is provided, the text option will be ignored.
html
string
Required.
If text is set, this is not required. HTML to use within the hint. If html is provided, the text option will be ignored.
id
string
Optional ID attribute to add to the hint span tag.
classes
string
Classes to add to the hint span tag.
attributes
object
HTML attributes (for example data attributes) to add to the hint span tag.
{% from"govuk/components/input/macro.njk"import govukInput %}
{{ govukInput({
label: {
text: "What is the name of the event?",
classes: "govuk-label--l",
isPageHeading: true
},
hint: {
text: "The name you’ll use on promotional material"
},
id: "event-name",
name: "eventName"
}) }}
When not to use hint text
Do not use hint text to explain anything that’s longer than a short, simple sentence. Screen readers read out the entire text when users interact with the form element. This could frustrate users if the text is long.
Do not include links within hint text. While screen readers will read out the link text when describing the field, they will not tell users that the text is a link.
Numbers
Asking for 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.
See how to do this by opening the HTML and Nunjucks tabs in this example:
<divclass="govuk-form-group"><h1class="govuk-label-wrapper"><labelclass="govuk-label govuk-label--l"for="account-number">
What is your account number?
</label></h1><divid="account-number-hint"class="govuk-hint">
Must be between 6 and 8 digits long
</div><inputclass="govuk-input govuk-input--width-10"id="account-number"name="accountNumber"type="text"spellcheck="false"aria-describedby="account-number-hint"inputmode="numeric"></div>
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work; these are marked as “Required” in the option description.
If you’re using Nunjucks macros in production with “html” options, or ones ending with “html”, you must sanitise the HTML to protect against cross-site scripting exploits.
Primary options
Name
Type
Description
id
string
Required.
The ID of the input.
name
string
Required.
The name of the input, which is submitted with the form data.
type
string
Type of input control to render, for example, a password input control. Defaults to "text".
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 errorMessage.
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 autocapitalization for a full list of values that can be used.
inputWrapper
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 inputWrapper.
attributes
object
HTML attributes (for example data attributes) to add to the input.
Options for prefix object
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.
Options for suffix object
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.
Options for formGroup object
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.
<divclass="govuk-form-group"><labelclass="govuk-label"for="weight">
Weight, in kilograms
</label><divclass="govuk-input__wrapper"><inputclass="govuk-input govuk-input--width-5"id="weight"name="weight"type="text"spellcheck="false"><divclass="govuk-input__suffix"aria-hidden="true">kg</div></div></div>
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work; these are marked as “Required” in the option description.
If you’re using Nunjucks macros in production with “html” options, or ones ending with “html”, you must sanitise the HTML to protect against cross-site scripting exploits.
Primary options
Name
Type
Description
id
string
Required.
The ID of the input.
name
string
Required.
The name of the input, which is submitted with the form data.
type
string
Type of input control to render, for example, a password input control. Defaults to "text".
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 errorMessage.
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 autocapitalization for a full list of values that can be used.
inputWrapper
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 inputWrapper.
attributes
object
HTML attributes (for example data attributes) to add to the input.
Options for prefix object
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.
Options for suffix object
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.
Options for formGroup object
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.
Do not use <input type="number"> unless your user research shows that there’s a need for it. With <input type="number"> there’s a risk of users accidentally incrementing a number when they’re trying to do something else - for example, scroll up or down the page. And if the user tries to enter something that’s not a number, there’s no explicit feedback about what they’re doing wrong.
Codes and sequences
Help the user visually check the code they’ve typed is correct by styling the input’s text to visually separate each character. This is important if you’re asking the user to enter a code or sequence they’re unlikely to have memorised, such as an application reference ID, account number or security code.
You do not need to do this for memorable information, such as phone numbers and postcodes.
<divclass="govuk-form-group"><labelclass="govuk-label"for="authentication-code">
Company authentication code
</label><divid="authentication-code-hint"class="govuk-hint">
This is on the company incorporation letter sent to the registered office address
</div><inputclass="govuk-input govuk-input--width-5 govuk-input--extra-letter-spacing"id="authentication-code"name="authenticationCode"type="text"spellcheck="false"value="NC1701"aria-describedby="authentication-code-hint"></div>
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work; these are marked as “Required” in the option description.
If you’re using Nunjucks macros in production with “html” options, or ones ending with “html”, you must sanitise the HTML to protect against cross-site scripting exploits.
Primary options
Name
Type
Description
id
string
Required.
The ID of the input.
name
string
Required.
The name of the input, which is submitted with the form data.
type
string
Type of input control to render, for example, a password input control. Defaults to "text".
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 errorMessage.
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 autocapitalization for a full list of values that can be used.
inputWrapper
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 inputWrapper.
attributes
object
HTML attributes (for example data attributes) to add to the input.
Options for prefix object
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.
Options for suffix object
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.
Options for formGroup object
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.
<divclass="govuk-form-group"><h1class="govuk-label-wrapper"><labelclass="govuk-label govuk-label--l"for="cost-per-item">
What is the cost per item, in pounds?
</label></h1><divclass="govuk-input__wrapper"><divclass="govuk-input__prefix"aria-hidden="true">£</div><inputclass="govuk-input govuk-input--width-5"id="cost-per-item"name="costPerItem"type="text"spellcheck="false"><divclass="govuk-input__suffix"aria-hidden="true">per item</div></div></div>
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work; these are marked as “Required” in the option description.
If you’re using Nunjucks macros in production with “html” options, or ones ending with “html”, you must sanitise the HTML to protect against cross-site scripting exploits.
Primary options
Name
Type
Description
id
string
Required.
The ID of the input.
name
string
Required.
The name of the input, which is submitted with the form data.
type
string
Type of input control to render, for example, a password input control. Defaults to "text".
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 errorMessage.
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 autocapitalization for a full list of values that can be used.
inputWrapper
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 inputWrapper.
attributes
object
HTML attributes (for example data attributes) to add to the input.
Options for prefix object
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.
Options for suffix object
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.
Options for formGroup object
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.
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.
<divclass="govuk-form-group"><h1class="govuk-label-wrapper"><labelclass="govuk-label govuk-label--l"for="cost">
What is the cost in pounds?
</label></h1><divclass="govuk-input__wrapper"><divclass="govuk-input__prefix"aria-hidden="true">£</div><inputclass="govuk-input govuk-input--width-5"id="cost"name="cost"type="text"spellcheck="false"></div></div>
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work; these are marked as “Required” in the option description.
If you’re using Nunjucks macros in production with “html” options, or ones ending with “html”, you must sanitise the HTML to protect against cross-site scripting exploits.
Primary options
Name
Type
Description
id
string
Required.
The ID of the input.
name
string
Required.
The name of the input, which is submitted with the form data.
type
string
Type of input control to render, for example, a password input control. Defaults to "text".
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 errorMessage.
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 autocapitalization for a full list of values that can be used.
inputWrapper
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 inputWrapper.
attributes
object
HTML attributes (for example data attributes) to add to the input.
Options for prefix object
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.
Options for suffix object
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.
Options for formGroup object
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.
<divclass="govuk-form-group"><h1class="govuk-label-wrapper"><labelclass="govuk-label govuk-label--l"for="weight">
What is the weight in kilograms?
</label></h1><divclass="govuk-input__wrapper"><inputclass="govuk-input govuk-input--width-5"id="weight"name="weight"type="text"spellcheck="false"><divclass="govuk-input__suffix"aria-hidden="true">kg</div></div></div>
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work; these are marked as “Required” in the option description.
If you’re using Nunjucks macros in production with “html” options, or ones ending with “html”, you must sanitise the HTML to protect against cross-site scripting exploits.
Primary options
Name
Type
Description
id
string
Required.
The ID of the input.
name
string
Required.
The name of the input, which is submitted with the form data.
type
string
Type of input control to render, for example, a password input control. Defaults to "text".
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 errorMessage.
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 autocapitalization for a full list of values that can be used.
inputWrapper
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 inputWrapper.
attributes
object
HTML attributes (for example data attributes) to add to the input.
Options for prefix object
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.
Options for suffix object
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.
Options for formGroup object
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.
Use the autocomplete attribute on text inputs to help users complete forms more quickly. This lets you specify an input’s purpose so browsers can autofill the information on a user’s behalf if they’ve entered it previously.
For example, to enable autofill on a postcode field, set the autocomplete attribute to postal-code. See how to do this in the HTML and Nunjucks tabs in the following example.
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work; these are marked as “Required” in the option description.
If you’re using Nunjucks macros in production with “html” options, or ones ending with “html”, you must sanitise the HTML to protect against cross-site scripting exploits.
Primary options
Name
Type
Description
id
string
Required.
The ID of the input.
name
string
Required.
The name of the input, which is submitted with the form data.
type
string
Type of input control to render, for example, a password input control. Defaults to "text".
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 errorMessage.
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 autocapitalization for a full list of values that can be used.
inputWrapper
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 inputWrapper.
attributes
object
HTML attributes (for example data attributes) to add to the input.
Options for prefix object
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.
Options for suffix object
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.
Options for formGroup object
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.
If you are working in production and there is a relevant input purpose, you’ll need to use the autocomplete attribute to meet WCAG 2.1 Level AA.
You will not normally need to use the autocomplete attribute in prototypes, as users will not generally be using their own devices.
Do not disable copy and paste
Users often need to copy and paste information into a text input, so do not stop them from doing this.
Avoid restricting the length of a user’s input
Using the maxlength attribute means there is no feedback to users that their text input is truncated. This is especially true where the text has been copied and pasted from elsewhere. This can cause users to accidentally provide incorrect or incomplete information.
A restrictive maximum length can stop users from formatting information in their usual way. For example, putting spaces in a postcode or commas in a large number.
Some assistive technologies do not tell users if an input has a maxlength set or if the user has passed the limit. Voice control software may insert additional spaces into the input.
If you must enforce a maximum length for technical reasons, inform the user of the limit in the hint, but allow them to provide more information. Only return an error if the value is longer than allowed after normalisation. For longer values, consider using the Character count component instead.
How and when to spellcheck a user’s input
Sometimes, browsers will spellcheck the information a user puts into a text input. If a user enters something which is recognised as a spelling error, sighted users will see a red line under the word.
If you are asking users for information which is not appropriate to spellcheck, like a reference number, name, email address or National Insurance number, disable the spellcheck.
To do this set the spellcheck attribute to false as shown in this example.
<divclass="govuk-form-group"><labelclass="govuk-label"for="name">
Reference number
</label><inputclass="govuk-input"id="name"name="name"type="text"spellcheck="false"></div>
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work; these are marked as “Required” in the option description.
If you’re using Nunjucks macros in production with “html” options, or ones ending with “html”, you must sanitise the HTML to protect against cross-site scripting exploits.
Primary options
Name
Type
Description
id
string
Required.
The ID of the input.
name
string
Required.
The name of the input, which is submitted with the form data.
type
string
Type of input control to render, for example, a password input control. Defaults to "text".
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 errorMessage.
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 autocapitalization for a full list of values that can be used.
inputWrapper
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 inputWrapper.
attributes
object
HTML attributes (for example data attributes) to add to the input.
Options for prefix object
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.
Options for suffix object
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.
Options for formGroup object
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.
Browsers do not consistently spellcheck user’s input by default. If you are asking a question where spellcheck would be useful, set the spellcheck attribute to true.
<divclass="govuk-form-group govuk-form-group--error"><h1class="govuk-label-wrapper"><labelclass="govuk-label govuk-label--l"for="event-name">
What is the name of the event?
</label></h1><divid="event-name-hint"class="govuk-hint">
The name you’ll use on promotional material
</div><pid="event-name-error"class="govuk-error-message"><spanclass="govuk-visually-hidden">Error:</span> Enter an event name
</p><inputclass="govuk-input govuk-input--error"id="event-name"name="eventName"type="text"aria-describedby="event-name-hint event-name-error"></div>
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work; these are marked as “Required” in the option description.
If you’re using Nunjucks macros in production with “html” options, or ones ending with “html”, you must sanitise the HTML to protect against cross-site scripting exploits.
Primary options
Name
Type
Description
id
string
Required.
The ID of the input.
name
string
Required.
The name of the input, which is submitted with the form data.
type
string
Type of input control to render, for example, a password input control. Defaults to "text".
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 errorMessage.
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 autocapitalization for a full list of values that can be used.
inputWrapper
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 inputWrapper.
attributes
object
HTML attributes (for example data attributes) to add to the input.
Options for prefix object
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.
Options for suffix object
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.
Options for formGroup object
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.
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.
Options for formGroup afterInput object
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.
Options for inputWrapper object
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.
Options for label component
Name
Type
Description
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.
for
string
The value of the for attribute, the ID of the input the label is associated with.
isPageHeading
boolean
Whether the label also acts as the heading for the page.
classes
string
Classes to add to the label tag.
attributes
object
HTML attributes (for example data attributes) to add to the label tag.
Options for hint component
Name
Type
Description
text
string
Required.
If html is set, this is not required. Text to use within the hint. If html is provided, the text option will be ignored.
html
string
Required.
If text is set, this is not required. HTML to use within the hint. If html is provided, the text option will be ignored.
id
string
Optional ID attribute to add to the hint span tag.
classes
string
Classes to add to the hint span tag.
attributes
object
HTML attributes (for example data attributes) to add to the hint span tag.
{% from"govuk/components/input/macro.njk"import govukInput %}
{{ govukInput({
label: {
text: "What is the name of the event?",
classes: "govuk-label--l",
isPageHeading: true
},
id: "event-name",
name: "eventName",
hint: {
text: "The name you’ll use on promotional material"
},
errorMessage: {
text: "Enter an event name"
}
}) }}
<divclass="govuk-form-group govuk-form-group--error"><h1class="govuk-label-wrapper"><labelclass="govuk-label govuk-label--l"for="cost-per-item-error">
What is the cost per item, in pounds?
</label></h1><pid="cost-per-item-error-error"class="govuk-error-message"><spanclass="govuk-visually-hidden">Error:</span> Enter a cost per item, in pounds
</p><divclass="govuk-input__wrapper"><divclass="govuk-input__prefix"aria-hidden="true">£</div><inputclass="govuk-input govuk-input--width-5 govuk-input--error"id="cost-per-item-error"name="costPerItemError"type="text"spellcheck="false"aria-describedby="cost-per-item-error-error"><divclass="govuk-input__suffix"aria-hidden="true">per item</div></div></div>
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work; these are marked as “Required” in the option description.
If you’re using Nunjucks macros in production with “html” options, or ones ending with “html”, you must sanitise the HTML to protect against cross-site scripting exploits.
Primary options
Name
Type
Description
id
string
Required.
The ID of the input.
name
string
Required.
The name of the input, which is submitted with the form data.
type
string
Type of input control to render, for example, a password input control. Defaults to "text".
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 errorMessage.
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 autocapitalization for a full list of values that can be used.
inputWrapper
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 inputWrapper.
attributes
object
HTML attributes (for example data attributes) to add to the input.
Options for prefix object
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.
Options for suffix object
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.
Options for formGroup object
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.