Your Character Count Is Wrong (And So Is Your Word Count)
A string has at least three different lengths. A close reading of how browser-based word counters, letter counters and Unicode escapers actually compute their numbers — and which definition to use for limits, storage and billing.
What this guide covers
- 1. Three different things called a character
- 2. What a browser word counter actually computes
- 3. The letter counter has a units mismatch
- 4. Escaping Unicode exposes the surrogate pair
- 5. Which definition should you actually use?
- 6. A short checklist before you ship a counter
- 7. Frequently asked questions
- 8. The one-line version
Ask three people how long the string `👨👩👧👦` is and you will get three defensible answers: one, seven, or eleven. All three are correct, depending on whether you are counting what a human sees, what Unicode calls a code point, or what JavaScript stores in memory. Most counter tools silently pick one of these and label it 'characters', which is where the trouble starts.
This is not an abstract concern. Character limits in forms, database column widths, SMS billing, social platform post limits and 'words read per minute' estimates all depend on that choice. When the number is wrong, a user gets their text truncated mid-glyph, a database rejects a value that appears to fit, or an analytics dashboard reports a reading time that nobody can reproduce.
Three different things called a character
- Grapheme cluster — what a reader perceives as one symbol. The family emoji above is one grapheme, even though it is built from several emoji joined by invisible zero-width joiners.
- Code point — one Unicode scalar value. The family emoji is seven code points: four people, three joiners. A flag such as 🇨🇳 is two regional indicator code points.
- UTF-16 code unit — the 16-bit slot JavaScript strings are made of. Code points above U+FFFF need a surrogate pair, two slots. The family emoji is eleven of these.
JavaScript's `String.prototype.length` counts UTF-16 code units, not characters in any human sense. That is a language design decision dating to the mid-1990s, when Unicode fit in 16 bits, and it is not going to change because changing it would break the web. `Array.from(s).length` and `[...s].length` count code points instead, because the string iterator walks scalar values. Neither counts graphemes; for that you need `Intl.Segmenter`.
What a browser word counter actually computes
The Word Counter on this site is a compact example of the whole problem. Its `count()` function is short enough to read in one sitting, and every line makes a specific assumption about what text is.
- `text.trim().split(/\s+/).length` — words are runs of non-whitespace separated by ASCII-ish whitespace.
- `text.length` — characters are UTF-16 code units.
- `text.replace(/\s/g, '').length` — the same definition, with whitespace removed.
- `text.split(/[.!?]+/).filter(Boolean).length` — a sentence ends at a full stop, exclamation mark or question mark.
- `Math.ceil(words / 200)` — a person reads 200 of those words per minute.
Run a Chinese sentence through it and you get a striking result: `今天天气很好,我们去公园吧。` reports 14 characters and 1 word. There are no spaces between Chinese words, so the whitespace split never fires. The reading time then comes out as one minute no matter how long the paragraph is. Japanese and Thai behave the same way. The counter is not broken — it implements a definition of 'word' that only works for space-delimited scripts, and it never tells you that.
Sentence splitting has its own edge cases. `Dr. Smith arrived at 3.14 pm. Really!` is two sentences to a human and four to `split(/[.!?]+/)`: the abbreviation, the decimal point and the final `pm.` each create an artificial boundary. Ellipses, initials, version numbers and quoted sentences all do this. Regular expressions that look for punctuation cannot distinguish an abbreviation from a sentence end without a dictionary or a model.
The letter counter has a units mismatch
The Letter Counter is even more instructive. It iterates with `for (const c of input.toLowerCase())`, which walks code points, and tests each against `/[a-z]/`. But it computes the percentage denominator as `input.length`, which counts UTF-16 code units. The numerator and denominator are in different units.
For pure ASCII the two agree, so the bug is invisible in the common case. Feed it text containing emoji, accented characters outside the Latin-1 range, or CJK, and the reported 'share of total characters' quietly stops being a share of anything. It also ignores every letter outside `a-z` by design — `é`, `ñ`, `ü`, `ß` and all non-Latin scripts are simply not counted. The tool says so in its hint text, which is the honest way to ship a deliberately narrow definition.
Escaping Unicode exposes the surrogate pair
The Unicode Converter encodes input with `input.split('').map(c => '\\u' + c.charCodeAt(0).toString(16).padStart(4, '0'))`. `split('')` splits on UTF-16 code units, so a supplementary-plane character is torn into its two surrogates. A single 😀 becomes `\ud83d\ude00` — two escape sequences, neither of which is a valid standalone character.
That output is not useless: it is an accurate description of how the string is stored, and it round-trips correctly if you paste it back, because the decoder reconstructs the pair. But it cannot represent a code point above U+FFFF as `\u{1F600}` the way modern JavaScript escape syntax allows, and it will confuse anyone who expects one escape per visible symbol. If you need code-point escapes, iterate with `for...of` and use `codePointAt(0)`.
Which definition should you actually use?
- Form `maxlength` and legacy database `VARCHAR(n)`: UTF-16 code units, because that is what the constraint will actually count. Use `text.length`. If your database counts bytes in UTF-8 instead, use `new TextEncoder().encode(s).length` — a CJK character is three bytes, an emoji four.
- User-facing character limits: grapheme clusters, via `Intl.Segmenter`. A user who sees one family emoji will not accept being charged eleven characters.
- Cursor movement, deletion and text selection: grapheme clusters too. Deleting half a surrogate pair produces an invalid string; deleting half a ZWJ sequence mangles an emoji.
- Word counts for CJK: whitespace splitting is the wrong instrument. Segmenters with `granularity: 'word'` and a matching locale do far better, though word segmentation in Chinese remains a research problem rather than a settled rule.
- Billing and rate limits: whatever the other party specified. SMS counts GSM-7 septets or UCS-2 code units depending on the alphabet; social platforms use their own weighted-length rules. Read the spec rather than assuming `length`.
The Text Trimmer and Line Number Adder are useful here in a narrow way: they let you see exactly where a transformation cut a string relative to line boundaries. They do not change the underlying counting rule, so treat their output as a view of the same UTF-16 model, not as a different definition.
A short checklist before you ship a counter
- Name the unit in the UI. 'Characters (UTF-16 code units)' is ugly but unambiguous; 'Characters' alone is a promise you cannot keep.
- Decide what happens at a boundary. Truncating at `n` code units can leave a dangling high surrogate. Clamp to the nearest grapheme boundary instead.
- Normalise before comparing. `é` (U+00E9) and `e` + U+0301 look identical, have different lengths, and compare unequal without NFC normalisation via `s.normalize('NFC')`.
- Test with a fixed corpus: a ZWJ emoji sequence, a flag, a combining accent in both forms, a CJK paragraph, and a right-to-left string. These five inputs catch almost every counting bug.
Frequently asked questions
Why does the word counter say my Chinese paragraph is one word? It splits on whitespace. CJK text does not use spaces between words, so use a word segmenter or report characters instead.
Is `Array.from(s).length` the right character count? It counts code points, which fixes surrogate pairs but still splits combined emoji and accented characters built from a base plus a combining mark. For visible characters use `Intl.Segmenter`.
Can I just use a library? For grapheme-aware slicing, yes — but check whether it ships its own Unicode tables and how current they are. `Intl.Segmenter` is supported in current browsers and tracks the platform's Unicode version.
Why do two tools disagree on the same text? They are almost certainly using different definitions. Ask which unit each one counts before assuming one is broken.
Does any of this involve sending my text anywhere? No. These counters run in the page using built-in JavaScript APIs; the calculation never leaves the browser.
The one-line version
A string does not have a length until you say what you are counting. Pick the unit that matches the constraint you are enforcing, put its name next to the number, and test with an emoji family before you believe the result.
Tools run privately in your browser
Every tool referenced in this guide processes your input in the browser rather than uploading it to a server we operate, and requires no account. A typical single job stays free. Larger batches, history export, and an ad-free page are optional on Pro. A few tools load a processing engine from a CDN on first use; see the privacy policy for details. Browse the full toolbox →