Form character count
Shows how many characters remain before, or exceed, an input limit.
On this page
This docs is LLM-friendly and available as clean Markdown.
Supported browser agents can also use WebMCP to search, read, and open these docs. Learn more
Usage
import { GlFormCharacterCount } from "gitlab-ui-react/form-character-count";<GlFormCharacterCount
countTextId="summary-count"
limit={100}
overLimitText="1 character over limit."
remainingCountText="25 characters remaining."
value="Lorem ipsum" />Default
Use a character count when a text field has a meaningful limit. The visible count updates immediately, while its polite live region is debounced to avoid excessive announcements.
Input character count
40 characters remaining.
40 characters remaining.
import { useState } from "react";
import { GlFormField, GlFormFieldLabel } from "gitlab-ui-react/form-field";
import { GlFormCharacterCount } from "gitlab-ui-react/form-character-count";
import { GlFormInput } from "gitlab-ui-react/form-input";
const limit = 40;
export default function FormCharacterCountExample() {
const [value, setValue] = useState("");
const remaining = limit - value.length;
return (
<GlFormField className="max-w-md">
<GlFormFieldLabel htmlFor="summary">
Summary
</GlFormFieldLabel>
<GlFormInput
aria-describedby="summary-count"
id="summary"
value={value}
onValueChange={(nextValue) => setValue(String(nextValue))} />
<GlFormCharacterCount
countTextId="summary-count"
limit={limit}
overLimitText={`${Math.abs(remaining)} characters over limit.`}
remainingCountText={`${Math.max(remaining, 0)} characters remaining.`}
value={value} />
</GlFormField>
);
}
Accessibility
- Connect the input to
countTextIdwitharia-describedby. - Provide localized
remainingCountTextandoverLimitText; include the current count in each value. - Do not use the counter as the only validation feedback when exceeding the limit prevents submission.
API
GlFormCharacterCount forwards supported attributes to its root <div> and does not accept unnamed children.
| Prop | Description | Default |
|---|---|---|
countTextId |
Sets the polite live region ID referenced by the input. | — |
limit |
Sets the character limit. | — |
value |
Supplies the current input value. | "" |
remainingCountText |
Provides localized text shown at or below the limit. | — |
overLimitText |
Provides localized text shown above the limit. | — |