--- url: "https://design-system.service.gov.uk/components/text-input" titulek: "Text input – GOV.UK Design System" h1: "Text input" popis: "Help users enter information with the text input component" jazyk: "en" kanonicka: "https://design-system.service.gov.uk/components/text-input/" drobecky: ["Home", "Components"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 02:12:56" znaku: 131158 slov: 20152 kodovani: "utf-8" sha256: "40b1b233e3eb638e06f832ef67691b04a6dea71cf0ef96d8ee954ffd3242c8c1" --- # Text input - HTML - Nunjucks HTML ```

``` Nunjucks Nunjucks macro options Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text. Some options are required for the macro to work; these are marked as “Required” in the option description. Deprecated options are marked as “Deprecated”. If you’re using Nunjucks macros in production with “html” options, or ones ending with “html”, you must sanitise the HTML to protect against [cross-site scripting exploits](https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting). Primary options string The ID of the input. Defaults to the value of `name`. string **Required.** The name of the input, which is submitted with the form data. string Type of input control to render, for example, a password input control. Defaults to `"text"`. string Optional value for [the inputmode attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode). string Optional initial value of the input. boolean If `true`, input will be disabled. string One or more element IDs to add to the `aria-describedby` attribute, used to provide additional descriptive information for screenreader users. object **Required.** The label used by the text input component. See macro options for label. object Can be used to add a hint to a text input component. See macro options for hint. object Can be used to add an error message to the text input component. The error message component will not display if you use a falsy value for `errorMessage`, for example `false` or `null`. [See macro options for errorMessage](/components/error-message/#options-error-message-example). object Can be used to add a prefix to the text input component. See macro options for prefix. object Can be used to add a suffix to the text input component. See macro options for suffix. object Additional options for the form group containing the text input component. See macro options for formGroup. string Classes to add to the input. string Attribute to meet [WCAG success criterion 1.3.5: Identify input purpose](https://www.w3.org/WAI/WCAG22/Understanding/identify-input-purpose.html), for instance `"bday-day"`. See the [Autofill section in the HTML standard](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill) section in the HTML standard for full list of attributes that can be used. string Attribute to [provide a regular expression pattern](https://html.spec.whatwg.org/multipage/input.html#the-pattern-attribute), used to match allowed character combinations for the input value. boolean Optional field to enable or disable the `spellcheck` attribute on the input. string Optional field to enable or disable autocapitalisation of user input. [See the Autocapitalization section in the HTML spec](https://html.spec.whatwg.org/multipage/interaction.html#autocapitalization) for a full list of values that can be used. 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. object HTML attributes (for example data attributes) to add to the input. Options for `prefix` object 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. 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. string Classes to add to the prefix. object HTML attributes (for example data attributes) to add to the prefix element. Options for `suffix` object 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. 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. string Classes to add to the suffix element. object HTML attributes (for example data attributes) to add to the suffix element. Options for `formGroup` object string Classes to add to the form group (for example to show error state for the whole group). object HTML attributes (for example data attributes) to add to the form group. object Content to add before the input used by the text input component. See macro options for formGroup beforeInput. object Content to add after the input used by the text input component. See macro options for formGroup afterInput. Options for formGroup `beforeInput` object string **Required.** Text to add before the input. If `html` is provided, the `text` option will be ignored. string **Required.** HTML to add before the input. If `html` is provided, the `text` option will be ignored. Options for formGroup `afterInput` object string **Required.** Text to add after the input. If `html` is provided, the `text` option will be ignored. string **Required.** HTML to add after the input. If `html` is provided, the `text` option will be ignored. Options for `inputWrapper` object string Classes to add to the wrapping element. object HTML attributes (for example data attributes) to add to the wrapping element. Options for `label` component 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. 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. string The value of the `for` attribute, the ID of the input the label is associated with. boolean Whether the label also acts as the heading for the page. string Classes to add to the label tag. object HTML attributes (for example data attributes) to add to the label tag. Options for `hint` component 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. 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. string Optional ID attribute to add to the hint span tag. string Classes to add to the hint span tag. 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](/components/textarea/). ## 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 - not all screen readers read it out - its browser default styles often do not meet [WCAG 2.2 success criterion 1.4.3 Contrast (minimum)](https://www.w3.org/TR/WCAG22/#contrast-minimum) ### If you’re asking one question on the page If you’re asking just [one question per page in your service](/patterns/question-pages/#start-by-asking-one-question-per-page) as recommended, you can set the contents of the `