Home / Blog / Other text utilities

Character-count scope

Calculate Words, Characters and Letters Separately

Calculate word and character totals using the right unit, with checked examples for spaces, punctuation, accents and emoji rather than a word-length estimate.

Calculate Words, Characters and Letters Separately

Calculate words and characters as separate measurements of the actual text. A word total cannot determine an exact character total because words have different lengths, punctuation adds characters and spacing may be included or excluded. Start by identifying the unit required by the destination, then count the selected text in that unit.

Compare the totals for one phrase

Paste green folder into Count Words and Characters. The fixture contains two word tokens, twelve characters including the space, eleven characters without whitespace and eleven letters. Each number describes a different property of the same phrase.

The total can be checked manually: green has five letters, folder has six and the separating space contributes one character. Adding five, six and one produces twelve. Multiplying the two-word count by an assumed average word length would only produce an estimate.

Account for punctuation and digits

TextCharactersLetters
folder66
folder!76
folder276

The exclamation mark and digit increase the character count without increasing the letter count. They are part of the submitted string if they remain in the field. Do not use a letters-only total to assess a limit that includes punctuation or numbers.

Similarly, a hyphenated expression can count as one word while containing several letters and punctuation characters. Word boundaries and character boundaries are separate decisions; a change to one total does not imply an equal change to the other.

Decide how whitespace is treated

The local without-whitespace count removes spaces, tabs and line-break whitespace before counting the remaining text. It does not mean remove punctuation. For A followed by a line break and B, the current browser gives three character clusters including the line break and two without whitespace.

Leading and trailing spaces also matter. The string containing a space, folder, and another space has eight characters including those spaces and six without them. A receiving form may trim them before enforcing its own limit; that behavior belongs to the receiving form, not to the counter.

Choose the character definition carefully

In a modern browser with Intl.Segmenter, the local character counter uses grapheme clusters after Unicode NFC normalization. That approximates user-perceived characters more closely than JavaScript string length. Older environments without that API use a code-point fallback, so complex joined characters can produce a different result.

The family emoji 👨‍👩‍👧‍👦 is one grapheme cluster in the tested browser, seven Unicode code points and eleven JavaScript UTF-16 code units. All three figures can be technically correct when their units are stated. None is an interchangeable measure of storage bytes.

Check equivalent accent spellings

Café can be encoded with a single accented letter or with an e followed by a combining accent. The local tool normalizes both tested forms and reports four characters. A raw code-point or byte count can distinguish their original encodings before normalization.

When a system specifies an encoding-based limit, use its actual measurement rather than assuming a visible-character counter matches it. For ordinary editing, the visible result may be the useful number; for a database or protocol, the storage representation may matter instead.

Measure the final selected string

Select exactly the text that will be submitted, including the punctuation and line breaks required in that field. Paste it into the counter, inspect its boundaries and choose the relevant displayed total. Replace the input with a second small example if you need to confirm that the result updates.

Recount after revisions and test the destination’s own limit when available. Keep the selection and counting unit with any reported result. MDN’s Intl.Segmenter documentation explains the browser segmentation API, while the examples here describe the tested local counter behavior.