JavaScript length counts UTF-16 code units, not what readers call “letters”
This pane’s “characters” value is the string length after line endings are normalized to LF: it is the number of UTF-16 code units, the same unit that JSON.stringify and most DOM APIs use in JavaScript. Supplementary characters such as many emoji occupy two code units, so length can be 2 while the reader still sees one symbol. A true grapheme count needs Intl.Segmenter or a library. “Without spaces” removes every Unicode whitespace category character, not only the ASCII space. “Words” splits on runs of whitespace after trim—there is no Chinese or Japanese word segmentation here. “Lines” counts substrings separated by LF; “paragraphs” counts non-empty blocks separated by one or more blank lines. “Byte length” is UTF-8 from TextEncoder, what fits a byte budget on the wire or in a VARCHAR byte cap. For placeholders and layout, script choice changes line breaks—see lorem ipsum generator. For authored markup, tags and spaces both count—see Markdown to HTML. To move between decimal bytes and KiB, see byte unit converter.
What code units, graphemes, whitespace-split words, and UTF-8 bytes each measure
Why “characters” here is UTF-16 code units and can disagree with a visual character count
- ECMAScript exposes string length as the count of UTF-16 code units, not extended grapheme clusters.
- A supplementary-plane character is encoded as a surrogate pair, so length is 2 and charCodeAt shows two halves.
- An emoji with a skin-tone modifier or a joiner sequence can be several code units while still one extended grapheme.
- Normalization to NFC or NFD changes code unit count without changing what most readers see as “the same text”.
Why splitting on whitespace mis-counts “words” in Chinese, Japanese, and Thai
- With no spaces between words, the whole line can be one token after trim.
- English and French rely on spaces; CJK and Thai often do not, so “word” needs a segmenter tuned to the language.
- Punctuation attached to a token stays inside that token; hyphens and apostrophes are not split unless adjacent to whitespace.
- Multiple internal spaces collapse for counting words; they still count as separate characters unless removed in “without spaces”.
Why CRLF normalization changes line and paragraph counts from raw paste
- Windows ends a line with CR followed by LF; old Mac files sometimes use CR alone. Both become one LF before counting.
- Each LF starts a new line; an empty final line still adds one line if the string ends with a newline.
- A paragraph is a trimmed block between blank lines; a single newline inside a paragraph does not start a new paragraph.
- Markdown’s hard line break (two spaces before newline) is still one line in this counter—it does not become a paragraph break.
Why UTF-8 byte length can exceed “character” count on multilingual text
- ASCII is one byte per code unit; common Han characters are often three bytes in UTF-8.
- Emoji are often four bytes each while still contributing two UTF-16 code units in the browser string.
- A wire limit or SMS segment is usually counted in bytes or septets, not in JavaScript length.
- Database BYTE length limits align with UTF-8 octets when the column is utf8mb4, not with grapheme count.
Which column matches a limit from a product spec or a schema
A tweet, post, or bio box that says “280 characters”
The product may count extended grapheme clusters or apply a normalization first. This page counts UTF-16 code units. For emoji-heavy text, compare against the same engine the platform uses.
A database column or API field that says VARCHAR(191) bytes
Use the UTF-8 byte row. The character row is code units; trimming spaces does not shrink surrogate pairs or multi-byte Han characters.