---
url: "https://design-system.service.gov.uk/components/character-count/"
titulek: "Character count – GOV.UK Design System"
h1: "Character count"
popis: "Tell users how many characters or words they can enter into a textarea"
jazyk: "en"
kanonicka: "https://design-system.service.gov.uk/components/character-count/"
drobecky: ["Home", "Components"]
zdroj: "live"
wayback_snapshot: ""
stazeno: "2026-09-14 01:21:28"
znaku: 56048
slov: 8365
kodovani: "utf-8"
sha256: "ab939fbc08ec8cd10cb4e296cb68a127f8f80da81f3855803807376a9be3a59d"
---
# Character count
Help users know how much text they can enter when there is a limit on the number of characters.
- HTML
- Nunjucks
HTML
```
Do not include personal or financial information like your National Insurance number or credit card details
You can enter up to 200 characters
```
Nunjucks
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work; these are marked as “Required” in the option description. Deprecated options are marked as “Deprecated”.
If you’re using Nunjucks macros in production with “html” options, or ones ending with “html”, you must sanitise the HTML to protect against [cross-site scripting exploits](https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting).
Primary options string
The ID of the textarea. Defaults to the value of `name`.
string **Required.**
The name of the textarea, which is submitted with the form data.
string
Optional number of textarea rows (default is 5 rows).
string
Optional initial value of the textarea.
string **Required.**
If `maxwords` is set, this is not required. The maximum number of characters. If `maxwords` is provided, the `maxlength` option will be ignored.
string **Required.**
If `maxlength` is set, this is not required. The maximum number of words. If `maxwords` is provided, the `maxlength` option will be ignored.
string
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.
object **Required.**
The label used by the character count component.
See macro options for label.
object
Can be used to add a hint to the character count component.
See macro options for hint.
object
Can be used to add an error message to the character count component. The error message component will not display if you use a falsy value for `errorMessage`, for example `false` or `null`.
[See macro options for errorMessage](/components/error-message/#options-error-message-example).
object
Additional options for the form group containing the character count component.
See macro options for formGroup.
string
Classes to add to the textarea.
object
HTML attributes (for example data attributes) to add to the textarea.
boolean
Optional field to enable or disable the `spellcheck` attribute on the character count.
object
Additional options for the count message used by the character count component.
See macro options for countMessage.
string
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 `%{count}` placeholder with the value of the `maxlength` or `maxwords` parameter.
object
Message displayed when the number of characters is under the configured maximum, `maxlength`. This message is displayed visually and through assistive technologies. The component will replace the `%{count}` placeholder with the number of remaining characters. [Our pluralisation rules apply to this macro option](https://frontend.design-system.service.gov.uk/localise-govuk-frontend/#understanding-pluralisation-rules).
string
Message displayed when the number of characters reaches the configured maximum, `maxlength`. This message is displayed visually and through assistive technologies.
object
Message displayed when the number of characters is over the configured maximum, `maxlength`. This message is displayed visually and through assistive technologies. The component will replace the `%{count}` placeholder with the number of characters above the maximum.[Our pluralisation rules apply to this macro option](https://frontend.design-system.service.gov.uk/localise-govuk-frontend/#understanding-pluralisation-rules).
object
Message displayed when the number of words is under the configured maximum, `maxwords`. This message is displayed visually and through assistive technologies. The component will replace the `%{count}` placeholder with the number of remaining words. [Our pluralisation rules apply to this macro option](https://frontend.design-system.service.gov.uk/localise-govuk-frontend/#understanding-pluralisation-rules).
string
Message displayed when the number of words reaches the configured maximum, `maxwords`. This message is displayed visually and through assistive technologies.
object
Message displayed when the number of words is over the configured maximum, `maxwords`. This message is displayed visually and through assistive technologies. The component will replace the `%{count}` placeholder with the number of characters above the maximum. [Our pluralisation rules apply to this macro option](https://frontend.design-system.service.gov.uk/localise-govuk-frontend/#understanding-pluralisation-rules).
Options for `formGroup` object string
Classes to add to the form group (for example to show error state for the whole group).
object
HTML attributes (for example data attributes) to add to the form group.
object
Content to add before the textarea used by the character count component.
See macro options for formGroup beforeInput.
object
Content to add after the textarea used by the character count component.
See macro options for formGroup afterInput.
Options for formGroup `beforeInput` object string **Required.**
Text to add before the textarea. If `html` is provided, the `text` option will be ignored.
string **Required.**
HTML to add before the textarea. If `html` is provided, the `text` option will be ignored.
Options for formGroup `afterInput` object string **Required.**
Text to add after the textarea. If `html` is provided, the `text` option will be ignored.
string **Required.**
HTML to add after the textarea. If `html` is provided, the `text` option will be ignored.
Options for `countMessage` object string
Classes to add to the count message.
Options for `label` component string **Required.**
If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` option will be ignored.
string **Required.**
If `text` is set, this is not required. HTML to use within the label. If `html` is provided, the `text` option will be ignored.
string
The value of the `for` attribute, the ID of the input the label is associated with.
boolean
Whether the label also acts as the heading for the page.
string
Classes to add to the label tag.
object
HTML attributes (for example data attributes) to add to the label tag.
Options for `hint` component string **Required.**
If `html` is set, this is not required. Text to use within the hint. If `html` is provided, the `text` option will be ignored.
string **Required.**
If `text` is set, this is not required. HTML to use within the hint. If `html` is provided, the `text` option will be ignored.
string
Optional ID attribute to add to the hint span tag.
string
Classes to add to the hint span tag.
object
HTML attributes (for example data attributes) to add to the hint span tag.
```
{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({
name: "withHint",
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 component](/components/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.
- HTML
- Nunjucks
HTML
```
Do not include personal or financial information like your National Insurance number or credit card details
You can enter up to 200 characters
```
Nunjucks
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work; these are marked as “Required” in the option description. Deprecated options are marked as “Deprecated”.
If you’re using Nunjucks macros in production with “html” options, or ones ending with “html”, you must sanitise the HTML to protect against [cross-site scripting exploits](https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting).
Primary options string
The ID of the textarea. Defaults to the value of `name`.
string **Required.**
The name of the textarea, which is submitted with the form data.
string
Optional number of textarea rows (default is 5 rows).
string
Optional initial value of the textarea.
string **Required.**
If `maxwords` is set, this is not required. The maximum number of characters. If `maxwords` is provided, the `maxlength` option will be ignored.
string **Required.**
If `maxlength` is set, this is not required. The maximum number of words. If `maxwords` is provided, the `maxlength` option will be ignored.
string
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.
object **Required.**
The label used by the character count component.
See macro options for label.
object
Can be used to add a hint to the character count component.
See macro options for hint.
object
Can be used to add an error message to the character count component. The error message component will not display if you use a falsy value for `errorMessage`, for example `false` or `null`.
[See macro options for errorMessage](/components/error-message/#options-error-message-example).
object
Additional options for the form group containing the character count component.
See macro options for formGroup.
string
Classes to add to the textarea.
object
HTML attributes (for example data attributes) to add to the textarea.
boolean
Optional field to enable or disable the `spellcheck` attribute on the character count.
object
Additional options for the count message used by the character count component.
See macro options for countMessage.
string
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 `%{count}` placeholder with the value of the `maxlength` or `maxwords` parameter.
object
Message displayed when the number of characters is under the configured maximum, `maxlength`. This message is displayed visually and through assistive technologies. The component will replace the `%{count}` placeholder with the number of remaining characters. [Our pluralisation rules apply to this macro option](https://frontend.design-system.service.gov.uk/localise-govuk-frontend/#understanding-pluralisation-rules).
string
Message displayed when the number of characters reaches the configured maximum, `maxlength`. This message is displayed visually and through assistive technologies.
object
Message displayed when the number of characters is over the configured maximum, `maxlength`. This message is displayed visually and through assistive technologies. The component will replace the `%{count}` placeholder with the number of characters above the maximum.[Our pluralisation rules apply to this macro option](https://frontend.design-system.service.gov.uk/localise-govuk-frontend/#understanding-pluralisation-rules).
object
Message displayed when the number of words is under the configured maximum, `maxwords`. This message is displayed visually and through assistive technologies. The component will replace the `%{count}` placeholder with the number of remaining words. [Our pluralisation rules apply to this macro option](https://frontend.design-system.service.gov.uk/localise-govuk-frontend/#understanding-pluralisation-rules).
string
Message displayed when the number of words reaches the configured maximum, `maxwords`. This message is displayed visually and through assistive technologies.
object
Message displayed when the number of words is over the configured maximum, `maxwords`. This message is displayed visually and through assistive technologies. The component will replace the `%{count}` placeholder with the number of characters above the maximum. [Our pluralisation rules apply to this macro option](https://frontend.design-system.service.gov.uk/localise-govuk-frontend/#understanding-pluralisation-rules).
Options for `formGroup` object string
Classes to add to the form group (for example to show error state for the whole group).
object
HTML attributes (for example data attributes) to add to the form group.
object
Content to add before the textarea used by the character count component.
See macro options for formGroup beforeInput.
object
Content to add after the textarea used by the character count component.
See macro options for formGroup afterInput.
Options for formGroup `beforeInput` object string **Required.**
Text to add before the textarea. If `html` is provided, the `text` option will be ignored.
string **Required.**
HTML to add before the textarea. If `html` is provided, the `text` option will be ignored.
Options for formGroup `afterInput` object string **Required.**
Text to add after the textarea. If `html` is provided, the `text` option will be ignored.
string **Required.**
HTML to add after the textarea. If `html` is provided, the `text` option will be ignored.
Options for `countMessage` object string
Classes to add to the count message.
Options for `label` component string **Required.**
If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` option will be ignored.
string **Required.**
If `text` is set, this is not required. HTML to use within the label. If `html` is provided, the `text` option will be ignored.
string
The value of the `for` attribute, the ID of the input the label is associated with.
boolean
Whether the label also acts as the heading for the page.
string
Classes to add to the label tag.
object
HTML attributes (for example data attributes) to add to the label tag.
Options for `hint` component string **Required.**
If `html` is set, this is not required. Text to use within the hint. If `html` is provided, the `text` option will be ignored.
string **Required.**
If `text` is set, this is not required. HTML to use within the hint. If `html` is provided, the `text` option will be ignored.
string
Optional ID attribute to add to the hint span tag.
string
Classes to add to the hint span tag.
object
HTML attributes (for example data attributes) to add to the hint span tag.
```
{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({
name: "withHint",
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 `