How to use the string length calculator
- Type or paste your text into the input area.
- The string length calculator updates instantly as you type.
- Review the six metrics: code points, UTF-16 units, UTF-8 bytes, graphemes, words and lines.
- Compare the values to understand how your text will be stored or transmitted.
What each metric means
A proper string character counter needs to distinguish between several ways of measuring text. Here is what each row reports:
- Characters (code points): The number of Unicode scalar values. This matches Python's
len(s)on a Unicode string. - UTF-16 code units: The number of 16-bit units used by JavaScript's native
String.length. Characters above U+FFFF require two units (a surrogate pair). - UTF-8 bytes: The byte count when encoded as UTF-8. ASCII characters take 1 byte, Latin extended takes 2, most CJK and emoji take 3 or 4.
- Grapheme clusters: What a user perceives as a single character. A base letter plus combining marks (like e + acute accent) form one grapheme. This uses
Intl.Segmenterwhere available. - Words: Sequences of non-whitespace characters separated by spaces, tabs or line breaks.
- Lines: The number of lines, counting an empty string as one line. Each newline character adds a line.
Why string length varies by encoding
Consider the waving hand emoji (U+1F44B). As a Unicode code point it is one character. In UTF-16, which JavaScript uses internally, it requires two code units because it sits outside the Basic Multilingual Plane. In UTF-8 it occupies four bytes. If you append a skin tone modifier (U+1F3FD), you now have two code points and four UTF-16 units, but visually it is still one grapheme cluster. This is why a basic string length counter that only reports .length can mislead you when working with emoji, accented letters or scripts like Devanagari.
Python developers often expect len('cafe\u0301') to return 4, but it returns 5 because the combining acute accent is a separate code point. Encoding that same string to UTF-8 with 'cafe\u0301'.encode('utf-8') yields 6 bytes. This tool mirrors those exact behaviours so you can verify counts across languages without leaving the browser.
Common string lengths reference
The table below shows how typical inputs are measured by this string length calculator. Use it as a quick sanity check when debugging.
| Input | Code points | UTF-16 units | UTF-8 bytes | Graphemes |
|---|---|---|---|---|
| A | 1 | 1 | 1 | 1 |
| é (U+00E9) | 1 | 1 | 2 | 1 |
| e + ◌́ (U+0065 U+0301) | 2 | 2 | 3 | 1 |
| € (U+20AC) | 1 | 1 | 3 | 1 |
| 😀 (U+1F600) | 1 | 2 | 4 | 1 |
| 👨👩👧 (family ZWJ) | 5 | 7 | 18 | 1 |
Notice how the family emoji uses zero-width joiners (U+200D) to combine multiple emoji into a single grapheme cluster. The code point count is 5, but visually it is one character.
Practical use cases
Developers rely on accurate string measurement for many tasks. Database columns defined as VARCHAR(255) may limit by bytes or by characters depending on the engine and collation. If your database counts UTF-8 bytes, a 255-byte column holds fewer than 255 emoji. API rate limits and payload size constraints also operate on byte counts rather than visual characters.
When building forms, you might pair this tool with a character counter to enforce user-facing limits. Social media platforms typically count grapheme clusters, not UTF-16 units, so pasting a complex emoji sequence might consume more of your budget than expected. For generating test data of specific lengths, a random string generator can produce strings that you then verify here.
How the calculations work
The code point count iterates through the string using a Unicode-aware iterator rather than indexing by position, ensuring surrogate pairs are counted once. UTF-8 byte calculation follows the standard encoding rules: code points from U+0000 to U+007F take 1 byte, U+0080 to U+07FF take 2 bytes, U+0800 to U+FFFF take 3 bytes, and U+10000 to U+10FFFF take 4 bytes.
Grapheme segmentation relies on the Intl.Segmenter API with the granularity: 'grapheme' option. Where this API is unavailable, the tool falls back to counting code points and notes the limitation. Word counting splits on whitespace using a regular expression that handles spaces, tabs and all standard line terminators.
Worked examples
| Example | Input | Result |
|---|---|---|
| Emoji test | Text: Hello 👋🌍 | Characters (code points): 8; UTF-16 code units: 10; UTF-8 bytes: 14; Grapheme clusters: 8; Words: 2; Lines: 1 |
| Accented characters | Text: café résumé | Characters (code points): 11; UTF-16 code units: 11; UTF-8 bytes: 14; Grapheme clusters: 11; Words: 2; Lines: 1 |
| Multi-line text | Text: Line one / Line two / Line three | Characters (code points): 28; UTF-16 code units: 28; UTF-8 bytes: 28; Grapheme clusters: 28; Words: 6; Lines: 3 |
| CJK characters | Text: 你好世界 | Characters (code points): 4; UTF-16 code units: 4; UTF-8 bytes: 12; Grapheme clusters: 4; Words: 1; Lines: 1 |
FAQ
What is the difference between characters and grapheme clusters?
A character (code point) is a single Unicode value. A grapheme cluster is what a reader sees as one character. For example, the letter e followed by a combining acute accent is two code points but one grapheme cluster.
Why does JavaScript String.length differ from this string length calculator?
JavaScript's .length property counts UTF-16 code units, not Unicode code points. Emoji and other characters outside the Basic Multilingual Plane use two code units each, so .length overcounts them compared to actual characters.
How are UTF-8 bytes calculated?
Each code point is mapped to 1 to 4 bytes based on its numeric value. ASCII characters (U+0000 to U+007F) use 1 byte, while most emoji use 4 bytes.
Does this string character counter handle empty strings correctly?
Yes. An empty string returns 0 for characters, bytes, graphemes and words, and 1 for lines, matching standard conventions in most programming languages.
Can I use this as a string length counter for database column sizing?
Absolutely. Check whether your database column limits by characters or by bytes. The UTF-8 bytes row tells you exactly how much storage the text requires in a UTF-8 encoded column.
Is my text sent to a server?
No. All counting happens locally in your browser. Nothing is uploaded or stored.