fixmint

Characters with or without spaces: which count a form uses

By · · 4 min read

A form, CV portal, SMS or social post counts characters in one of two ways: with spaces, or without them. Read the field's label or help text first, because it often says which. If it says neither, use the stricter count, which is usually the one without spaces. Emoji and some accented letters can also count as more than one character in systems that measure text in code units or bytes, so a text can pass in one counter and fail in another. Count with a tool that follows the same rule as the form.

Word counterIs my text over the limit?Open

With spaces or without them

  • With spaces counts every character you type, including each space, as one character.
  • Without spaces removes all whitespace before counting, so the words run together. The word counter's no-spaces figure removes every whitespace character, including line breaks, tabs and non-breaking spaces, then counts what is left.

"Hello world" has 11 characters with its space and 10 without it. A field that asks for characters with no spaces wants the second number.

Why one emoji can count as two

Text has two kinds of length. The first is the one people see: a grapheme cluster, which is one visible character even when several code points build it. The second is what the computer stores. JavaScript's string length, and many older systems, count UTF-16 code units. Most letters use one unit, but characters outside the Basic Multilingual Plane, including many emoji, use two. The thumbs-up emoji, U+1F44D, looks like one character and is two UTF-16 units, so a counter that uses code units reports 2.

The word counter here counts visible characters, so the thumbs-up emoji is 1. A family emoji is also 1, even though it is several code points joined by zero-width joiners. A form that counts code units will report more, and the difference grows with every emoji in the text.

Accented letters

The letter é can be stored in two ways. As one code point, U+00E9, it is one unit everywhere. As the letter e followed by the combining acute accent, U+0301, it is two code points and two units. Both look identical on screen. A counter that counts code points or units gives 2 for the second form, while the word counter gives 1 for both.

Byte limits add another difference. In UTF-8, é takes two bytes and most emoji take four. A field with a byte limit can hold fewer accented letters or emoji than its character count suggests. The word counter does not show bytes, so estimate them separately.

Line breaks and hidden characters

A line break is one character in a text box. Many systems store a Windows line break as two characters, carriage return and line feed, and web form submissions send line breaks in that form. A count run on a server can therefore be higher than the box suggests, by one for each line break. Count the text as it will be submitted, not only as you typed it.

Zero-width spaces behave differently. The no-spaces count does not treat them as whitespace, so they stay in the figure and inflate it. Remove hidden characters first. That tool keeps tabs and line breaks, and it turns non-breaking spaces into normal spaces, which the no-spaces count then removes. The hidden characters guide explains where these characters come from.

One text, five counts

Take the word "Café", a space and a thumbs-up emoji, U+1F44D, with the é stored as one code point. Different measures give different totals:

MeasureCount
Visible characters, with spaces (the word counter)6
Code points6
UTF-16 code units (JavaScript's length)7
UTF-8 bytes10
Visible characters, without spaces (the word counter)5

Each total is correct for its own measure. The form decides which measure counts, which is why the rule matters more than any single number.

Steps

  1. Read the rule: characters, bytes or words, and whether spaces count.
  2. Clean the text with remove hidden characters, so invisible characters do not inflate the count.
  3. Paste the text into the word counter and read the characters and characters without spaces. The limit rows show common limits, but the figure to use is the one the form counts.
  4. If the form counts bytes, estimate them separately, as above.
  5. If the form shows its own live counter, trust that figure over yours, and use this tool to find out why the two differ.
  6. If the rule is still unclear, leave a margin. Word count limits covers the same question for words and platform rules.

Edge cases

  • The platform's rule wins. Where a platform has its own counter, match its figure rather than a generic one.
  • Trailing spaces. A form may trim spaces at the ends of a field, or it may not. One trailing space can change the count by one.
  • Copied text. Text copied from a web page can contain non-breaking spaces and invisible characters. Clean it before counting.
Cover of How to Remain Valuable When Intelligence Becomes CheapHow to Remain Valuable When Intelligence Becomes Cheap

224 pages on the human, economic and strategic advantages that stay scarce when AI can do most cognitive work.

$3.84 Get it on Gumroad →