DevKitHub

Programming

Word and Character Counter

Paste text to get its counts. Characters are reported three ways, because a tweet, a database column and JavaScript itself each count them differently.

3 lines
Words
28
22 unique
Characters
131
code points
Sentences
3
Paragraphs
2

The three character counts

Characterswhat a person counts
131
UTF-16 unitsJavaScript .length
131
UTF-8 bytesstorage and payload limits
131

More

Without spaces
103
Lines
3
Longest word
opinion
Average word
3.5 characters
Reading time238 wpm
1 min
Speaking time130 wpm
1 min

Most frequent words

the
dog
lazy
brown
did
expect
for
fox
had
its

This tool runs entirely in your browser. Your input is never uploaded, stored or logged.

How it works

How many characters is this? has three correct answers, and the gap between them is where the bugs are. Code points are what a person means by a character: 🚀 is one. UTF-16 code units are what JavaScript’s own .length returns: 🚀 is two, which is why slicing a string at a fixed index can cut an emoji in half and produce a broken character. UTF-8 bytes are what a VARCHAR limit, a network payload and an HTTP header actually count: 🚀 is four, and a Japanese character is three. All three are reported rather than picking one and being quietly wrong for the other two.

Words are found by matching runs of letters and digits, with an internal apostrophe kept as part of the word, so "don’t" is one word and "hello , world" is two. This works outside the Latin alphabet — Cyrillic and Greek text is counted the same way — which a whitespace split does not reliably do. Sentences end at a full stop, exclamation mark or question mark followed by whitespace or the end of the text, and a run of terminators counts once, so "Really?!" is one sentence rather than two.

Reading time uses 238 words per minute and speaking time 130, both from Brysbaert’s 2019 meta-analysis of reading rate studies rather than the 200 that most estimators repeat without a source. Both are rounded up, because a piece that takes 1.2 minutes to read does not take one. The frequency list ignores words of two letters or fewer, which would otherwise be entirely "the", "of" and "a", and ties are broken alphabetically so the same text always produces the same list.

Common problems

Every example below is run against this tool in our test suite, so what it says here is what the tool actually does.

The character count disagrees with the one the form shows.

Why:
The two are counting different things. A field limited to 255 is usually counting UTF-8 bytes or UTF-16 units, not characters, so text with accents, emoji or CJK hits the limit well before the count suggests.
Fix:
Compare against the right number here: bytes for a database column or an API limit, UTF-16 units for anything doing JavaScript string arithmetic.

An emoji was cut in half and became a question mark.

Why:
A string was truncated at a UTF-16 index that fell between the two halves of a surrogate pair. The remaining half is not a character and renders as a replacement glyph.
Fix:
Slice by code points — spread the string into an array first — or use a library that understands grapheme clusters.

The word count is lower than the one in a word processor.

Why:
Word processors count differently. Hyphenated compounds, numbers with separators and text in headers or footnotes are all handled inconsistently between tools, and none of them is wrong.
Fix:
Use one tool consistently for anything with a word limit, and leave margin rather than sitting exactly on the boundary.

Frequently asked questions

Why are there three character counts?
Because three different things count characters three different ways. A person counts 🚀 as one, JavaScript counts it as two UTF-16 units, and UTF-8 storage counts it as four bytes. Which one you need depends on what is imposing the limit.
How is reading time estimated?
At 238 words per minute for silent reading and 130 for speaking aloud, from Brysbaert’s 2019 meta-analysis. Both are rounded up to the next whole minute. Technical material is read considerably slower than prose, so treat it as a floor.
What counts as a sentence?
Text ending in a full stop, exclamation mark or question mark followed by a space or the end of the input. Abbreviations like "e.g." inflate the count slightly — that is a hard problem in general and no counter gets it entirely right.
Is my text uploaded?
No. Everything is counted in your browser as you type, and nothing is transmitted, stored or logged.

Read more about this

Last updated