W3docs

String Functions

String Word Count

Count the number of words in any text. Hyphenated words and contractions count as one word.

About counting words in text

This tool counts the words in whatever text you paste into the box. The count updates as you type — nothing is uploaded or logged, the whole computation runs in your browser. It answers the same question as a word processor's status bar, for text you're editing elsewhere: a draft with a minimum-word SEO target, an abstract with a hard cap, or a product description you need to trim.

Words are found with the browser's Unicode word segmentation (Intl.Segmenter with isWordLike), so letters from any script count: accented Latin (héllo wörld is 2 words), Cyrillic (Привет мир is 2), and Japanese or Chinese, which have no spaces and are split with a built-in dictionary. Numbers count as words (3 apples and 2 pears is 5), and contractions like don't and hyphenated words like well-known count as one word each. Punctuation and symbols never count.

Where Intl.Segmenter isn't available the tool falls back to a regular expression, /[\p{L}\p{N}]+(?:['’-][\p{L}\p{N}]+)*/gu, which treats any run of letters and digits as a word and gives the same answer for space-separated text. This is a deliberate departure from PHP's str_word_count(), which ignores digits and splits words at accented letters. Word processors use their own tokenizers, so expect small differences from their counts, mostly around hyphens and unusual punctuation.

Examples

What counts as a wordtext
héllo wörld            → 2
Привет мир             → 2
日本語 テキスト        → 2
3 apples and 2 pears   → 5
it's a sun-flower      → 3

Any script counts, numbers count, and an internal apostrophe or hyphen keeps a word together.

The same count in plain JavaScriptjs
const seg = new Intl.Segmenter('und', { granularity: 'word' });
[...seg.segment('Привет мир, 2024!')].filter((s) => s.isWordLike).length;
// 3 — "Привет", "мир", "2024"

Intl.Segmenter is the Web API this tool uses. A /[A-Za-z]+/ regex would find no words in this string at all.

Raw HTML inflates the counttext
<p class='intro'>Hello world.</p>
→ 6 words   (p, class, intro, Hello, world, p)

Hello world.
→ 2 words

Tag names and attribute values are words too, so pasting markup overcounts. Strip tags first with the HTML Tags Remover.

Frequently asked questions

Does a hyphenated word or a contraction count as one word or two?

One. An apostrophe or hyphen inside a word keeps it together, so well-known and don’t each count as a single word.

Do numbers count as words?

Yes. I have 2 cats is 4 words, and a lone 2024 is 1 word. Punctuation and symbols on their own are never counted.

Does it work for Russian, Chinese, Japanese and accented text?

Yes. Words are detected with Unicode word segmentation, so héllo wörld and Привет мир are 2 words each. Japanese and Chinese have no spaces between words, so they are split with a built-in dictionary and the count is a good estimate rather than an exact linguistic answer.

Should I strip HTML tags before counting words?

Yes, if you're pasting markup. Tag names and attribute values are words too, so <p class='intro'>Hello world.</p> counts as 6 instead of the 2 a reader sees. Run the text through the HTML Tags Remover first.

Will this match the word count in Microsoft Word or Google Docs?

Usually, for ordinary prose. Each program uses its own tokenizer, so counts can differ slightly around hyphens, slashes and symbols. This tool is not a byte-for-byte clone of PHP str_word_count(), which ignores digits and non-ASCII letters.