String length
Measure a string in several meaningful ways at once, including emoji and Hebrew.
Why "how long is this string?" has more than one answer
It sounds like a trivial question, but the length of a piece of text depends entirely on what you are counting. A person counts the characters they can see. A database counts the storage a value takes. JavaScript counts something different again. When these numbers disagree — and they often do for emoji, accented letters and non-Latin scripts — a single "length" is misleading. This tool shows five meaningful measures side by side so you can pick the one that matters for your situation.
The five metrics explained
- Characters (graphemes): what a human perceives as one character. An emoji family like 👨👩👧, or a letter with a combining accent, counts as one — this is the count that matches "by eye".
- Code points: the number of Unicode scalar values. A single visible character can be built from several code points joined together, so this number is often higher than the grapheme count.
- UTF-16 units: the value JavaScript reports from a string's .length property. Characters outside the Basic Multilingual Plane (most emoji) take two UTF-16 units each.
- Words: the number of word-like tokens, detected in a Unicode-aware way rather than by naively splitting on spaces.
- Lines: the number of lines, counting every line break.
Why emoji and accents break naïve counting
Modern text is built from Unicode, which represents many visible characters as sequences rather than single units. A flag emoji is two regional-indicator symbols. A family emoji is several people joined by invisible "zero-width joiner" characters. An accented é can be a single code point or a plain e followed by a combining accent. Each of these looks like one character but can count as two, three or more depending on the metric. That is exactly why counting by hand, or trusting one number, leads to bugs.
Which count should you use?
- Character limits people see (a bio, a tweet-style field, an SMS preview): use Characters (graphemes), because that matches what the user counts.
- JavaScript string handling, array indexing or slicing: use UTF-16 units, since that is what .length and string indices are based on.
- Database column sizes: check whether your column is measured in characters or bytes — many are byte-limited, and UTF-8 bytes differ again from all of these counts.
- Word or line counts for editors and readability: use the Words and Lines metrics.
Frequently asked questions
- Which count matches JavaScript's string length?
- The UTF-16 units value matches the raw .length property in JavaScript. If your code slices or indexes strings, this is the number that governs its behaviour.
- Why does one emoji count as several characters?
- Many emoji are composed of several Unicode code points joined together. As a grapheme (what you see) it is one character, but its code point and UTF-16 counts are higher, which is why each measure is shown separately.
- Does it count trailing spaces and newlines?
- Yes. Every character you paste is counted, including leading and trailing whitespace and line breaks. If your totals look higher than expected, check for invisible trailing whitespace.
- Is my text sent anywhere?
- No. All counting happens in your browser. The text you type or paste never leaves your device.
- What is a grapheme?
- A grapheme, or "grapheme cluster", is a user-perceived character — the smallest unit a reader would call a single character, even if it is built from several underlying code points.
- How are bytes different from these counts?
- Bytes depend on the encoding. In UTF-8, an ASCII letter is one byte, most accented and non-Latin characters are two or three, and many emoji are four. None of the five metrics here is a byte count, so for byte-limited fields you should encode to UTF-8 first.