Components

Textarea

Use the textarea component when you need to let users enter an amount of text that’s longer than a single line.

This will be shown on the public page for the event, below the event title
<div class="govuk-form-group">
<h1 class="govuk-label-wrapper">
<label class="govuk-label govuk-label--l" for="event-description">
What is the event about?
</label>
</h1>
<div id="event-description-hint" class="govuk-hint">
This will be shown on the public page for the event, below the event title
</div>
<textarea
class="govuk-textarea"
id="event-description"
name="event-description"
rows="5"
aria-describedby="event-description-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
Name Type Description
id string Required.

The ID of the textarea.

name string Required.

The name of the textarea, which is submitted with the form data.

spellcheck boolean

Optional field to enable or disable the spellcheck attribute on the textarea.

rows string

Optional number of textarea rows (default is 5 rows).

value string

Optional initial value of the textarea.

disabled boolean

If true, textarea will be disabled.

describedBy string

One or more element IDs to add to the aria-describedby attribute, used to provide additional descriptive information for screenreader users.

label object Required.

The label used by the textarea component.

See label.

hint object

Can be used to add a hint to the textarea component.

See hint.

errorMessage object

Can be used to add an error message to the textarea component. The error message component will not display if you use a falsy value for errorMessage, for example false or null.

See error message.

formGroup object

Additional options for the form group containing the textarea component.

See formGroup.

classes string

Classes to add to the textarea.

autocomplete string

Attribute to identify input purpose, for example "street-address". See autofill for full list of attributes that can be used.

attributes object

HTML attributes (for example data attributes) to add to the textarea.

Options for formGroup
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 textarea used by the textarea component.

See beforeInput.

afterInput object

Content to add after the textarea used by the textarea component.

See afterInput.

Options for afterInput
Name Type Description
text string Required.

Text to add after the textarea. If html is provided, the text option will be ignored.

html string Required.

HTML to add after the textarea. If html is provided, the text option will be ignored.

Options for beforeInput
Name Type Description
text string Required.

Text to add before the textarea. If html is provided, the text option will be ignored.

html string Required.

HTML to add before the textarea. If html is provided, the text option will be ignored.

Options for hint
Name Type Description
text 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.

html 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.

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.

Options for label
Name Type Description
text 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.

html 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.

for string

The value of the for attribute, the ID of the input the label is associated with.

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.

{% from "moduk/components/textarea/macro.njk" import modukTextarea -%}

{{ modukTextarea({
name: "event-description",
id: "event-description",
label: {
text: "What is the event about?",
classes: "govuk-label--l",
isPageHeading: true
},
hint: {
text: "This will be shown on the public page for the event, below the event title"
}
}) -}}

See GOV.UK textarea component guidance for:

  • when to use this component
  • when not to use it

How it works

See GOV.UK textarea 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.

This will be shown on the public page for the event, below the event title
<div class="govuk-form-group">
<h1 class="govuk-label-wrapper">
<label
class="govuk-label govuk-label--l"
for="event-description-with-page-heading"
>

What is the event about?
</label>
</h1>
<div id="event-description-with-page-heading-hint" class="govuk-hint">
This will be shown on the public page for the event, below the event title
</div>
<textarea
class="govuk-textarea"
id="event-description-with-page-heading"
name="event-description-with-page-heading"
rows="5"
aria-describedby="event-description-with-page-heading-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
Name Type Description
id string Required.

The ID of the textarea.

name string Required.

The name of the textarea, which is submitted with the form data.

spellcheck boolean

Optional field to enable or disable the spellcheck attribute on the textarea.

rows string

Optional number of textarea rows (default is 5 rows).

value string

Optional initial value of the textarea.

disabled boolean

If true, textarea will be disabled.

describedBy string

One or more element IDs to add to the aria-describedby attribute, used to provide additional descriptive information for screenreader users.

label object Required.

The label used by the textarea component.

See label.

hint object

Can be used to add a hint to the textarea component.

See hint.

errorMessage object

Can be used to add an error message to the textarea component. The error message component will not display if you use a falsy value for errorMessage, for example false or null.

See error message.

formGroup object

Additional options for the form group containing the textarea component.

See formGroup.

classes string

Classes to add to the textarea.

autocomplete string

Attribute to identify input purpose, for example "street-address". See autofill for full list of attributes that can be used.

attributes object

HTML attributes (for example data attributes) to add to the textarea.

Options for formGroup
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 textarea used by the textarea component.

See beforeInput.

afterInput object

Content to add after the textarea used by the textarea component.

See afterInput.

Options for afterInput
Name Type Description
text string Required.

Text to add after the textarea. If html is provided, the text option will be ignored.

html string Required.

HTML to add after the textarea. If html is provided, the text option will be ignored.

Options for beforeInput
Name Type Description
text string Required.

Text to add before the textarea. If html is provided, the text option will be ignored.

html string Required.

HTML to add before the textarea. If html is provided, the text option will be ignored.

Options for hint
Name Type Description
text 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.

html 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.

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.

Options for label
Name Type Description
text 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.

html 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.

for string

The value of the for attribute, the ID of the input the label is associated with.

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.

{% from "moduk/components/textarea/macro.njk" import modukTextarea %}

{{ modukTextarea({
name: "event-description-with-page-heading",
id: "event-description-with-page-heading",
label: {
text: "What is the event about?",
classes: "govuk-label--l",
isPageHeading: true
},
hint: {
text: "This will be shown on the public page for the event, below the event title"
}
}) }}

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="event-description-not-as-page-heading">
What is the event about?
</label>
<textarea
class="govuk-textarea"
id="event-description-not-as-page-heading"
name="event-description-not-as-page-heading"
rows="5"
>
</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
Name Type Description
id string Required.

The ID of the textarea.

name string Required.

The name of the textarea, which is submitted with the form data.

spellcheck boolean

Optional field to enable or disable the spellcheck attribute on the textarea.

rows string

Optional number of textarea rows (default is 5 rows).

value string

Optional initial value of the textarea.

disabled boolean

If true, textarea will be disabled.

describedBy string

One or more element IDs to add to the aria-describedby attribute, used to provide additional descriptive information for screenreader users.

label object Required.

The label used by the textarea component.

See label.

hint object

Can be used to add a hint to the textarea component.

See hint.

errorMessage object

Can be used to add an error message to the textarea component. The error message component will not display if you use a falsy value for errorMessage, for example false or null.

See error message.

formGroup object

Additional options for the form group containing the textarea component.

See formGroup.

classes string

Classes to add to the textarea.

autocomplete string

Attribute to identify input purpose, for example "street-address". See autofill for full list of attributes that can be used.

attributes object

HTML attributes (for example data attributes) to add to the textarea.

Options for formGroup
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 textarea used by the textarea component.

See beforeInput.

afterInput object

Content to add after the textarea used by the textarea component.

See afterInput.

Options for afterInput
Name Type Description
text string Required.

Text to add after the textarea. If html is provided, the text option will be ignored.

html string Required.

HTML to add after the textarea. If html is provided, the text option will be ignored.

Options for beforeInput
Name Type Description
text string Required.

Text to add before the textarea. If html is provided, the text option will be ignored.

html string Required.

HTML to add before the textarea. If html is provided, the text option will be ignored.

Options for hint
Name Type Description
text 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.

html 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.

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.

Options for label
Name Type Description
text 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.

html 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.

for string

The value of the for attribute, the ID of the input the label is associated with.

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.

{% from "moduk/components/textarea/macro.njk" import modukTextarea -%}

{{ modukTextarea({
name: "event-description-not-as-page-heading",
id: "event-description-not-as-page-heading",
label: {
text: "What is the event about?"
}
}) -}}

Error messages

Error messages should be styled like this:

This will be shown on the public page for the event, below the event title

Error: Enter some details about the event

<div class="govuk-form-group govuk-form-group--error">
<h1 class="govuk-label-wrapper">
<label
class="govuk-label govuk-label--l"
for="event-description-with-error"
>

What is the event about?
</label>
</h1>
<div id="event-description-with-error-hint" class="govuk-hint">
This will be shown on the public page for the event, below the event title
</div>
<p id="event-description-with-error-error" class="govuk-error-message">
<span class="govuk-visually-hidden">Error:</span> Enter some details about
the event
</p>
<textarea
class="govuk-textarea govuk-textarea--error"
id="event-description-with-error"
name="event-description-with-error"
rows="5"
aria-describedby="event-description-with-error-hint event-description-with-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.

Primary options
Name Type Description
id string Required.

The ID of the textarea.

name string Required.

The name of the textarea, which is submitted with the form data.

spellcheck boolean

Optional field to enable or disable the spellcheck attribute on the textarea.

rows string

Optional number of textarea rows (default is 5 rows).

value string

Optional initial value of the textarea.

disabled boolean

If true, textarea will be disabled.

describedBy string

One or more element IDs to add to the aria-describedby attribute, used to provide additional descriptive information for screenreader users.

label object Required.

The label used by the textarea component.

See label.

hint object

Can be used to add a hint to the textarea component.

See hint.

errorMessage object

Can be used to add an error message to the textarea component. The error message component will not display if you use a falsy value for errorMessage, for example false or null.

See error message.

formGroup object

Additional options for the form group containing the textarea component.

See formGroup.

classes string

Classes to add to the textarea.

autocomplete string

Attribute to identify input purpose, for example "street-address". See autofill for full list of attributes that can be used.

attributes object

HTML attributes (for example data attributes) to add to the textarea.

Options for formGroup
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 textarea used by the textarea component.

See beforeInput.

afterInput object

Content to add after the textarea used by the textarea component.

See afterInput.

Options for afterInput
Name Type Description
text string Required.

Text to add after the textarea. If html is provided, the text option will be ignored.

html string Required.

HTML to add after the textarea. If html is provided, the text option will be ignored.

Options for beforeInput
Name Type Description
text string Required.

Text to add before the textarea. If html is provided, the text option will be ignored.

html string Required.

HTML to add before the textarea. If html is provided, the text option will be ignored.

Options for hint
Name Type Description
text 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.

html 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.

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.

Options for label
Name Type Description
text 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.

html 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.

for string

The value of the for attribute, the ID of the input the label is associated with.

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.

{% from "moduk/components/textarea/macro.njk" import modukTextarea -%}

{{ modukTextarea({
name: "event-description-with-error",
id: "event-description-with-error",
label: {
text: "What is the event about?",
classes: "govuk-label--l",
isPageHeading: true
},
hint: {
text: "This will be shown on the public page for the event, below the event title"
},
errorMessage: {
text: "Enter some details about the event"
}
}) -}}

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.