<divclass="govuk-form-group"><h1class="govuk-label-wrapper"><labelclass="govuk-label govuk-label--l"for="with-hint">
Can you provide more detail?
</label></h1><divid="with-hint-hint"class="govuk-hint">
Do not include personal or financial information like your National Insurance number or credit card details.
</div><textareaclass="govuk-textarea govuk-js-character-count"id="with-hint"name="with-hint"rows="5"aria-describedby="with-hint-info with-hint-hint"></textarea></div><divid="with-hint-info"class="govuk-hint govuk-character-count__message">
You can enter up to 200 characters
</div></div>
<p>
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
</p>
<p>
Some options are required for the macro to work; these are marked as "Required" in the option description.
</p>
<p>
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against <a href="https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting">cross-site scripting exploits</a>.
</p>
<table class="govuk-table app-options__table" id="options-character-count-example--primary">
<caption class="govuk-table__caption govuk-heading-m govuk-visually-hidden">Primary options</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The ID of the textarea.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">name</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The name of the textarea, which is submitted with the form data.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">rows</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional number of textarea rows (default is 5 rows).
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">value</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional initial value of the textarea.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">maxlength</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>maxwords</code> is set, this is not required. The maximum number of characters. If <code>maxwords</code> is provided, the <code>maxlength</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">maxwords</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>maxlength</code> is set, this is not required. The maximum number of words. If <code>maxwords</code> is provided, the <code>maxlength</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">threshold</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The percentage value of the limit at which point the count message is displayed. If this attribute is set, the count message will be hidden by default.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">label</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
Options for the label component.
See <a href="#options-character-count-example--label">label</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hint</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the hint component.
See <a href="#options-character-count-example--hint">hint</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">errorMessage</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the error message component. The error message component will not display if you use a falsy value for <code>errorMessage</code>, for example <code>false</code> or <code>null</code>.
See <a href="/components/error-message/#options-error-message-example">errorMessage</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">formGroup</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the form-group wrapper.
See <a href="#options-character-count-example--formGroup">formGroup</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the textarea.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the textarea.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">spellcheck</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Optional field to enable or disable the <code>spellcheck</code> attribute on the character count.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">countMessage</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the count message.
See <a href="#options-character-count-example--countMessage">countMessage</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">textareaDescriptionText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Message made available to assistive technologies to describe that the component accepts only a limited amount of content. It is visible on the page when JavaScript is unavailable. The component will replace the <code>%{count}</code> placeholder with the value of the <code>maxlength</code> or <code>maxwords</code> parameter.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">charactersUnderLimitText</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Message displayed when the number of characters is under the configured maximum, <code>maxlength</code>. This message is displayed visually and through assistive technologies. The component will replace the <code>%{count}</code> placeholder with the number of remaining characters. This is a <a href="https://frontend.design-system.service.gov.uk/localise-govuk-frontend">pluralised list of messages</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">charactersAtLimitText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Message displayed when the number of characters reaches the configured maximum, <code>maxlength</code>. This message is displayed visually and through assistive technologies.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">charactersUnderLimitText</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Message displayed when the number of characters is over the configured maximum, <code>maxlength</code>. This message is displayed visually and through assistive technologies. The component will replace the <code>%{count}</code> placeholder with the number of characters above the maximum. This is a <a href="https://frontend.design-system.service.gov.uk/localise-govuk-frontend">pluralised list of messages</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">wordsUnderLimitText</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Message displayed when the number of words is under the configured maximum, <code>maxwords</code>. This message is displayed visually and through assistive technologies. The component will replace the <code>%{count}</code> placeholder with the number of remaining words. This is a <a href="https://frontend.design-system.service.gov.uk/localise-govuk-frontend">pluralised list of messages</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">wordsAtLimitText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Message displayed when the number of words reaches the configured maximum, <code>maxwords</code>. This message is displayed visually and through assistive technologies.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">wordsUnderLimitText</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Message displayed when the number of words is over the configured maximum, <code>maxwords</code>. This message is displayed visually and through assistive technologies. The component will replace the <code>%{count}</code> placeholder with the number of characters above the maximum. This is a <a href="https://frontend.design-system.service.gov.uk/localise-govuk-frontend">pluralised list of messages</a>.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-character-count-example--formGroup">
<caption class="govuk-table__caption govuk-heading-m ">Options for formGroup</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the form group (for example to show error state for the whole group).
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-character-count-example--countMessage">
<caption class="govuk-table__caption govuk-heading-m ">Options for countMessage</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the count message.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-character-count-example--label">
<caption class="govuk-table__caption govuk-heading-m ">Options for label</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">text</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>html</code> is set, this is not required. Text to use within the label. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>text</code> is set, this is not required. HTML to use within the label. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">for</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The value of the <code>for</code> attribute, the ID of the input the label is associated with.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">isPageHeading</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Whether the label also acts as the heading for the page.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the label tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the label tag.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-character-count-example--hint">
<caption class="govuk-table__caption govuk-heading-m ">Options for hint</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">text</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>html</code> is set, this is not required. Text to use within the hint. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>text</code> is set, this is not required. HTML to use within the hint. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional ID attribute to add to the hint span tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the hint span tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the hint span tag.
</td>
</tr>
</tbody>
</table>
{{ govukCharacterCount({
name: "with-hint",
id: "with-hint",
maxlength: 200,
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
Always test your service without a character count first.
Only use the character count component when there is a good reason for limiting the number of characters users can enter. For example, if there is:
evidence that users are likely to enter more information than they need to
a legal or technical reason that means an entry must be no more than a certain number of characters
When not to use this component
If your users keep hitting the character limit imposed by the backend of your service then try to increase the limit rather than use a character count.
How it works
It tells users how many characters they have remaining as they type into a textarea with a character limit.
Users will get updates at a pace that works best for the way they interact with the textarea. This means:
sighted users will see a count message that updates as they type
screen reader users will hear the count announcement when they stop typing.
This component does not restrict the user from entering information. The user can enter more than the character limit, but are told they've entered too many characters. This lets them type or copy and paste their full answer, then edit it down.
The count message appears below the textarea so that:
it’s clearly separate from any hint text or error message above the textarea
if it’s below the visible screen area, users will still see it again when they scroll down to send their response
This component uses JavaScript. If JavaScript is not available, users will see a static message in place of the count message, telling them how many characters they can enter.
There are 2 ways to use the character count component. You can use HTML or, if you’re using Nunjucks or the GOV.UK Prototype Kit, you can use the Nunjucks macro.
<divclass="govuk-form-group"><h1class="govuk-label-wrapper"><labelclass="govuk-label govuk-label--l"for="with-hint">
Can you provide more detail?
</label></h1><divid="with-hint-hint"class="govuk-hint">
Do not include personal or financial information like your National Insurance number or credit card details.
</div><textareaclass="govuk-textarea govuk-js-character-count"id="with-hint"name="with-hint"rows="5"aria-describedby="with-hint-info with-hint-hint"></textarea></div><divid="with-hint-info"class="govuk-hint govuk-character-count__message">
You can enter up to 200 characters
</div></div>
<p>
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
</p>
<p>
Some options are required for the macro to work; these are marked as "Required" in the option description.
</p>
<p>
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against <a href="https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting">cross-site scripting exploits</a>.
</p>
<table class="govuk-table app-options__table" id="options-character-count-second-example--primary">
<caption class="govuk-table__caption govuk-heading-m govuk-visually-hidden">Primary options</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The ID of the textarea.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">name</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The name of the textarea, which is submitted with the form data.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">rows</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional number of textarea rows (default is 5 rows).
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">value</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional initial value of the textarea.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">maxlength</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>maxwords</code> is set, this is not required. The maximum number of characters. If <code>maxwords</code> is provided, the <code>maxlength</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">maxwords</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>maxlength</code> is set, this is not required. The maximum number of words. If <code>maxwords</code> is provided, the <code>maxlength</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">threshold</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The percentage value of the limit at which point the count message is displayed. If this attribute is set, the count message will be hidden by default.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">label</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
Options for the label component.
See <a href="#options-character-count-second-example--label">label</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hint</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the hint component.
See <a href="#options-character-count-second-example--hint">hint</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">errorMessage</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the error message component. The error message component will not display if you use a falsy value for <code>errorMessage</code>, for example <code>false</code> or <code>null</code>.
See <a href="/components/error-message/#options-error-message-example">errorMessage</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">formGroup</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the form-group wrapper.
See <a href="#options-character-count-second-example--formGroup">formGroup</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the textarea.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the textarea.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">spellcheck</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Optional field to enable or disable the <code>spellcheck</code> attribute on the character count.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">countMessage</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the count message.
See <a href="#options-character-count-second-example--countMessage">countMessage</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">textareaDescriptionText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Message made available to assistive technologies to describe that the component accepts only a limited amount of content. It is visible on the page when JavaScript is unavailable. The component will replace the <code>%{count}</code> placeholder with the value of the <code>maxlength</code> or <code>maxwords</code> parameter.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">charactersUnderLimitText</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Message displayed when the number of characters is under the configured maximum, <code>maxlength</code>. This message is displayed visually and through assistive technologies. The component will replace the <code>%{count}</code> placeholder with the number of remaining characters. This is a <a href="https://frontend.design-system.service.gov.uk/localise-govuk-frontend">pluralised list of messages</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">charactersAtLimitText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Message displayed when the number of characters reaches the configured maximum, <code>maxlength</code>. This message is displayed visually and through assistive technologies.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">charactersUnderLimitText</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Message displayed when the number of characters is over the configured maximum, <code>maxlength</code>. This message is displayed visually and through assistive technologies. The component will replace the <code>%{count}</code> placeholder with the number of characters above the maximum. This is a <a href="https://frontend.design-system.service.gov.uk/localise-govuk-frontend">pluralised list of messages</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">wordsUnderLimitText</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Message displayed when the number of words is under the configured maximum, <code>maxwords</code>. This message is displayed visually and through assistive technologies. The component will replace the <code>%{count}</code> placeholder with the number of remaining words. This is a <a href="https://frontend.design-system.service.gov.uk/localise-govuk-frontend">pluralised list of messages</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">wordsAtLimitText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Message displayed when the number of words reaches the configured maximum, <code>maxwords</code>. This message is displayed visually and through assistive technologies.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">wordsUnderLimitText</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Message displayed when the number of words is over the configured maximum, <code>maxwords</code>. This message is displayed visually and through assistive technologies. The component will replace the <code>%{count}</code> placeholder with the number of characters above the maximum. This is a <a href="https://frontend.design-system.service.gov.uk/localise-govuk-frontend">pluralised list of messages</a>.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-character-count-second-example--formGroup">
<caption class="govuk-table__caption govuk-heading-m ">Options for formGroup</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the form group (for example to show error state for the whole group).
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-character-count-second-example--countMessage">
<caption class="govuk-table__caption govuk-heading-m ">Options for countMessage</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the count message.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-character-count-second-example--label">
<caption class="govuk-table__caption govuk-heading-m ">Options for label</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">text</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>html</code> is set, this is not required. Text to use within the label. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>text</code> is set, this is not required. HTML to use within the label. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">for</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The value of the <code>for</code> attribute, the ID of the input the label is associated with.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">isPageHeading</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Whether the label also acts as the heading for the page.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the label tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the label tag.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-character-count-second-example--hint">
<caption class="govuk-table__caption govuk-heading-m ">Options for hint</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">text</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>html</code> is set, this is not required. Text to use within the hint. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>text</code> is set, this is not required. HTML to use within the hint. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional ID attribute to add to the hint span tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the hint span tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the hint span tag.
</td>
</tr>
</tbody>
</table>
{{ govukCharacterCount({
name: "with-hint",
id: "with-hint",
maxlength: 200,
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."
}
}) }}
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. Read more about asking multiple questions on question pages.
<div class="app-example app-example--tabs">
<div class="app-example__toolbar">
<a href="/components/character-count/without-heading/index.html" class="app-example__new-window" target="_blank">
Open this
<span class="govuk-visually-hidden">character count without a heading</span>
example in a new tab
</a>
</div>
<iframe title="Character count without a heading example" data-module="app-example-frame" class="app-example__frame app-example__frame--resizable" src="/components/character-count/without-heading/index.html" frameBorder="0" loading="lazy"></iframe>
</div>
<span id="options-character-count-without-a-heading-example"></span>
<ul class="app-tabs" role="tablist">
<li class="app-tabs__item js-tabs__item" role="presentation"><a href="#character-count-without-a-heading-example-html" role="tab" aria-controls="character-count-without-a-heading-example-html" data-track="tab-html">HTML</a></li>
<li class="app-tabs__item js-tabs__item" role="presentation"><a href="#character-count-without-a-heading-example-nunjucks" role="tab" aria-controls="character-count-without-a-heading-example-nunjucks" data-track="tab-nunjucks">Nunjucks</a></li>
</ul>
<div class="app-tabs__heading js-tabs__heading"><a href="#character-count-without-a-heading-example-html" aria-controls="character-count-without-a-heading-example-html" data-track="tab-html">HTML</a></div>
<div class="app-tabs__container js-tabs__container" id="character-count-without-a-heading-example-html" role="tabpanel">
<div class="app-example__code">
<pre data-module="app-copy" tabindex="0"><code class="hljs html"><span class="hljs-tag"><<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"govuk-character-count"</span> <span class="hljs-attr">data-module</span>=<span class="hljs-string">"govuk-character-count"</span> <span class="hljs-attr">data-maxlength</span>=<span class="hljs-string">"200"</span>></span>
<divclass="govuk-form-group"><labelclass="govuk-label"for="label-as-page-heading">
Describe the nature of your event
</label><textareaclass="govuk-textarea govuk-js-character-count"id="label-as-page-heading"name="label-as-page-heading"rows="5"aria-describedby="label-as-page-heading-info"></textarea></div><divid="label-as-page-heading-info"class="govuk-hint govuk-character-count__message">
You can enter up to 200 characters
</div></div>
<p>
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
</p>
<p>
Some options are required for the macro to work; these are marked as "Required" in the option description.
</p>
<p>
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against <a href="https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting">cross-site scripting exploits</a>.
</p>
<table class="govuk-table app-options__table" id="options-character-count-without-a-heading-example--primary">
<caption class="govuk-table__caption govuk-heading-m govuk-visually-hidden">Primary options</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The ID of the textarea.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">name</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The name of the textarea, which is submitted with the form data.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">rows</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional number of textarea rows (default is 5 rows).
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">value</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional initial value of the textarea.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">maxlength</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>maxwords</code> is set, this is not required. The maximum number of characters. If <code>maxwords</code> is provided, the <code>maxlength</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">maxwords</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>maxlength</code> is set, this is not required. The maximum number of words. If <code>maxwords</code> is provided, the <code>maxlength</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">threshold</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The percentage value of the limit at which point the count message is displayed. If this attribute is set, the count message will be hidden by default.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">label</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
Options for the label component.
See <a href="#options-character-count-without-a-heading-example--label">label</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hint</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the hint component.
See <a href="#options-character-count-without-a-heading-example--hint">hint</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">errorMessage</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the error message component. The error message component will not display if you use a falsy value for <code>errorMessage</code>, for example <code>false</code> or <code>null</code>.
See <a href="/components/error-message/#options-error-message-example">errorMessage</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">formGroup</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the form-group wrapper.
See <a href="#options-character-count-without-a-heading-example--formGroup">formGroup</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the textarea.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the textarea.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">spellcheck</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Optional field to enable or disable the <code>spellcheck</code> attribute on the character count.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">countMessage</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the count message.
See <a href="#options-character-count-without-a-heading-example--countMessage">countMessage</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">textareaDescriptionText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Message made available to assistive technologies to describe that the component accepts only a limited amount of content. It is visible on the page when JavaScript is unavailable. The component will replace the <code>%{count}</code> placeholder with the value of the <code>maxlength</code> or <code>maxwords</code> parameter.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">charactersUnderLimitText</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Message displayed when the number of characters is under the configured maximum, <code>maxlength</code>. This message is displayed visually and through assistive technologies. The component will replace the <code>%{count}</code> placeholder with the number of remaining characters. This is a <a href="https://frontend.design-system.service.gov.uk/localise-govuk-frontend">pluralised list of messages</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">charactersAtLimitText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Message displayed when the number of characters reaches the configured maximum, <code>maxlength</code>. This message is displayed visually and through assistive technologies.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">charactersUnderLimitText</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Message displayed when the number of characters is over the configured maximum, <code>maxlength</code>. This message is displayed visually and through assistive technologies. The component will replace the <code>%{count}</code> placeholder with the number of characters above the maximum. This is a <a href="https://frontend.design-system.service.gov.uk/localise-govuk-frontend">pluralised list of messages</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">wordsUnderLimitText</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Message displayed when the number of words is under the configured maximum, <code>maxwords</code>. This message is displayed visually and through assistive technologies. The component will replace the <code>%{count}</code> placeholder with the number of remaining words. This is a <a href="https://frontend.design-system.service.gov.uk/localise-govuk-frontend">pluralised list of messages</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">wordsAtLimitText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Message displayed when the number of words reaches the configured maximum, <code>maxwords</code>. This message is displayed visually and through assistive technologies.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">wordsUnderLimitText</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Message displayed when the number of words is over the configured maximum, <code>maxwords</code>. This message is displayed visually and through assistive technologies. The component will replace the <code>%{count}</code> placeholder with the number of characters above the maximum. This is a <a href="https://frontend.design-system.service.gov.uk/localise-govuk-frontend">pluralised list of messages</a>.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-character-count-without-a-heading-example--formGroup">
<caption class="govuk-table__caption govuk-heading-m ">Options for formGroup</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the form group (for example to show error state for the whole group).
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-character-count-without-a-heading-example--countMessage">
<caption class="govuk-table__caption govuk-heading-m ">Options for countMessage</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the count message.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-character-count-without-a-heading-example--label">
<caption class="govuk-table__caption govuk-heading-m ">Options for label</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">text</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>html</code> is set, this is not required. Text to use within the label. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>text</code> is set, this is not required. HTML to use within the label. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">for</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The value of the <code>for</code> attribute, the ID of the input the label is associated with.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">isPageHeading</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Whether the label also acts as the heading for the page.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the label tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the label tag.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-character-count-without-a-heading-example--hint">
<caption class="govuk-table__caption govuk-heading-m ">Options for hint</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">text</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>html</code> is set, this is not required. Text to use within the hint. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>text</code> is set, this is not required. HTML to use within the hint. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional ID attribute to add to the hint span tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the hint span tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the hint span tag.
</td>
</tr>
</tbody>
</table>
<divclass="govuk-form-group"><h1class="govuk-label-wrapper"><labelclass="govuk-label govuk-label--l"for="word-count">
Enter a job description
</label></h1><textareaclass="govuk-textarea govuk-js-character-count"id="word-count"name="word-count"rows="5"aria-describedby="word-count-info"></textarea></div><divid="word-count-info"class="govuk-hint govuk-character-count__message">
You can enter up to 150 words
</div></div>
<p>
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
</p>
<p>
Some options are required for the macro to work; these are marked as "Required" in the option description.
</p>
<p>
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against <a href="https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting">cross-site scripting exploits</a>.
</p>
<table class="govuk-table app-options__table" id="options-word-count-character-count-example--primary">
<caption class="govuk-table__caption govuk-heading-m govuk-visually-hidden">Primary options</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The ID of the textarea.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">name</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The name of the textarea, which is submitted with the form data.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">rows</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional number of textarea rows (default is 5 rows).
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">value</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional initial value of the textarea.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">maxlength</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>maxwords</code> is set, this is not required. The maximum number of characters. If <code>maxwords</code> is provided, the <code>maxlength</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">maxwords</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>maxlength</code> is set, this is not required. The maximum number of words. If <code>maxwords</code> is provided, the <code>maxlength</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">threshold</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The percentage value of the limit at which point the count message is displayed. If this attribute is set, the count message will be hidden by default.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">label</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
Options for the label component.
See <a href="#options-word-count-character-count-example--label">label</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hint</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the hint component.
See <a href="#options-word-count-character-count-example--hint">hint</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">errorMessage</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the error message component. The error message component will not display if you use a falsy value for <code>errorMessage</code>, for example <code>false</code> or <code>null</code>.
See <a href="/components/error-message/#options-error-message-example">errorMessage</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">formGroup</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the form-group wrapper.
See <a href="#options-word-count-character-count-example--formGroup">formGroup</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the textarea.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the textarea.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">spellcheck</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Optional field to enable or disable the <code>spellcheck</code> attribute on the character count.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">countMessage</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the count message.
See <a href="#options-word-count-character-count-example--countMessage">countMessage</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">textareaDescriptionText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Message made available to assistive technologies to describe that the component accepts only a limited amount of content. It is visible on the page when JavaScript is unavailable. The component will replace the <code>%{count}</code> placeholder with the value of the <code>maxlength</code> or <code>maxwords</code> parameter.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">charactersUnderLimitText</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Message displayed when the number of characters is under the configured maximum, <code>maxlength</code>. This message is displayed visually and through assistive technologies. The component will replace the <code>%{count}</code> placeholder with the number of remaining characters. This is a <a href="https://frontend.design-system.service.gov.uk/localise-govuk-frontend">pluralised list of messages</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">charactersAtLimitText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Message displayed when the number of characters reaches the configured maximum, <code>maxlength</code>. This message is displayed visually and through assistive technologies.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">charactersUnderLimitText</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Message displayed when the number of characters is over the configured maximum, <code>maxlength</code>. This message is displayed visually and through assistive technologies. The component will replace the <code>%{count}</code> placeholder with the number of characters above the maximum. This is a <a href="https://frontend.design-system.service.gov.uk/localise-govuk-frontend">pluralised list of messages</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">wordsUnderLimitText</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Message displayed when the number of words is under the configured maximum, <code>maxwords</code>. This message is displayed visually and through assistive technologies. The component will replace the <code>%{count}</code> placeholder with the number of remaining words. This is a <a href="https://frontend.design-system.service.gov.uk/localise-govuk-frontend">pluralised list of messages</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">wordsAtLimitText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Message displayed when the number of words reaches the configured maximum, <code>maxwords</code>. This message is displayed visually and through assistive technologies.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">wordsUnderLimitText</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Message displayed when the number of words is over the configured maximum, <code>maxwords</code>. This message is displayed visually and through assistive technologies. The component will replace the <code>%{count}</code> placeholder with the number of characters above the maximum. This is a <a href="https://frontend.design-system.service.gov.uk/localise-govuk-frontend">pluralised list of messages</a>.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-word-count-character-count-example--formGroup">
<caption class="govuk-table__caption govuk-heading-m ">Options for formGroup</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the form group (for example to show error state for the whole group).
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-word-count-character-count-example--countMessage">
<caption class="govuk-table__caption govuk-heading-m ">Options for countMessage</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the count message.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-word-count-character-count-example--label">
<caption class="govuk-table__caption govuk-heading-m ">Options for label</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">text</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>html</code> is set, this is not required. Text to use within the label. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>text</code> is set, this is not required. HTML to use within the label. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">for</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The value of the <code>for</code> attribute, the ID of the input the label is associated with.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">isPageHeading</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Whether the label also acts as the heading for the page.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the label tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the label tag.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-word-count-character-count-example--hint">
<caption class="govuk-table__caption govuk-heading-m ">Options for hint</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">text</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>html</code> is set, this is not required. Text to use within the hint. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>text</code> is set, this is not required. HTML to use within the hint. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional ID attribute to add to the hint span tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the hint span tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the hint span tag.
</td>
</tr>
</tbody>
</table>
When using a character count, try to set the limit higher than most users will need. Find out what this is by doing user research and data analysis.
If the limit is much higher than most users are likely to reach, you can choose to only display the message after a user has entered a certain amount.
To do this, set a threshold in the component markup. For example, data-threshold="75" will show the count message only when users have entered 75% of the limit.
Screen reader users will hear the character limit when they first interact with a textarea using the threshold option. Sighted users will not see anything until the count message is shown — though you might choose to include the character limit in the hint text.
<divclass="govuk-form-group"><h1class="govuk-label-wrapper"><labelclass="govuk-label govuk-label--l"for="threshold">
Can you provide more detail?
</label></h1><textareaclass="govuk-textarea govuk-js-character-count"id="threshold"name="threshold"rows="5"aria-describedby="threshold-info">Type another letter into this field after this message to see the threshold feature</textarea></div><divid="threshold-info"class="govuk-hint govuk-character-count__message">
You can enter up to 112 characters
</div></div>
<p>
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
</p>
<p>
Some options are required for the macro to work; these are marked as "Required" in the option description.
</p>
<p>
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against <a href="https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting">cross-site scripting exploits</a>.
</p>
<table class="govuk-table app-options__table" id="options-threshold-character-count-example--primary">
<caption class="govuk-table__caption govuk-heading-m govuk-visually-hidden">Primary options</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The ID of the textarea.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">name</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The name of the textarea, which is submitted with the form data.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">rows</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional number of textarea rows (default is 5 rows).
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">value</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional initial value of the textarea.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">maxlength</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>maxwords</code> is set, this is not required. The maximum number of characters. If <code>maxwords</code> is provided, the <code>maxlength</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">maxwords</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>maxlength</code> is set, this is not required. The maximum number of words. If <code>maxwords</code> is provided, the <code>maxlength</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">threshold</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The percentage value of the limit at which point the count message is displayed. If this attribute is set, the count message will be hidden by default.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">label</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
Options for the label component.
See <a href="#options-threshold-character-count-example--label">label</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hint</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the hint component.
See <a href="#options-threshold-character-count-example--hint">hint</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">errorMessage</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the error message component. The error message component will not display if you use a falsy value for <code>errorMessage</code>, for example <code>false</code> or <code>null</code>.
See <a href="/components/error-message/#options-error-message-example">errorMessage</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">formGroup</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the form-group wrapper.
See <a href="#options-threshold-character-count-example--formGroup">formGroup</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the textarea.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the textarea.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">spellcheck</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Optional field to enable or disable the <code>spellcheck</code> attribute on the character count.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">countMessage</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the count message.
See <a href="#options-threshold-character-count-example--countMessage">countMessage</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">textareaDescriptionText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Message made available to assistive technologies to describe that the component accepts only a limited amount of content. It is visible on the page when JavaScript is unavailable. The component will replace the <code>%{count}</code> placeholder with the value of the <code>maxlength</code> or <code>maxwords</code> parameter.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">charactersUnderLimitText</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Message displayed when the number of characters is under the configured maximum, <code>maxlength</code>. This message is displayed visually and through assistive technologies. The component will replace the <code>%{count}</code> placeholder with the number of remaining characters. This is a <a href="https://frontend.design-system.service.gov.uk/localise-govuk-frontend">pluralised list of messages</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">charactersAtLimitText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Message displayed when the number of characters reaches the configured maximum, <code>maxlength</code>. This message is displayed visually and through assistive technologies.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">charactersUnderLimitText</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Message displayed when the number of characters is over the configured maximum, <code>maxlength</code>. This message is displayed visually and through assistive technologies. The component will replace the <code>%{count}</code> placeholder with the number of characters above the maximum. This is a <a href="https://frontend.design-system.service.gov.uk/localise-govuk-frontend">pluralised list of messages</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">wordsUnderLimitText</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Message displayed when the number of words is under the configured maximum, <code>maxwords</code>. This message is displayed visually and through assistive technologies. The component will replace the <code>%{count}</code> placeholder with the number of remaining words. This is a <a href="https://frontend.design-system.service.gov.uk/localise-govuk-frontend">pluralised list of messages</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">wordsAtLimitText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Message displayed when the number of words reaches the configured maximum, <code>maxwords</code>. This message is displayed visually and through assistive technologies.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">wordsUnderLimitText</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Message displayed when the number of words is over the configured maximum, <code>maxwords</code>. This message is displayed visually and through assistive technologies. The component will replace the <code>%{count}</code> placeholder with the number of characters above the maximum. This is a <a href="https://frontend.design-system.service.gov.uk/localise-govuk-frontend">pluralised list of messages</a>.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-threshold-character-count-example--formGroup">
<caption class="govuk-table__caption govuk-heading-m ">Options for formGroup</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the form group (for example to show error state for the whole group).
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-threshold-character-count-example--countMessage">
<caption class="govuk-table__caption govuk-heading-m ">Options for countMessage</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the count message.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-threshold-character-count-example--label">
<caption class="govuk-table__caption govuk-heading-m ">Options for label</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">text</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>html</code> is set, this is not required. Text to use within the label. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>text</code> is set, this is not required. HTML to use within the label. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">for</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The value of the <code>for</code> attribute, the ID of the input the label is associated with.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">isPageHeading</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Whether the label also acts as the heading for the page.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the label tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the label tag.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-threshold-character-count-example--hint">
<caption class="govuk-table__caption govuk-heading-m ">Options for hint</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">text</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>html</code> is set, this is not required. Text to use within the hint. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>text</code> is set, this is not required. HTML to use within the hint. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional ID attribute to add to the hint span tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the hint span tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the hint span tag.
</td>
</tr>
</tbody>
</table>
{{ govukCharacterCount({
name: "threshold",
id: "threshold",
maxlength: 112,
threshold: 75,
value: "Type another letter into this field after this message to see the threshold feature",
label: {
text: "Can you provide more detail?",
classes: "govuk-label--l",
isPageHeading: true
}
}) }}
<divclass="govuk-form-group govuk-form-group--error"><h1class="govuk-label-wrapper"><labelclass="govuk-label govuk-label--l"for="exceeding-characters">
Enter a job description
</label></h1><pid="exceeding-characters-error"class="govuk-error-message"><spanclass="govuk-visually-hidden">Error:</span> Job description must be 350 characters or less
</p><textareaclass="govuk-textarea govuk-textarea--error govuk-js-character-count"id="exceeding-characters"name="exceeding"rows="5"aria-describedby="exceeding-characters-info exceeding-characters-error">A content designer works on the end-to-end journey of a service to help users complete their goal and government deliver a policy intent. Their work may involve the creation of, or change to, a transaction, product or single piece of content that stretches across digital and offline channels. They make sure appropriate content is shown to a user in the right place and in the best format.</textarea></div><divid="exceeding-characters-info"class="govuk-hint govuk-character-count__message">
You can enter up to 350 characters
</div></div>
<p>
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
</p>
<p>
Some options are required for the macro to work; these are marked as "Required" in the option description.
</p>
<p>
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against <a href="https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting">cross-site scripting exploits</a>.
</p>
<table class="govuk-table app-options__table" id="options-error-character-count-example--primary">
<caption class="govuk-table__caption govuk-heading-m govuk-visually-hidden">Primary options</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The ID of the textarea.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">name</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The name of the textarea, which is submitted with the form data.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">rows</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional number of textarea rows (default is 5 rows).
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">value</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional initial value of the textarea.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">maxlength</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>maxwords</code> is set, this is not required. The maximum number of characters. If <code>maxwords</code> is provided, the <code>maxlength</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">maxwords</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>maxlength</code> is set, this is not required. The maximum number of words. If <code>maxwords</code> is provided, the <code>maxlength</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">threshold</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The percentage value of the limit at which point the count message is displayed. If this attribute is set, the count message will be hidden by default.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">label</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
Options for the label component.
See <a href="#options-error-character-count-example--label">label</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hint</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the hint component.
See <a href="#options-error-character-count-example--hint">hint</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">errorMessage</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the error message component. The error message component will not display if you use a falsy value for <code>errorMessage</code>, for example <code>false</code> or <code>null</code>.
See <a href="/components/error-message/#options-error-message-example">errorMessage</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">formGroup</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the form-group wrapper.
See <a href="#options-error-character-count-example--formGroup">formGroup</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the textarea.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the textarea.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">spellcheck</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Optional field to enable or disable the <code>spellcheck</code> attribute on the character count.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">countMessage</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the count message.
See <a href="#options-error-character-count-example--countMessage">countMessage</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">textareaDescriptionText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Message made available to assistive technologies to describe that the component accepts only a limited amount of content. It is visible on the page when JavaScript is unavailable. The component will replace the <code>%{count}</code> placeholder with the value of the <code>maxlength</code> or <code>maxwords</code> parameter.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">charactersUnderLimitText</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Message displayed when the number of characters is under the configured maximum, <code>maxlength</code>. This message is displayed visually and through assistive technologies. The component will replace the <code>%{count}</code> placeholder with the number of remaining characters. This is a <a href="https://frontend.design-system.service.gov.uk/localise-govuk-frontend">pluralised list of messages</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">charactersAtLimitText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Message displayed when the number of characters reaches the configured maximum, <code>maxlength</code>. This message is displayed visually and through assistive technologies.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">charactersUnderLimitText</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Message displayed when the number of characters is over the configured maximum, <code>maxlength</code>. This message is displayed visually and through assistive technologies. The component will replace the <code>%{count}</code> placeholder with the number of characters above the maximum. This is a <a href="https://frontend.design-system.service.gov.uk/localise-govuk-frontend">pluralised list of messages</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">wordsUnderLimitText</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Message displayed when the number of words is under the configured maximum, <code>maxwords</code>. This message is displayed visually and through assistive technologies. The component will replace the <code>%{count}</code> placeholder with the number of remaining words. This is a <a href="https://frontend.design-system.service.gov.uk/localise-govuk-frontend">pluralised list of messages</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">wordsAtLimitText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Message displayed when the number of words reaches the configured maximum, <code>maxwords</code>. This message is displayed visually and through assistive technologies.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">wordsUnderLimitText</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Message displayed when the number of words is over the configured maximum, <code>maxwords</code>. This message is displayed visually and through assistive technologies. The component will replace the <code>%{count}</code> placeholder with the number of characters above the maximum. This is a <a href="https://frontend.design-system.service.gov.uk/localise-govuk-frontend">pluralised list of messages</a>.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-error-character-count-example--formGroup">
<caption class="govuk-table__caption govuk-heading-m ">Options for formGroup</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the form group (for example to show error state for the whole group).
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-error-character-count-example--countMessage">
<caption class="govuk-table__caption govuk-heading-m ">Options for countMessage</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the count message.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-error-character-count-example--label">
<caption class="govuk-table__caption govuk-heading-m ">Options for label</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">text</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>html</code> is set, this is not required. Text to use within the label. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>text</code> is set, this is not required. HTML to use within the label. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">for</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The value of the <code>for</code> attribute, the ID of the input the label is associated with.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">isPageHeading</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Whether the label also acts as the heading for the page.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the label tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the label tag.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-error-character-count-example--hint">
<caption class="govuk-table__caption govuk-heading-m ">Options for hint</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">text</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>html</code> is set, this is not required. Text to use within the hint. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>text</code> is set, this is not required. HTML to use within the hint. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional ID attribute to add to the hint span tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the hint span tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the hint span tag.
</td>
</tr>
</tbody>
</table>
{{ govukCharacterCount({
id: "exceeding-characters",
name: "exceeding",
maxlength: 350,
value: "A content designer works on the end-to-end journey of a service to help users complete their goal and government deliver a policy intent. Their work may involve the creation of, or change to, a transaction, product or single piece of content that stretches across digital and offline channels. They make sure appropriate content is shown to a user in the right place and in the best format.",
label: {
text: "Enter a job description",
classes: "govuk-label--l",
isPageHeading: true
},
errorMessage: {
text: "Job description must be 350 characters or less"
}
}) }}
If a user tries to send their response with too many characters, you must show an error message above the field as well as the count message below it.
The error message tells users what went wrong and how to fix it. The count message provides live feedback and updates as a user types.
The input shows a red border only when the user tries to enter more than the character limit. If the number of characters is within the limit, the input does not show this border even when there's been an error. We felt it might cause the user difficulty if the border disappeared once they started typing.
Make sure errors follow GOV.UK guidance on writing error messages and have specific error messages for specific error states.
If the input is empty
Say ‘Enter [whatever it is]’.
For example, ‘Enter a summary’.
If the input is too long
Say ‘[whatever it is] must be [number] characters or less’.
For example, ‘Summary must be 400 characters or less’.
Research on this component
The Government Digital Service (GDS) developed and tested this component in a prototype of the ‘Apply for a temporary event notice’ service.
During this research, the component was tested with 17 users, including those with low digital skills and users with disabilities.