Whitespace Character Codes: How to Identify Every Kind of Space in Text
Look up whitespace character codes like U+0020, U+00A0 and U+200B, reveal hidden spaces in your text, and replace them safely without changing meaningful content.
What a whitespace character code tells you
Every character in a text has a Unicode code point, including characters you cannot see. A code point is written as U+ followed by a hexadecimal number. The ordinary space you type with the space bar is U+0020. The no-break space U+00A0 looks identical on screen but behaves differently. It prevents a line break, and a search for a plain space will not match it. It can also break number parsing, CSV fields, log-in fields and exact-match lookups.
Inspecting whitespace by code does three things. It takes any text as input. It reports the position, code point, name and category of each space-like or invisible character. It changes nothing. That lets you replace a vague problem like "there's something weird between these words" with a specific character that you can search for, replace, or keep on purpose.
Common whitespace and invisible characters by code
Unicode defines a White_Space property that covers 25 code points. Several other characters are invisible but are not classed as whitespace. They often cause the same problems, so they are listed here too. The UTF-8 column shows the bytes you will see in a hex view of a UTF-8 file.
| Code point | Name | UTF-8 bytes | Unicode White_Space | Typical source or role |
| U+0009 | CHARACTER TABULATION (tab) | 09 | Yes | Indentation, columns in TSV files |
| U+000A | LINE FEED | 0A | Yes | Line ending on Unix-like systems |
| U+000B | LINE TABULATION | 0B | Yes | Rare; sometimes appears where a word processor exported a manual line break |
| U+000C | FORM FEED | 0C | Yes | Page break in older documents and source files |
| U+000D | CARRIAGE RETURN | 0D | Yes | First half of the CR LF line ending used on Windows |
| U+0020 | SPACE | 20 | Yes | Ordinary space |
| U+0085 | NEXT LINE (NEL) | C2 85 | Yes | Legacy line break, often a sign of text decoded with the wrong encoding |
| U+00A0 | NO-BREAK SPACE | C2 A0 | Yes | HTML , text copied from web pages and word processors |
| U+1680 | OGHAM SPACE MARK | E1 9A 80 | Yes | Word separator in Ogham script |
| U+2000–U+200A | EN QUAD through HAIR SPACE | E2 80 80 – E2 80 8A | Yes | Fixed-width typographic spaces, such as U+2007 FIGURE SPACE and U+2009 THIN SPACE |
| U+2028 | LINE SEPARATOR | E2 80 A8 | Yes | Unambiguous line break that many tools do not expect |
| U+2029 | PARAGRAPH SEPARATOR | E2 80 A9 | Yes | Unambiguous paragraph break |
| U+202F | NARROW NO-BREAK SPACE | E2 80 AF | Yes | Between numbers and units, before some French punctuation, and in some locale-formatted times |
| U+205F | MEDIUM MATHEMATICAL SPACE | E2 81 9F | Yes | Mathematical typesetting |
| U+3000 | IDEOGRAPHIC SPACE | E3 80 80 | Yes | Full-width space in Chinese, Japanese and Korean text |
| U+200B | ZERO WIDTH SPACE | E2 80 8B | No | Invisible line-break opportunity, often pasted from web pages or chat apps |
| U+200C | ZERO WIDTH NON-JOINER | E2 80 8C | No | Meaningful in Persian, Indic and other scripts |
| U+200D | ZERO WIDTH JOINER | E2 80 8D | No | Meaningful in emoji sequences and some scripts |
| U+2060 | WORD JOINER | E2 81 A0 | No | Invisible character that prevents a line break |
| U+FEFF | ZERO WIDTH NO-BREAK SPACE (byte order mark) | EF BB BF | No | Byte order mark at the start of a file; stray copies inside text |
Some characters on this list carry meaning. U+200C and U+200D change how emoji sequences and several writing systems display, so removing them can corrupt the text. Note also that U+180E MONGOLIAN VOWEL SEPARATOR was counted as whitespace in older Unicode versions. Since Unicode 6.3 it is a format character, so older tools and newer tools may classify it differently.
How the same code is written in different notations
Each context writes the same character in its own way, which matters when you search source files or build a replacement. Here is the no-break space as an example:
| Context | U+00A0 written as |
| Unicode notation | U+00A0 |
| Decimal value | 160 |
| HTML | or or |
| CSS content property | "\00A0" |
| JavaScript and JSON strings | \u00A0 |
| Python strings | \u00a0 or \N{NO-BREAK SPACE} |
| PCRE regular expressions | \x{00A0} |
| URL percent-encoding (UTF-8) | %C2%A0 |
A code point and its bytes are different things. U+00A0 is one character. In UTF-8 it takes two bytes, C2 A0. In Latin-1 or Windows-1252 it is the single byte A0. If UTF-8 text is decoded as Windows-1252, a no-break space shows up as "Â" followed by a blank. Seeing a stray "Â" near spaces is a strong clue that both a no-break space and an encoding mismatch are involved.
Step 1: Work on the exact text
Copy the problem text directly, or open the original file. Retyping it replaces the hidden characters with ordinary ones. Some web forms and editors also trim or normalize whitespace when you paste, so the safest approach is to save the text to a file and inspect that file.
Step 2: List the code points
This Python script prints every whitespace or invisible format character with its position, code point, Unicode category and name. The sample string is an illustrative example. In real use, replace it with the contents of your file, read with encoding="utf-8".
import unicodedata
text = "Total:\u00a0120\u2009kg\u200b\tdone\r\n"
for i, ch in enumerate(text):
cat = unicodedata.category(ch)
if ch.isspace() or cat in ("Zs", "Zl", "Zp", "Cf"):
name = unicodedata.name(ch, "<control>")
print(f"{i:>3} U+{ord(ch):04X} {cat} {name}")
Based on the character properties, the script should print the output below. This is the expected result, not a captured run. Positions count from zero. Control characters such as tab have no Unicode name, so the script labels them <control>.
6 U+00A0 Zs NO-BREAK SPACE
10 U+2009 Zs THIN SPACE
13 U+200B Cf ZERO WIDTH SPACE
14 U+0009 Cc <control>
19 U+000D Cc <control>
20 U+000A Cc <control>
Including category Cf also catches invisible format characters that are not spaces, such as U+00AD SOFT HYPHEN and the left-to-right and right-to-left marks. These often turn out to be the real problem. Also note that Python's isspace() returns True for a few control characters, U+001C to U+001F, that Unicode does not classify as White_Space.
If you are working in a browser console or Node.js instead, the following example does the same job. Its index counts characters rather than UTF-16 code units.
const text = "Total:\u00A0120\u2009kg\u200B\tdone";
[...text].forEach((ch, i) => {
if (/[\s\u0085\u200B-\u200D\u2060]/u.test(ch)) {
const hex = ch.codePointAt(0).toString(16).toUpperCase().padStart(4, "0");
console.log(i, "U+" + hex);
}
});
The extra characters in that pattern are there because JavaScript's \s does not match everything. It covers tab, line breaks, U+00A0, U+FEFF and the other space separators, but it does not match U+0085, U+200B, U+200C, U+200D or U+2060. Trimming functions have similar gaps. JavaScript's trim() and Python's strip() both remove no-break spaces from the ends of a string, but neither removes a zero width space.
Step 3: Check the raw bytes
A byte view shows exactly what is stored in the file, whatever an editor chooses to display. On Linux and macOS, od prints each byte in hex. In this example the no-break space appears as c2 a0 between the letters a (61) and b (62).
printf 'a\xc2\xa0b\n' | od -An -tx1
# expected: 61 c2 a0 62 0a
GNU cat -A gives a quicker visual check:
• Tab shows as ^I.
• Carriage return shows as ^M.
• The end of each line shows as $.
• Non-ASCII bytes show in M- notation, so a UTF-8 no-break space appears as M-BM- followed by a blank.
For whole files, hexdump -C file.txt shows offsets, hex bytes and a text column side by side.
printf 'a\xc2\xa0b\tc\r\n' | cat -A
# expected: aM-BM- b^Ic^M$
Step 4: Find every occurrence in a file
To find non-ASCII whitespace and zero-width characters, along with their line numbers, use grep with Perl-compatible patterns. This needs a grep built with -P support and a UTF-8 locale, for example LC_ALL=C.UTF-8. Without these, the \x{...} escapes may fail or match single bytes instead of characters.
grep -nP '[\x{0085}\x{00A0}\x{1680}\x{2000}-\x{200D}\x{2028}\x{2029}\x{202F}\x{205F}\x{2060}\x{3000}\x{FEFF}]' file.txt
Tabs and Windows line endings are plain ASCII, so a separate check keeps them distinct from the Unicode spaces: grep -nP '\t' file.txt lists tabs, and grep -c $'\r' file.txt counts lines that contain a carriage return.
Step 5: Decide what each character should become
There is no single correct cleanup. Base each decision on what the character does in your text and what the destination expects.
- U+0020 SPACE: keep.
- U+00A0, U+202F and U+2007: keep them where they deliberately prevent a line break, for example between a number and its unit in typeset text. Replace them with U+0020 in data fields, identifiers, search keys and CSV values.
- U+2000–U+200A, U+205F and U+3000: replace them with U+0020 in data. Keep them in typeset or CJK content where the width is intentional.
- U+200B and U+2060: these are usually safe to remove from data, where they rarely carry meaning.
- U+FEFF: keep it only at the very start of a file, and only if the program reading the file expects a byte order mark. Remove it anywhere else.
- U+200C and U+200D: do not remove them unless you are certain they are stray. They change how emoji sequences and several scripts render.
- U+000D, U+000A, U+0085, U+2028 and U+2029: convert all line breaks deliberately to the single convention your target expects, rather than deleting them.
- U+0009 tab: keep it wherever it has a structural role, such as TSV columns, Makefiles or indentation.
Step 6: Replace only the characters you chose
An explicit mapping changes the characters you listed and nothing else. The function below converts typographic and no-break spaces to U+0020, removes the zero width space and the word joiner, and drops a leading byte order mark. It leaves tabs, line breaks, U+200C and U+200D untouched. It requires Python 3.9 or later because of removeprefix().
SPACES = "\u00a0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000"
ZERO_WIDTH = "\u200b\u2060"
TABLE = {ord(ch): " " for ch in SPACES}
TABLE.update({ord(ch): None for ch in ZERO_WIDTH})
def clean_field(value: str) -> str:
return value.translate(TABLE).removeprefix("\ufeff")
# example: clean_field("Total:\u00a0120\u2009kg\u200b") should return "Total: 120 kg"
Avoid using Unicode NFKC normalization as a shortcut for this job. NFKC does convert U+00A0, U+2000–U+200A, U+202F, U+205F and U+3000 to U+0020. However, it leaves U+200B alone and also rewrites many characters that are not spaces. For example, it turns the ligature "fi" into "fi", the full-width "A" into "A", and the superscript "²" into "2". That is exactly the kind of unintended change to meaningful content this cleanup is meant to avoid.
Step 7: Verify the result
Run the Step 2 inspection or the Step 4 search again on the cleaned text. Only the characters you chose to keep should remain. Then confirm that the visible content did not change. The check below strips all whitespace and the removed zero-width characters from both versions and compares what is left. Here, before and after stand for the original and cleaned strings.
import re
INVISIBLE = re.compile(r"[\s\u200b\u2060\ufeff]")
def visible(s: str) -> str:
return INVISIBLE.sub("", s)
assert visible(before) == visible(after), "non-whitespace content changed"
If the assertion passes and the inspection lists only the code points you expected, the cleanup affected whitespace alone. If you processed a file, also compare its line count before and after with wc -l, unless you changed line endings on purpose.
Choosing an inspection tool
This guide relies on code points defined by Unicode and on documented behavior of standard language features and command-line utilities. It does not test or compare specific online inspectors or editor plugins, so no claims are made about their accuracy. If you use one, check two things. First, it should report actual code points such as U+00A0, not just a generic "space" label. Second, it should show your input exactly as pasted, without trimming or normalizing it first.