Use textarea to let users enter more than 1 line of text.
<div class="nhsuk-form-group">
<label class="nhsuk-label" for="example">
Can you provide more detail?
</label>
<div class="nhsuk-hint" id="example-hint">
Do not include personal or financial information, for example, your National Insurance number or credit card details.
</div>
<textarea class="nhsuk-textarea" id="example" name="example" rows="5" aria-describedby="example-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.
Name | Type | Required | Description |
---|---|---|---|
id | string | true | The id of the textarea. |
name | string | true | The name of the textarea, which is submitted with the form data. |
rows | string | false | Optional number of textarea rows (default is 5 rows). |
value | string | false | Optional initial value of the textarea. |
describedBy | string | false | One or more element IDs to add to the `aria-describedby` attribute, used to provide additional descriptive information for screenreader users. |
label | object | true | Options for the label component. |
hint | object | false | Options for the hint component. |
errorMessage | object | false | 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`. |
autocomplete | string | false | autocomplete attribute to identify input purpose, for instance "postal-code" or "username". |
classes | string | false | Classes to add to the textarea. |
attributes | object | false | HTML attributes (for example data attributes) to add to the textarea. |
{% from 'textarea/macro.njk' import textarea %}
{{ textarea({
name: "example",
id: "example",
label: {
text: "Can you provide more detail?"
},
hint: {
text: "Do not include personal or financial information, for example, your National Insurance number or credit card details."
}
}) }}
When to use textarea
Use textarea when you want users to enter an amount of text that’s longer than a single line.
When not to use textarea
Users can find open-ended questions difficult to answer. It's usually better to break up 1 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 textarea if you want users to enter single line answer, such as a phone number or name. In this case, you should use text input.
How to use textarea
Label textareas
You must label textareas.
Do not use placeholder text for a label, as it disappears when users click inside the textarea.
Align labels above the textarea they refer to. Labels should be short, direct and written in sentence case. Do not use colons at the end of labels.
Use the right size of textarea
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 specifying the rows
attribute.
<div class="nhsuk-form-group">
<label class="nhsuk-label" for="example-longer">
Can you provide more detail?
</label>
<div class="nhsuk-hint" id="example-longer-hint">
Do not include personal or financial information, for example, your National Insurance number or credit card details.
</div>
<textarea class="nhsuk-textarea" id="example-longer" name="example-longer" rows=" 10 " aria-describedby="example-longer-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.
Name | Type | Required | Description |
---|---|---|---|
id | string | true | The id of the textarea. |
name | string | true | The name of the textarea, which is submitted with the form data. |
rows | string | false | Optional number of textarea rows (default is 5 rows). |
value | string | false | Optional initial value of the textarea. |
describedBy | string | false | One or more element IDs to add to the `aria-describedby` attribute, used to provide additional descriptive information for screenreader users. |
label | object | true | Options for the label component. |
hint | object | false | Options for the hint component. |
errorMessage | object | false | 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`. |
autocomplete | string | false | autocomplete attribute to identify input purpose, for instance "postal-code" or "username". |
classes | string | false | Classes to add to the textarea. |
attributes | object | false | HTML attributes (for example data attributes) to add to the textarea. |
{% from 'textarea/macro.njk' import textarea %}
{{ textarea({
name: "example-longer",
id: "example-longer",
rows: "10",
label: {
text: "Can you provide more detail?"
},
hint: {
text: "Do not include personal or financial information, for example, your National Insurance number or credit card details."
}
}) }}
Using hint text
Use hint text to give users help in context, for example, tell users what information to include or not to include.
Do not disable copy and paste
Users will often need to copy and paste information into a textarea, so do not stop them doing this.
Error messages
Style error messages like this.
<div class="nhsuk-form-group nhsuk-form-group--error">
<label class="nhsuk-label" for="example-error">
Why can't you provide a National Insurance number?
</label>
<span class="nhsuk-error-message" id="example-error-error">
<span class="nhsuk-u-visually-hidden">Error:</span> You must provide an explanation.
</span>
<textarea class="nhsuk-textarea nhsuk-textarea--error" id="example-error" name="example-error" rows="5" aria-describedby="example-error-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.
Name | Type | Required | Description |
---|---|---|---|
id | string | true | The id of the textarea. |
name | string | true | The name of the textarea, which is submitted with the form data. |
rows | string | false | Optional number of textarea rows (default is 5 rows). |
value | string | false | Optional initial value of the textarea. |
describedBy | string | false | One or more element IDs to add to the `aria-describedby` attribute, used to provide additional descriptive information for screenreader users. |
label | object | true | Options for the label component. |
hint | object | false | Options for the hint component. |
errorMessage | object | false | 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`. |
autocomplete | string | false | autocomplete attribute to identify input purpose, for instance "postal-code" or "username". |
classes | string | false | Classes to add to the textarea. |
attributes | object | false | HTML attributes (for example data attributes) to add to the textarea. |
{% from 'textarea/macro.njk' import textarea %}
{{ textarea({
name: "example-error",
id: "example-error",
label: {
text: "Why can't you provide a National Insurance number?"
},
errorMessage: {
text: "You must provide an explanation."
}
}) }}
Follow:
Research
We tested the textarea component on a "Register with a GP" prototype at 2 labs in December 2018. Users understood the purpose of the textarea and were able to use it.
If you’ve used this component, get in touch to share your user research findings.
Help us improve this guidance
Share insights or feedback and take part in the discussion. We use GitHub as a collaboration space. All the information on it is open to the public.
Read more about how to feedback or share insights.
If you have any questions, get in touch with the service manual team.
Updated: January 2020