Text input
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.
<div class="govuk-form-group">
<h1 class="govuk-label-wrapper">
<label class="govuk-label govuk-label--l" for="default">
What is the name of the event?
</label>
</h1>
<input
class="govuk-input"
id="default"
name="event-name-default"
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.
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 |
inputmode | string | Optional value for inputmode. |
value | string | Optional initial value of the input. |
disabled | boolean | If |
describedBy | string | One or more element IDs to add to the |
label | object | Required. The label used by the text input component. See label. |
hint | object | Can be used to add a hint to a text input component. See hint. |
errorMessage | 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 See error message. |
prefix | object | Can be used to add a prefix to the text input component. See prefix. |
suffix | object | Can be used to add a suffix to the text input component. See suffix. |
formGroup | object | Additional options for the form group containing the text input component. See formGroup. |
classes | string | Classes to add to the input. |
autocomplete | string | Attribute to identify input purpose, for instance "postal-code" or "username". See autofill for 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. |
spellcheck | boolean | Optional field to enable or disable the |
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 See inputWrapper. |
attributes | object | HTML attributes (for example data attributes) to add to the input. |
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. |
beforeInput | object | Content to add before the input used by the text input component. See beforeInput. |
afterInput | object | Content to add after the input used by the text input component. See afterInput. |
Name | Type | Description |
---|---|---|
text | string | Required. Text to add after the input. If |
html | string | Required. HTML to add after the input. If |
Name | Type | Description |
---|---|---|
text | string | Required. Text to add before the input. If |
html | string | Required. HTML to add before the input. If |
Name | Type | Description |
---|---|---|
text | string | Required. If |
html | string | Required. If |
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. |
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 |
---|---|---|
text | string | Required. If |
html | string | Required. If |
for | string | The value of the |
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. |
Name | Type | Description |
---|---|---|
text | string | Required. Required. If |
html | string | Required. Required. If |
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 | string | Required. If |
classes | string | Classes to add to the suffix element. |
attributes | object | HTML attributes (for example data attributes) to add to the suffix element. |
{% from "moduk/components/input/macro.njk" import modukInput -%}
{{ modukInput({
label: {
text: "What is the name of the event?",
classes: "govuk-label--l",
isPageHeading: true
},
id: "default",
name: "event-name-default"
}) -}}
See GOV.UK text input component guidance for:
- when to use this component
- when not to use it
How it works
See GOV.UK text input component guidance for detail on how this component works.
If you’re asking one question on the page
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.
<div class="govuk-form-group">
<h1 class="govuk-label-wrapper">
<label class="govuk-label govuk-label--l" for="with-page-heading">
What is the name of the event?
</label>
</h1>
<input
class="govuk-input"
id="with-page-heading"
name="event-name-with-page-heading"
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.
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 |
inputmode | string | Optional value for inputmode. |
value | string | Optional initial value of the input. |
disabled | boolean | If |
describedBy | string | One or more element IDs to add to the |
label | object | Required. The label used by the text input component. See label. |
hint | object | Can be used to add a hint to a text input component. See hint. |
errorMessage | 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 See error message. |
prefix | object | Can be used to add a prefix to the text input component. See prefix. |
suffix | object | Can be used to add a suffix to the text input component. See suffix. |
formGroup | object | Additional options for the form group containing the text input component. See formGroup. |
classes | string | Classes to add to the input. |
autocomplete | string | Attribute to identify input purpose, for instance "postal-code" or "username". See autofill for 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. |
spellcheck | boolean | Optional field to enable or disable the |
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 See inputWrapper. |
attributes | object | HTML attributes (for example data attributes) to add to the input. |
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. |
beforeInput | object | Content to add before the input used by the text input component. See beforeInput. |
afterInput | object | Content to add after the input used by the text input component. See afterInput. |
Name | Type | Description |
---|---|---|
text | string | Required. Text to add after the input. If |
html | string | Required. HTML to add after the input. If |
Name | Type | Description |
---|---|---|
text | string | Required. Text to add before the input. If |
html | string | Required. HTML to add before the input. If |
Name | Type | Description |
---|---|---|
text | string | Required. If |
html | string | Required. If |
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. |
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 |
---|---|---|
text | string | Required. If |
html | string | Required. If |
for | string | The value of the |
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. |
Name | Type | Description |
---|---|---|
text | string | Required. Required. If |
html | string | Required. Required. If |
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 | string | Required. If |
classes | string | Classes to add to the suffix element. |
attributes | object | HTML attributes (for example data attributes) to add to the suffix element. |
{% from "moduk/components/input/macro.njk" import modukInput %}
{{ modukInput({
label: {
text: "What is the name of the event?",
classes: "govuk-label--l",
isPageHeading: true
},
id: "with-page-heading",
name: "event-name-with-page-heading"
}) }}
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.
<div class="govuk-form-group">
<label class="govuk-label" for="with-not-as-page-heading">
What is the name of the event?
</label>
<input
class="govuk-input"
id="with-not-as-page-heading"
name="event-name-with-not-as-page-heading"
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.
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 |
inputmode | string | Optional value for inputmode. |
value | string | Optional initial value of the input. |
disabled | boolean | If |
describedBy | string | One or more element IDs to add to the |
label | object | Required. The label used by the text input component. See label. |
hint | object | Can be used to add a hint to a text input component. See hint. |
errorMessage | 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 See error message. |
prefix | object | Can be used to add a prefix to the text input component. See prefix. |
suffix | object | Can be used to add a suffix to the text input component. See suffix. |
formGroup | object | Additional options for the form group containing the text input component. See formGroup. |
classes | string | Classes to add to the input. |
autocomplete | string | Attribute to identify input purpose, for instance "postal-code" or "username". See autofill for 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. |
spellcheck | boolean | Optional field to enable or disable the |
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 See inputWrapper. |
attributes | object | HTML attributes (for example data attributes) to add to the input. |
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. |
beforeInput | object | Content to add before the input used by the text input component. See beforeInput. |
afterInput | object | Content to add after the input used by the text input component. See afterInput. |
Name | Type | Description |
---|---|---|
text | string | Required. Text to add after the input. If |
html | string | Required. HTML to add after the input. If |
Name | Type | Description |
---|---|---|
text | string | Required. Text to add before the input. If |
html | string | Required. HTML to add before the input. If |
Name | Type | Description |
---|---|---|
text | string | Required. If |
html | string | Required. If |
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. |
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 |
---|---|---|
text | string | Required. If |
html | string | Required. If |
for | string | The value of the |
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. |
Name | Type | Description |
---|---|---|
text | string | Required. Required. If |
html | string | Required. Required. If |
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 | string | Required. If |
classes | string | Classes to add to the suffix element. |
attributes | object | HTML attributes (for example data attributes) to add to the suffix element. |
{% from "moduk/components/input/macro.njk" import modukInput -%}
{{ modukInput({
label: {
text: "What is the name of the event?"
},
id: "with-not-as-page-heading",
name: "event-name-with-not-as-page-heading"
}) -}}
Hint text
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.
<div class="govuk-form-group">
<h1 class="govuk-label-wrapper">
<label class="govuk-label govuk-label--l" for="with-hint">
What is the name of the event?
</label>
</h1>
<div id="with-hint-hint" class="govuk-hint">
The name you’ll use on promotional material
</div>
<input
class="govuk-input"
id="with-hint"
name="event-name-with-hint"
type="text"
aria-describedby="with-hint-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.
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 |
inputmode | string | Optional value for inputmode. |
value | string | Optional initial value of the input. |
disabled | boolean | If |
describedBy | string | One or more element IDs to add to the |
label | object | Required. The label used by the text input component. See label. |
hint | object | Can be used to add a hint to a text input component. See hint. |
errorMessage | 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 See error message. |
prefix | object | Can be used to add a prefix to the text input component. See prefix. |
suffix | object | Can be used to add a suffix to the text input component. See suffix. |
formGroup | object | Additional options for the form group containing the text input component. See formGroup. |
classes | string | Classes to add to the input. |
autocomplete | string | Attribute to identify input purpose, for instance "postal-code" or "username". See autofill for 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. |
spellcheck | boolean | Optional field to enable or disable the |
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 See inputWrapper. |
attributes | object | HTML attributes (for example data attributes) to add to the input. |
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. |
beforeInput | object | Content to add before the input used by the text input component. See beforeInput. |
afterInput | object | Content to add after the input used by the text input component. See afterInput. |
Name | Type | Description |
---|---|---|
text | string | Required. Text to add after the input. If |
html | string | Required. HTML to add after the input. If |
Name | Type | Description |
---|---|---|
text | string | Required. Text to add before the input. If |
html | string | Required. HTML to add before the input. If |
Name | Type | Description |
---|---|---|
text | string | Required. If |
html | string | Required. If |
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. |
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 |
---|---|---|
text | string | Required. If |
html | string | Required. If |
for | string | The value of the |
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. |
Name | Type | Description |
---|---|---|
text | string | Required. Required. If |
html | string | Required. Required. If |
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 | string | Required. If |
classes | string | Classes to add to the suffix element. |
attributes | object | HTML attributes (for example data attributes) to add to the suffix element. |
{% from "moduk/components/input/macro.njk" import modukInput -%}
{{ modukInput({
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: "with-hint",
name: "event-name-with-hint"
}) -}}
Prefixes and suffixes
<div class="govuk-form-group">
<h1 class="govuk-label-wrapper">
<label class="govuk-label govuk-label--l" for="with-prefix-and-suffix">
What is the cost per item, in pounds?
</label>
</h1>
<div class="govuk-input__wrapper">
<div class="govuk-input__prefix" aria-hidden="true">£</div>
<input
class="govuk-input govuk-input--width-5"
id="with-prefix-and-suffix"
name="cost-per-item-with-prefix-and-suffix"
type="text"
spellcheck="false"
/>
<div class="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.
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 |
inputmode | string | Optional value for inputmode. |
value | string | Optional initial value of the input. |
disabled | boolean | If |
describedBy | string | One or more element IDs to add to the |
label | object | Required. The label used by the text input component. See label. |
hint | object | Can be used to add a hint to a text input component. See hint. |
errorMessage | 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 See error message. |
prefix | object | Can be used to add a prefix to the text input component. See prefix. |
suffix | object | Can be used to add a suffix to the text input component. See suffix. |
formGroup | object | Additional options for the form group containing the text input component. See formGroup. |
classes | string | Classes to add to the input. |
autocomplete | string | Attribute to identify input purpose, for instance "postal-code" or "username". See autofill for 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. |
spellcheck | boolean | Optional field to enable or disable the |
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 See inputWrapper. |
attributes | object | HTML attributes (for example data attributes) to add to the input. |
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. |
beforeInput | object | Content to add before the input used by the text input component. See beforeInput. |
afterInput | object | Content to add after the input used by the text input component. See afterInput. |
Name | Type | Description |
---|---|---|
text | string | Required. Text to add after the input. If |
html | string | Required. HTML to add after the input. If |
Name | Type | Description |
---|---|---|
text | string | Required. Text to add before the input. If |
html | string | Required. HTML to add before the input. If |
Name | Type | Description |
---|---|---|
text | string | Required. If |
html | string | Required. If |
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. |
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 |
---|---|---|
text | string | Required. If |
html | string | Required. If |
for | string | The value of the |
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. |
Name | Type | Description |
---|---|---|
text | string | Required. Required. If |
html | string | Required. Required. If |
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 | string | Required. If |
classes | string | Classes to add to the suffix element. |
attributes | object | HTML attributes (for example data attributes) to add to the suffix element. |
{% from "moduk/components/input/macro.njk" import modukInput -%}
{{ modukInput({
id: "with-prefix-and-suffix",
name: "cost-per-item-with-prefix-and-suffix",
label: {
text: "What is the cost per item, in pounds?",
classes: "govuk-label--l",
isPageHeading: true
},
prefix: {
text: "£"
},
suffix: {
text: "per item"
},
classes: "govuk-input--width-5",
spellcheck: false
}) -}}
Text inputs with a prefix
<div class="govuk-form-group">
<h1 class="govuk-label-wrapper">
<label class="govuk-label govuk-label--l" for="with-prefix">
What is the cost in pounds?
</label>
</h1>
<div class="govuk-input__wrapper">
<div class="govuk-input__prefix" aria-hidden="true">£</div>
<input
class="govuk-input govuk-input--width-5"
id="with-prefix"
name="cost-with-prefix"
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.
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 |
inputmode | string | Optional value for inputmode. |
value | string | Optional initial value of the input. |
disabled | boolean | If |
describedBy | string | One or more element IDs to add to the |
label | object | Required. The label used by the text input component. See label. |
hint | object | Can be used to add a hint to a text input component. See hint. |
errorMessage | 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 See error message. |
prefix | object | Can be used to add a prefix to the text input component. See prefix. |
suffix | object | Can be used to add a suffix to the text input component. See suffix. |
formGroup | object | Additional options for the form group containing the text input component. See formGroup. |
classes | string | Classes to add to the input. |
autocomplete | string | Attribute to identify input purpose, for instance "postal-code" or "username". See autofill for 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. |
spellcheck | boolean | Optional field to enable or disable the |
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 See inputWrapper. |
attributes | object | HTML attributes (for example data attributes) to add to the input. |
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. |
beforeInput | object | Content to add before the input used by the text input component. See beforeInput. |
afterInput | object | Content to add after the input used by the text input component. See afterInput. |
Name | Type | Description |
---|---|---|
text | string | Required. Text to add after the input. If |
html | string | Required. HTML to add after the input. If |
Name | Type | Description |
---|---|---|
text | string | Required. Text to add before the input. If |
html | string | Required. HTML to add before the input. If |
Name | Type | Description |
---|---|---|
text | string | Required. If |
html | string | Required. If |
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. |
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 |
---|---|---|
text | string | Required. If |
html | string | Required. If |
for | string | The value of the |
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. |
Name | Type | Description |
---|---|---|
text | string | Required. Required. If |
html | string | Required. Required. If |
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 | string | Required. If |
classes | string | Classes to add to the suffix element. |
attributes | object | HTML attributes (for example data attributes) to add to the suffix element. |
{% from "moduk/components/input/macro.njk" import modukInput -%}
{{ modukInput({
id: "with-prefix",
name: "cost-with-prefix",
label: {
text: "What is the cost in pounds?",
classes: "govuk-label--l",
isPageHeading: true
},
prefix: {
text: "£"
},
classes: "govuk-input--width-5",
spellcheck: false
}) -}}
Text inputs with a suffix
<div class="govuk-form-group">
<h1 class="govuk-label-wrapper">
<label class="govuk-label govuk-label--l" for="with-suffix">
What is the weight in kilograms?
</label>
</h1>
<div class="govuk-input__wrapper">
<input
class="govuk-input govuk-input--width-5"
id="with-suffix"
name="weight-with-suffix"
type="text"
spellcheck="false"
/>
<div class="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.
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 |
inputmode | string | Optional value for inputmode. |
value | string | Optional initial value of the input. |
disabled | boolean | If |
describedBy | string | One or more element IDs to add to the |
label | object | Required. The label used by the text input component. See label. |
hint | object | Can be used to add a hint to a text input component. See hint. |
errorMessage | 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 See error message. |
prefix | object | Can be used to add a prefix to the text input component. See prefix. |
suffix | object | Can be used to add a suffix to the text input component. See suffix. |
formGroup | object | Additional options for the form group containing the text input component. See formGroup. |
classes | string | Classes to add to the input. |
autocomplete | string | Attribute to identify input purpose, for instance "postal-code" or "username". See autofill for 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. |
spellcheck | boolean | Optional field to enable or disable the |
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 See inputWrapper. |
attributes | object | HTML attributes (for example data attributes) to add to the input. |
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. |
beforeInput | object | Content to add before the input used by the text input component. See beforeInput. |
afterInput | object | Content to add after the input used by the text input component. See afterInput. |
Name | Type | Description |
---|---|---|
text | string | Required. Text to add after the input. If |
html | string | Required. HTML to add after the input. If |
Name | Type | Description |
---|---|---|
text | string | Required. Text to add before the input. If |
html | string | Required. HTML to add before the input. If |
Name | Type | Description |
---|---|---|
text | string | Required. If |
html | string | Required. If |
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. |
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 |
---|---|---|
text | string | Required. If |
html | string | Required. If |
for | string | The value of the |
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. |
Name | Type | Description |
---|---|---|
text | string | Required. Required. If |
html | string | Required. Required. If |
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 | string | Required. If |
classes | string | Classes to add to the suffix element. |
attributes | object | HTML attributes (for example data attributes) to add to the suffix element. |
{% from "moduk/components/input/macro.njk" import modukInput -%}
{{ modukInput({
id: "with-suffix",
name: "weight-with-suffix",
label: {
text: "What is the weight in kilograms?",
classes: "govuk-label--l",
isPageHeading: true
},
suffix: {
text: "kg"
},
classes: "govuk-input--width-5",
spellcheck: false
}) -}}
Changes from the GOV.UK version
MOD.UK Design System components are closely based on GOV.UK Design System components.
For this component we’ve changed the font.
Have you tested this component?
Let us know how we could improve this component or share your user research findings.
Email the MOD.UK Design System team at design-system@digital.mod.uk
Need help?
Email the MOD.UK Design System team at design-system@digital.mod.uk if you have questions or feedback.