Components
Textarea
<div class="govuk-form-group">
<h1 class="govuk-label-wrapper"><label class="govuk-label govuk-label--l" for="more-detail">
Can you provide more detail?
</label>
</h1>
<div id="more-detail-hint" class="govuk-hint">
Do not include personal or financial information, like your National Insurance number or credit card details.
</div>
<textarea class="govuk-textarea" id="more-detail" name="more-detail" rows="5" aria-describedby="more-detail-hint"></textarea>
</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
string |
Required.
The id of the textarea.
|
string |
Required.
The name of the textarea, which is submitted with the form data.
|
boolean |
Optional field to enable or disable the spellcheck attribute on the textarea.
|
string |
Optional number of textarea rows (default is 5 rows).
|
string |
Optional initial value of the textarea.
|
string |
One or more element IDs to add to the aria-describedby attribute, used to provide additional descriptive information for screenreader users.
|
object |
Required.
Options for the label component.
See label.
|
object |
Options for the hint component.
See hint.
|
object |
Options for the error message component. The error message component will not display if you use a falsy value for errorMessage , for example false or null .
See errorMessage.
|
object |
Options for the form-group wrapper
See formGroup.
|
string |
Classes to add to the textarea.
|
string |
Attribute to identify input purpose, for instance "postal-code" or "username". See autofill for full list of attributes that can be used.
|
object |
HTML attributes (for example data attributes) to add to the textarea.
|
Options for formGroup
string |
Classes to add to the form group (e.g. to show error state for the whole group)
|
Options for label
string |
Required.
If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` argument 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` argument 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
string |
Required.
If `html` is set, this is not required. Text to use within the hint. If `html` is provided, the `text` argument 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` argument 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/textarea/macro.njk" import govukTextarea %}
{{ govukTextarea({
name: "more-detail",
id: "more-detail",
label: {
text: "Can you provide more detail?",
classes: "govuk-label--l",
isPageHeading: true
},
hint: {
text: "Do not include personal or financial information, like your National Insurance number or credit card details."
}
}) }}
When to use this component
Use the textarea component when you need to let users enter an amount of text that’s longer than a single line.
When not to use this component
Users can find open-ended questions difficult to answer. It might be better to break up one complex question into a series of simple ones, for example where users can select from options using radios.
If you need to ask an open question
Do not use the textarea component if you need to let users enter shorter answers no longer than a single line, such as a phone number or name. In this case, you should use the text input component.
How it works
There are 2 ways to use the textarea component. You can use HTML or, if you’re using Nunjucks or the GOV.UK Prototype Kit, you can use the Nunjucks macro.
<div class="govuk-form-group">
<h1 class="govuk-label-wrapper"><label class="govuk-label govuk-label--l" for="more-detail">
Can you provide more detail?
</label>
</h1>
<div id="more-detail-hint" class="govuk-hint">
Do not include personal or financial information, like your National Insurance number or credit card details.
</div>
<textarea class="govuk-textarea" id="more-detail" name="more-detail" rows="5" aria-describedby="more-detail-hint"></textarea>
</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
string |
Required.
The id of the textarea.
|
string |
Required.
The name of the textarea, which is submitted with the form data.
|
boolean |
Optional field to enable or disable the spellcheck attribute on the textarea.
|
string |
Optional number of textarea rows (default is 5 rows).
|
string |
Optional initial value of the textarea.
|
string |
One or more element IDs to add to the aria-describedby attribute, used to provide additional descriptive information for screenreader users.
|
object |
Required.
Options for the label component.
See label.
|
object |
Options for the hint component.
See hint.
|
object |
Options for the error message component. The error message component will not display if you use a falsy value for errorMessage , for example false or null .
See errorMessage.
|
object |
Options for the form-group wrapper
See formGroup.
|
string |
Classes to add to the textarea.
|
string |
Attribute to identify input purpose, for instance "postal-code" or "username". See autofill for full list of attributes that can be used.
|
object |
HTML attributes (for example data attributes) to add to the textarea.
|
Options for formGroup
string |
Classes to add to the form group (e.g. to show error state for the whole group)
|
Options for label
string |
Required.
If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` argument 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` argument 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
string |
Required.
If `html` is set, this is not required. Text to use within the hint. If `html` is provided, the `text` argument 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` argument 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/textarea/macro.njk" import govukTextarea %}
{{ govukTextarea({
name: "more-detail",
id: "more-detail",
label: {
text: "Can you provide more detail?",
classes: "govuk-label--l",
isPageHeading: true
},
hint: {
text: "Do not include personal or financial information, like your National Insurance number or credit card details."
}
}) }}
Label textareas
You must label textareas. Placeholder text is not a suitable substitute for a label, as it disappears when users click inside the textarea.
Labels must be aligned above the textarea they refer to. They should be short, direct and written in sentence case. Do not use colons at the end of labels.
Use appropriately-sized textareas
Make the height of a textarea proportional to the amount of text you expect users to enter. You can set the height of a textarea by by specifying the rows
attribute.
<div class="govuk-form-group">
<h1 class="govuk-label-wrapper"><label class="govuk-label govuk-label--l" for="more-detail">
Can you provide more detail?
</label>
</h1>
<div id="more-detail-hint" class="govuk-hint">
Do not include personal or financial information, like your National Insurance number or credit card details.
</div>
<textarea class="govuk-textarea" id="more-detail" name="more-detail" rows="8" aria-describedby="more-detail-hint"></textarea>
</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
string |
Required.
The id of the textarea.
|
string |
Required.
The name of the textarea, which is submitted with the form data.
|
boolean |
Optional field to enable or disable the spellcheck attribute on the textarea.
|
string |
Optional number of textarea rows (default is 5 rows).
|
string |
Optional initial value of the textarea.
|
string |
One or more element IDs to add to the aria-describedby attribute, used to provide additional descriptive information for screenreader users.
|
object |
Required.
Options for the label component.
See label.
|
object |
Options for the hint component.
See hint.
|
object |
Options for the error message component. The error message component will not display if you use a falsy value for errorMessage , for example false or null .
See errorMessage.
|
object |
Options for the form-group wrapper
See formGroup.
|
string |
Classes to add to the textarea.
|
string |
Attribute to identify input purpose, for instance "postal-code" or "username". See autofill for full list of attributes that can be used.
|
object |
HTML attributes (for example data attributes) to add to the textarea.
|
Options for formGroup
string |
Classes to add to the form group (e.g. to show error state for the whole group)
|
Options for label
string |
Required.
If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` argument 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` argument 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
string |
Required.
If `html` is set, this is not required. Text to use within the hint. If `html` is provided, the `text` argument 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` argument 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/textarea/macro.njk" import govukTextarea %}
{{ govukTextarea({
name: "more-detail",
id: "more-detail",
rows: "8",
label: {
text: "Can you provide more detail?",
classes: "govuk-label--l",
isPageHeading: true
},
hint: {
text: "Do not include personal or financial information, like your National Insurance number or credit card details."
}
}) }}
Do not disable copy and paste
Users will often need to copy and paste information into a textarea, so do not stop them from doing this.
Limiting the number of characters
If there’s a good reason to limit the number of characters users can enter, you can use the character count component.
Error messages
Error messages should be styled like this:
<div class="govuk-form-group govuk-form-group--error">
<h1 class="govuk-label-wrapper"><label class="govuk-label govuk-label--l" for="more-detail">
Can you provide more detail?
</label>
</h1>
<div id="more-detail-hint" class="govuk-hint">
Do not include personal or financial information, like your National Insurance number or credit card details.
</div>
<span id="more-detail-error" class="govuk-error-message">
<span class="govuk-visually-hidden">Error:</span> Enter more detail
</span>
<textarea class="govuk-textarea govuk-textarea--error" id="more-detail" name="more-detail" rows="5" aria-describedby="more-detail-hint more-detail-error"></textarea>
</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
string |
Required.
The id of the textarea.
|
string |
Required.
The name of the textarea, which is submitted with the form data.
|
boolean |
Optional field to enable or disable the spellcheck attribute on the textarea.
|
string |
Optional number of textarea rows (default is 5 rows).
|
string |
Optional initial value of the textarea.
|
string |
One or more element IDs to add to the aria-describedby attribute, used to provide additional descriptive information for screenreader users.
|
object |
Required.
Options for the label component.
See label.
|
object |
Options for the hint component.
See hint.
|
object |
Options for the error message component. The error message component will not display if you use a falsy value for errorMessage , for example false or null .
See errorMessage.
|
object |
Options for the form-group wrapper
See formGroup.
|
string |
Classes to add to the textarea.
|
string |
Attribute to identify input purpose, for instance "postal-code" or "username". See autofill for full list of attributes that can be used.
|
object |
HTML attributes (for example data attributes) to add to the textarea.
|
Options for formGroup
string |
Classes to add to the form group (e.g. to show error state for the whole group)
|
Options for label
string |
Required.
If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` argument 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` argument 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
string |
Required.
If `html` is set, this is not required. Text to use within the hint. If `html` is provided, the `text` argument 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` argument 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/textarea/macro.njk" import govukTextarea %}
{{ govukTextarea({
name: "more-detail",
id: "more-detail",
label: {
text: "Can you provide more detail?",
classes: "govuk-label--l",
isPageHeading: true
},
hint: {
text: "Do not include personal or financial information, like your National Insurance number or credit card details."
},
errorMessage: {
text: "Enter more detail"
}
}) }}
Make sure errors follow the guidance in error message and have specific error messages for specific error states.
Say ‘Enter [whatever it is]’.
For example, ‘Enter summary’.
Say ‘[whatever it is] must be [number] characters or fewer’.
For example, ‘Summary must be 400 characters or fewer’.
Say ‘[whatever it is] must be [number] characters or more’.
For example, ‘Summary must be 10 characters or more’.
Say ‘[whatever it is] must be between [number] and [number] characters’.
For example, ‘Summary must be between 10 and 400 characters’.
Say ‘[whatever it is] must not include [characters]’.
For example, ‘Summary must not include è and £’.
Say ‘[whatever it is] must only include [list of allowed characters]’.
For example, ‘Summary must only include letters a to z, hyphens, spaces and apostrophes.
Help improve this page
To help make sure that this page is useful, relevant and up to date, you can: