How to Find and Remove Invisible Characters (Zero-Width Spaces & More)
Written by Muhammad Ali · Senior Full Stack Software Engineer
Personal website: codedbymali.comLearn what zero-width spaces, BOM, NBSP and bidi characters are, why they break code and text, and how to find and remove them with our free tool.
Your code looks perfect, but the compiler says Invalid character. A JSON.parse call fails on the very first character. Two strings look exactly the same, yet === says they are different. A search for a word in your document finds nothing, even though you can see it.
In all of these cases the culprit is usually a character you cannot see: a zero-width space, a byte order mark, a non-breaking space or a hidden direction control. This guide explains the most common invisible characters, where they come from, and how to find and remove them in seconds with our free Invisible Character Detector & Remover.
What are invisible characters?
Unicode has thousands of characters, and some of them are designed to take up no space or to look exactly like a normal space. They are useful in the right place — for example, to join emoji or to stop a line from breaking — but when they slip into code, URLs, passwords or data, they cause bugs that are very hard to spot.
The most common ones:
- Zero-width space (U+200B) – an "empty" character. Often copied from websites, Slack, Word or PDFs.
- Byte order mark / BOM (U+FEFF) – added at the start of files by some Windows editors.
- Non-breaking space (U+00A0) – looks like a space but is a different character. Very common from Word, Google Docs and web pages.
- Zero-width joiner (U+200D) – glues emoji together (👨👩👧). Fine in emoji, a problem anywhere else.
- Bidi controls (U+202E, U+2066 and friends) – change the reading direction of text. They can hide malicious code.
- Tag characters (U+E0000–U+E007F) – invisible copies of ASCII letters that can hide whole sentences inside normal text.
How to find them (3 steps)
- Open the Invisible Character Detector.
- Paste your text or drop a file. Every hidden character shows up as a colored badge like
[ZWSP]or[NBSP], with its code point and line:column. - Pick what to clean, then copy or download the clean text.
Everything runs in your browser, so you can safely paste code, API keys or private documents.
Worked example
Here is a line of JavaScript that will not run:
const price = 100;
It looks fine. But paste it into the detector and you see:
const price[ZWSP] = 100;
There is a zero-width space after price, so JavaScript sees a variable name that contains an illegal character. Click Clean and the line works again.
Another example: the domain pаypal.com. The second letter is a Cyrillic "а", not a Latin "a". It looks the same but goes to a completely different website. The tool's look-alike check flags it as а → looks like "a" (Latin).
Invisible characters cheat sheet
| Name | Code point | Usually comes from | Safe to remove? |
|---|---|---|---|
| Zero-width space | U+200B | websites, chat apps, PDFs | Yes |
| Zero-width non-joiner | U+200C | Persian/Hindi text, copy-paste | Only in non-Indic/Arabic text |
| Zero-width joiner | U+200D | emoji sequences | Not inside emoji |
| Word joiner | U+2060 | word processors | Yes |
| BOM | U+FEFF | Windows Notepad, Excel CSV | Yes, at file start |
| Non-breaking space | U+00A0 | Word, Google Docs, HTML |
Replace with a space |
| Narrow NBSP | U+202F | macOS dates/times, French text | Replace with a space |
| Soft hyphen | U+00AD | ebooks, CMS editors | Yes |
| Right-to-left override | U+202E | attacks, filename tricks | Yes |
| Tag characters | U+E0000–E007F | hidden prompt text | Yes |
Why this matters for code: Trojan Source
In 2021, researchers showed that bidi control characters can make code look different to a human than to the compiler (CVE-2021-42574, "Trojan Source"). A line that seems to be a comment can actually be running code. GitHub now shows a warning for these characters, but many editors and copy-paste flows do not. The detector shows a red warning when it finds bidi controls in code-like text.
Hidden characters in AI text
People often ask if ChatGPT or other AI tools add hidden "watermark" characters. Most AI output does not contain secret watermarks, but copied AI text often includes non-breaking spaces, narrow NBSPs or zero-width spaces from the chat interface or formatting. On the other side, attackers use tag characters to hide instructions inside text that an AI model will read but a human will not see. The detector decodes those hidden tag messages so you can see exactly what is there.
Common mistakes
- Removing every ZWJ. It breaks emoji like 👨👩👧 and some languages. Keep ZWJ inside emoji (the tool does this by default).
- Using "trim()" and thinking you're done.
trim()removes NBSP but not zero-width spaces. - Saving JSON or shell scripts with a BOM. Many parsers fail on it. Save as "UTF-8 without BOM".
- Replacing look-alike letters in real foreign text. A Cyrillic "а" is correct in a Russian word. Only replace look-alikes inside Latin words.
- Searching with a normal regex.
\sin JavaScript does not match U+200B. Use a tool that checks code points.
FAQ
What is a zero-width space? It is the Unicode character U+200B. It has no width, so you cannot see it, but programs treat it as a real character.
Why does my code say "unexpected character" when the line looks fine? Most often there is a zero-width space, a BOM or a non-breaking space in it. Paste the line into the detector to see it.
How do I remove a BOM from a file? Drop the file into the tool, keep "Remove BOM" checked, and download the cleaned file. In VS Code you can also click the encoding in the status bar and choose "Save with Encoding → UTF-8".
Does trim() remove zero-width spaces?
No. In JavaScript trim() removes normal whitespace and NBSP, but not U+200B. Use str.replace(/[\u200B-\u200D\u2060\uFEFF]/g, '').
Is my text uploaded anywhere? No. The tool runs 100% in your browser. Nothing is sent to a server.
Try it now: Invisible Character Detector & Remover →
Related tools: Whitespace Remover, Find and Replace, Text Diff, Word Counter, HTML Entity Encoder, Log Sanitizer.