What Is a Zero-Width Space?
A zero-width space is an invisible Unicode character with the code U+200B. It takes no room on the line. Its job is to mark a place where a line of text is allowed to break.
The short name is ZWSP. This guide explains what the zero-width space does, how it differs from similar characters, how to type or copy it, what goes wrong when it hides in a text, and how to remove it.
What does a zero-width space do?
A zero-width space tells the software that a line may be broken at that point. The Unicode rules for line breaking describe its job as providing a break opportunity, and they name it as the way to allow a break by hand around letters or symbols.
| Text | On a wide line | On a narrow line |
|---|---|---|
| A long word without a zero-width space | Stays in one piece | Runs over the edge or breaks at a random place |
| The same word with a zero-width space in the middle | Looks exactly the same, no gap | Breaks at the marked place, without a hyphen |
That is its use in normal writing: long links, long file paths and languages that do not put spaces between words, where the software needs help to find the place for a line break.
Zero-width space facts
| Property | Value |
|---|---|
| Name | Zero width space |
| Short name | ZWSP |
| Code point | U+200B |
| Width | None |
| HTML code | ​ or ​ |
| Size in UTF-8 | 3 bytes |
| In a link, percent-encoded | %E2%80%8B |
HTML also has an element with the same effect. MDN Web Docs states that the wbr element, a word break opportunity, behaves like the U+200B zero-width space. Neither of them adds a hyphen at the break.
Zero-width space vs similar characters
Four invisible characters with no width are often mixed up. Two of them do the opposite of the zero-width space.
| Character | Code | What it does |
|---|---|---|
| Zero width space | U+200B | Allows a line break at that place |
| Word joiner | U+2060 | Prohibits a line break before and after it |
| Zero width joiner | U+200D | Joins the characters on both sides, as in combined emojis |
| Zero width non-joiner | U+200C | Keeps two letters from joining |
The no-break space, U+00A0, is different again. It is a visible gap with the width of a space, and it keeps two words on the same line. All the types are compared in invisible characters explained.
Is a zero-width space a space?
Not in the way a word counter or a search understands a space. It does not separate words. We ran a short text through the counting code of our own Word Counter.
| Text | Words | Characters |
|---|---|---|
| wordword and more | 3 | 17 |
| The same text with a zero-width space inside "wordword" | 3 | 18 |
The word count stays the same, because the zero-width space does not split the word. The character count goes up by one. This is how a hidden character can push a text over a limit that it seems to respect.
What problems does a zero-width space cause?
- Two texts that look the same are different. "hello" with a zero-width space in the middle has six characters, not five, and does not equal the normal word.
- Search fails. A search for the normal word does not find the one with the hidden character.
- Logins fail. A username or password pasted with a zero-width space does not match the stored one.
- Links break. In an address the character becomes %E2%80%8B, and the page is not found.
- Code fails. A zero-width space inside a name or a number is an error that the eye cannot find.
It mostly arrives through copy and paste from web pages, documents and chat apps, where it was put on purpose to help long words break.
How to copy a zero-width space
There is no key for it on a keyboard, so it is copied. In our invisible character tool, choose Zero width space, set the number and press Copy. In HTML, write ​ at the place where a break is allowed.
Paste it in the Test it here box of the tool to make sure it was copied. The box looks empty, and the count of invisible characters shows 1.
How to remove a zero-width space
Because you cannot select what you cannot see, a zero-width space is removed by its code. In a tool that supports regular expressions, search for the code and replace it with nothing.
- Paste the text in a find and replace tool. The Find and Replace tool on this site works for this.
- Turn on Use a regular expression.
- In the find box, type the six characters \u200B. Leave the replace box empty.
- Read the result. The line Replacements above it shows how many were found and removed.
We tested this with our own tool: one zero-width space in a text of 18 characters was found and removed, and 17 characters were left. For other hidden characters, see the guide on how to remove invisible characters.
Frequently asked questions
- What is the Unicode code of the zero-width space?
- U+200B. In HTML it can be written as ​ or ​.
- Does a zero-width space count as a character?
- Yes. It adds one to the character count, although nothing is shown.
- Does a zero-width space separate words?
- No. A word with a zero-width space inside is still counted as one word by our Word Counter.
- How do I type a zero-width space?
- There is no key for it. Copy it from a tool such as our Invisible Character page, or write ​ in HTML.
- What is the difference between a zero-width space and a word joiner?
- They are opposites. A zero-width space allows a line break at its place. A word joiner, U+2060, prohibits one.