0 Width Characters: How to Find and Handle Zero-Width Characters in Text
Learn what zero-width characters are, why they cause hidden text problems, how to reveal them with search, code and byte views, and how to remove them without breaking meaningful text.
A zero-width character, also written as a 0 width character, is a Unicode character that takes up no visible space when text is displayed. It still exists in the text and affects searching, comparing, counting and copying. Two strings can look identical on screen and still fail an equality check because one contains a character you cannot see. This guide explains what these characters are, what an inspection tool or script does with them, and how to find, judge and remove them step by step without damaging text that needs them.
What zero-width characters are
Unicode assigns every character a code point, written as U+ followed by a hexadecimal number. Most zero-width characters are format characters (Unicode general category Cf). They do not draw a glyph. Instead, they give instructions to the software laying out the text, such as allowing a line break, preventing one, or controlling how neighboring characters join.
| Code point | Name | Purpose | UTF-8 bytes |
| U+200B | ZERO WIDTH SPACE | Marks a possible line-break point without showing a space | E2 80 8B |
| U+200C | ZERO WIDTH NON-JOINER | Stops two adjacent characters from joining into a ligature or connected form | E2 80 8C |
| U+200D | ZERO WIDTH JOINER | Asks adjacent characters to join; used in many emoji sequences | E2 80 8D |
| U+2060 | WORD JOINER | Prevents a line break at that position | E2 81 A0 |
| U+FEFF | ZERO WIDTH NO-BREAK SPACE / BYTE ORDER MARK | Used at the start of a file as a byte order mark; mid-text use is deprecated in favor of U+2060 | EF BB BF |
Several related characters are also invisible in normal display, even though they are not always called zero-width: the soft hyphen (U+00AD), the left-to-right and right-to-left marks (U+200E, U+200F), and the bidirectional embedding, override and isolate controls (U+202A to U+202E and U+2066 to U+2069). A thorough inspection usually looks for these too.
What an invisible-character inspection does to your text
An inspection tool or script takes ordinary text as input and makes hidden characters visible. Depending on the tool, the output is one of three things: a marked-up copy of the text with placeholders where hidden characters sit, a report listing each character's position, code point and name, or a cleaned copy with selected characters removed. Inspection alone should not change your text. Removal is a separate step, and it is the step where meaningful content can be lost.
Example (illustrative): the word below contains a zero width space between the two halves. It is shown here with an explicit placeholder because the real character would be invisible.
Displayed: password
Actual: pass<U+200B>word
Length: 9 characters, not 8
Signs that text contains zero-width characters
- A search for a word you can clearly see returns no match.
- Two values that look identical are treated as different, for example duplicate entries in a spreadsheet or a failed login with a pasted password.
- The cursor seems to stick for an extra keypress when moving through a word.
- A character or word count is higher than what you see.
- The first column header of a CSV file is not recognized, which often points to a byte order mark (U+FEFF) at the start of the file.
- A pasted URL, username or code identifier stops working even though it looks correct.
Step 1: Compare the visible length with the real length
The quickest check is to count characters with a program rather than by eye. If the count is larger than the number of characters you can see, something hidden is present. Note that languages count differently: Python counts code points, while JavaScript's length property counts UTF-16 code units. For the characters in the table above, both give the same result because each fits in one code unit.
# Python (illustrative)
text = "pass\u200bword"
print(len(text)) # 9, although only 8 letters are visible
Step 2: Search for the characters directly
Most editors and command-line tools that support regular expressions can search by code point. The pattern below matches the five characters from the table. On Linux, GNU grep needs the -P option for this syntax and a UTF-8 locale so it reads the bytes as Unicode characters.
grep -nP '[\x{200B}-\x{200D}\x{2060}\x{FEFF}]' file.txt
The -n option prints the line number of each match. To include the bidirectional controls and soft hyphen as well, extend the character class, or use a Unicode property such as \p{Cf} in engines that support it. Be aware that \p{Cf} matches every format character, so it can also flag characters that are intentional.
Step 3: Reveal each character with its position and name
A short script can list every hidden character so you can decide what each one is doing before you remove anything. The Python example below uses the standard unicodedata module to print the official name.
import unicodedata
INVISIBLE = {"\u200b", "\u200c", "\u200d", "\u2060", "\ufeff",
"\u00ad", "\u200e", "\u200f"}
def report(text):
for i, ch in enumerate(text):
if ch in INVISIBLE:
print(i, f"U+{ord(ch):04X}", unicodedata.name(ch, "UNKNOWN"))
report("pass\u200bword")
# expected: 4 U+200B ZERO WIDTH SPACE
In JavaScript, you can replace each hidden character with a visible placeholder to see where it sits in context:
const reveal = (s) =>
s.replace(/[\u200B-\u200D\u2060\uFEFF\u00AD\u200E\u200F]/g, (m) =>
`<U+${m.codePointAt(0).toString(16).toUpperCase().padStart(4, "0")}>`
);
reveal("pass\u200Bword"); // "pass<U+200B>word"
Step 4: Confirm at the byte level if needed
When you are unsure whether a tool is hiding or converting something, look at the raw bytes. In a UTF-8 file, the byte sequences from the table appear exactly as listed, for example E2 80 8B for a zero width space or EF BB BF for a byte order mark at the start of the file. A hex viewer such as xxd or hexdump shows them.
xxd file.txt | head
Step 5: Decide what to remove and what to keep
Not every zero-width character is a mistake. Removing all of them blindly can change how text displays or what it means.
- Zero width joiner (U+200D) is part of many emoji sequences, such as family, profession and flag combinations. Removing it splits one emoji into several separate ones.
- Zero width non-joiner (U+200C) is required for correct spelling in some writing systems, including Persian and several Indic scripts. Removing it can change the appearance of a word and, in some cases, its correct form.
- Directional marks (U+200E, U+200F) can be needed for correct display when right-to-left and left-to-right text are mixed.
- Zero width space (U+200B), word joiner (U+2060) and a byte order mark in the middle of text are usually safe to remove from data such as identifiers, passwords, URLs, codes and spreadsheet values, where they serve no layout purpose.
- A byte order mark at the very start of a file may be expected by some software; check what the receiving program needs before stripping it.
Step 6: Remove selectively
Target only the characters you have decided to remove. The example below strips zero width space, word joiner and byte order mark, and leaves joiners, non-joiners and directional marks untouched.
import re
cleaned = re.sub("[\u200b\u2060\ufeff]", "", text)
If the text is a single-purpose value, such as a product code or email field, you can use a stricter rule. If it is prose, emoji or multilingual content, keep the rule narrow.
Step 7: Verify the result
- Run the same search or report from Steps 2 and 3 on the cleaned text and confirm that only the characters you intended to keep remain.
- Compare the length before and after; the difference should equal the number of characters you meant to remove.
- Compare the original and cleaned text with a diff tool that shows invisible characters, to confirm no visible content changed.
- Retest the original problem: the search should now match, the comparison should succeed, or the CSV header should be recognized.
What this guide does not cover
No specific inspection products or online services were evaluated for this article, so it does not compare their features, accuracy or limits. The commands and scripts above are illustrative examples based on documented Unicode code points and standard language behavior; test them on a copy of your own data before relying on them, since editor settings, file encodings and tool versions can affect results.