Textarea
Use the textarea component when you need to let users enter an amount of text that’s longer than a single line.
When to use this component
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 a Radios component.
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 Input (text) component.
How it works
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.
There are 2 ways to use the textarea component. You can use HTML or, if you are using Nunjucks, you can use the Nunjucks macro.
Get the Nunjucks macro for this example from the Camden Frontend library
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 specifying the rows attribute.
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.
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.
Get the Nunjucks macro for this example from the Camden Frontend library
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:
Get the Nunjucks macro for this example from the Camden Frontend library
Make sure errors follow the guidance in the Error message component 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 less’.
For example, ‘Summary must be 400 characters or less’.
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.
Research on this component
This component is based on the textarea component from the GOV.UK Design System.
You can take part in the ‘Textarea' discussion on GOV.UK’s Design System’s GitHub and share your research.