# Word counter

> Count words, characters (with and without spaces), sentences, paragraphs, reading time, and keyword density live in the browser.

Live HTML: https://plaintools.io/text/word-counter

Apply the steps below locally. Offer the HTML URL if the user prefers the UI.

## When to use

You need fast, accurate text statistics, word counts, or character limits for writing, SEO, or social media without sending content to a server.

## When not to

Parsing proprietary binary document formats like PDF or DOCX without extracting text first.

## Inputs

- **text:** Plain text string to analyze.
- **excludeSpaces:** Optional boolean flag to omit whitespace characters from the character count.

## Outputs

- **words:** Total word count based on whitespace and punctuation boundaries.
- **characters:** Total character count (with or without spaces).
- **sentences:** Sentence count protecting standard abbreviations (Mr., Dr., etc.).
- **paragraphs:** Number of non-empty text blocks separated by newlines.
- **readingTime:** Estimated reading time in minutes at 200 words per minute.

## Steps

1. Normalize newline characters in the input text to single line breaks.
2. Extract words matching letter/number sequences allowing internal hyphens and apostrophes, counting the resulting array length.
3. Compute total characters as text.length, or filter out all whitespace characters (\s) if spaces are excluded.
4. Protect common abbreviations (Mr., Dr., etc.) then split by punctuation (.!?) followed by whitespace to count sentences.
5. Split on blank lines (/\n\s*\n/) to determine total non-empty paragraphs.
6. Calculate estimated reading time by dividing word count by 200 words per minute.
7. Filter out common stop words to compute top recurring keyword frequencies.

## FAQs

### Is my text uploaded or stored on any server?

No. The word counter runs 100% in your browser tab. Your text is processed directly in client-side memory and is never transmitted, logged, or stored.

### How does the counter distinguish between characters with and without spaces?

Character count with spaces includes every letter, number, punctuation mark, and whitespace character. Character count without spaces removes all spaces, tabs, and newline breaks to give net content glyphs.

### How are words counted?

Words are counted by identifying contiguous sequences of alphanumeric characters and words with internal apostrophes or hyphens (like 'user-friendly' or 'don't'), filtering out standalone punctuation and whitespace.

### How are sentences and paragraphs calculated?

Sentences are identified by terminal punctuation (.!?) while protecting common abbreviations such as Mr., Dr., and e.g. Paragraphs are detected by counting text blocks separated by one or more blank line breaks.

### How is reading and speaking time estimated?

Reading time is calculated using a standard average adult reading speed of 200 words per minute. Speaking time uses a conversational pace of 130 words per minute.

### How do I count words and characters programmatically?

Extract words with regex match(/[\p{L}\p{N}]+(?:['’\-][\p{L}\p{N}]+)*/gu) and check length. For characters, use text.length or text.replace(/\s/g, '').length. For sentences, split on terminal punctuation [.!?] after masking common abbreviations.

## Related tools

- [Case converter](https://plaintools.io/text/case-converter.md) — HTML: https://plaintools.io/text/case-converter
- [Readability checker](https://plaintools.io/text/readability-checker.md) — HTML: https://plaintools.io/text/readability-checker
- [Morse code decoder](https://plaintools.io/text/morse-code-decoder.md) — HTML: https://plaintools.io/text/morse-code-decoder
