BBoltlyze

Character Counts, Emoji and UTF-8 Bytes: Which Number Does Your App Use?

Published · Updated · 4 min read

“Character count” can mean several different measurements. Boltlyze's character counter reports JavaScript UTF-16 code units, the same count after removing whitespace, and UTF-8 encoded bytes. None of those necessarily equals the number of visible symbols a reader sees or the limit used by another app.

One sample, three measurements

Try this sample in the counter:

A😀é

The last visible accented letter is written as e followed by a combining acute accent (U+0301). In JavaScript:

const text = 'A😀e\u0301';
text.length;                              // 5 UTF-16 code units
text.replace(/\s/g, '').length;          // 5 code units; this sample has no whitespace
new TextEncoder().encode(text).length;   // 8 UTF-8 bytes
[...text].length;                        // 4 Unicode code points

The visible sequence has three grapheme clusters for most readers: A, 😀 and é. The accented e contains two code points, and the emoji is represented by a UTF-16 surrogate pair. That's why code units, code points, grapheme clusters and UTF-8 bytes give different totals.

Add a space and a line break, for example A 😀 on one line and é on the next. The counter's whitespace-free field removes characters that JavaScript matches with \s; it does not remove punctuation or normalize accented sequences. The UTF-8 byte count measures the encoded text, including the space and newline.

When each measurement is useful

  • UTF-16 code units are useful when checking APIs or JavaScript code that uses string.length.
  • Whitespace-free code units can help compare text length when spaces, tabs and line breaks should be excluded, but it is not a word count.
  • UTF-8 bytes estimate the size of the text after UTF-8 encoding. It is not the number of visible characters and does not include JSON escaping or other transport overhead.
  • Grapheme clusters are closer to what people perceive as characters. This tool does not count them.

If you need grapheme clusters in modern JavaScript, compare with Intl.Segmenter:

const segmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
[...segmenter.segment('A😀e\u0301')].length; // 3 grapheme clusters

Support and segmentation details can vary by runtime and Unicode version. For platform posts, database fields and forms, use the destination's own counter or validation rule before submitting. Services can count code points, UTF-16 units, graphemes, bytes or a product-specific measure.

A quick check in Boltlyze

  1. Paste the sample A😀é into the character counter.
  2. Compare “With whitespace” with JavaScript's text.length result above; both should be 5.
  3. Compare the UTF-8 field with TextEncoder; both should be 8 bytes.
  4. Paste the same input into the word counter. It uses whitespace-separated tokens, which is a different rule from character counting.
  5. Confirm the final length where the text will be used. The browser counter cannot know another service's current counting convention.

The text is counted locally in your browser. A limited usage event may report the tool ID, timing and success status, but not the text itself. See the Privacy Policy for separate analytics and advertising data flows.

Tools used in this guide

More guides