What Is a Zero-Width Space (U+200B)? How to Find and Remove It
A zero-width space is a character that takes up no space on screen, so you cannot see it, but software still counts it. That is exactly why it causes such confusing bugs. This guide explains what it is, where it comes from, how to find it, and how to remove it safely.
What is a zero-width space?
The zero-width space is the Unicode character U+200B. It has no visible shape and no width. It was designed as a hint for line breaking: it marks a spot where a line is allowed to wrap, without showing a space. That is useful for languages that are written without spaces between words, and for very long strings such as web addresses.
In HTML you can write it as ​ or ​. In most programming languages it is "\u200b".
Similar invisible characters
The zero-width space has relatives, and they behave differently:
| Code | Name | What it is for |
|---|---|---|
U+200B | Zero-width space | Allows a line break without showing a space |
U+200C | Zero-width non-joiner | Stops two letters from joining, used in Persian and some Indic scripts |
U+200D | Zero-width joiner | Joins characters, used to build many emoji, such as family emoji |
U+2060 | Word joiner | Prevents a line break at that spot |
U+FEFF | Byte order mark | Marks the encoding at the start of a file; also called zero-width no-break space |
Because the last three have real jobs, removing every invisible character blindly can damage emoji or text in some languages. A good cleaner keeps them where they belong.
Where do zero-width spaces come from?
There is no single source. The usual routes are:
- Copying text out of web pages, content management systems, chat windows or messaging apps, which sometimes add them for line breaking or formatting.
- Text that passed through word processors or converters that insert them.
- Deliberate use. Some people hide zero-width characters in text to mark a copy or to carry a small hidden message.
You usually cannot tell where a particular one came from just by looking at it. What matters is finding it and deciding whether to keep it.
What problems do they cause?
- Search and replace finds nothing for a word that is clearly on the screen, because the word has an invisible character inside it.
- Two identical-looking strings do not match, which breaks logins, usernames, lookups and duplicate checks.
- Character counts are higher than expected, which can trip length limits in forms.
- Spreadsheet formulas fail, for example a lookup that cannot find a value that seems to be there.
- Data files break, such as a CSV column header that no longer matches its name.
How to find zero-width spaces
In the AI Text Cleaner
Paste your text into the left box. If it contains unusual characters, a list appears under the boxes showing each code, its name and how many times it appears.
In a code editor
Visual Studio Code highlights invisible and look-alike Unicode characters by default, so a zero-width space usually shows up as a marked box. The behaviour is controlled by the editor.unicodeHighlight settings.
On the command line
Perl is installed on macOS and most Linux systems. This prints the line numbers that contain the character:
perl -CSD -ne 'print "$.: $_" if /\x{200B}/' file.txt
In a spreadsheet
To test whether a cell contains one, compare its length with the length after removing the character:
=LEN(A1) - LEN(SUBSTITUTE(A1, UNICHAR(8203), ""))
How to remove zero-width spaces
With the AI Text Cleaner
Leave the option Remove invisible characters switched on and copy the cleaned text from the right box. Nothing is uploaded; the cleaning happens in your browser.
In a spreadsheet
=SUBSTITUTE(A1, UNICHAR(8203), "")
This works in Excel and in Google Sheets.
In Python
import re
clean = re.sub(r"[\u200b\u2060\ufeff]", "", text)
Notice that this pattern leaves U+200C and U+200D alone on purpose.
On the command line
perl -CSD -pe 's/\x{200B}//g' input.txt > output.txt
In Google Docs
Open Find and replace, tick Match using regular expressions, search for \x{200B} and replace with nothing. If your version handles it differently, use a cleaner tool instead.
Should you always remove them?
No. If the text is meant for a language that uses joiners or non-joiners, or contains emoji sequences, those characters are doing real work. Remove the zero-width space and the byte order mark freely in ordinary text, but check the result if your text includes those cases.
Quick answers
Is a zero-width space the same as a normal space? No. A normal space is visible as a gap and has width. A zero-width space has neither.
Can a zero-width space make text look wrong? Sometimes it changes where a line breaks, but usually it is completely invisible, which is the reason it is hard to find.
Do zero-width spaces mean a text was written by AI? No. They come from many places and prove nothing about who wrote the text.