What Is a Non-Breaking Space (NBSP)? How to Find and Replace It
A non-breaking space looks exactly like a normal space, but it behaves differently. It is one of the most common reasons that copied text will not match, will not wrap, or throws a strange error in code. Here is what it is and how to deal with it.
What is a non-breaking space?
A non-breaking space (NBSP) is the Unicode character U+00A0. It has two properties that a normal space does not:
- It prevents a line break at that position, so the words on both sides stay together on one line.
- In HTML, it is not collapsed. Browsers merge several normal spaces into one, but several
entities all stay.
In HTML it is written . In programming languages it is usually "\u00a0" or "\xa0".
What is it used for?
NBSP has real, good uses in typography:
- Keeping a number and its unit together, such as 10 km, so they never split across lines.
- Keeping a title and a name together, such as Dr. Smith.
- Avoiding a single word left alone at the end of a paragraph.
- In French and some other languages, a narrow non-breaking space is placed before certain punctuation marks.
Why does it cause trouble?
The trouble starts when an NBSP ends up where a normal space was expected. Common symptoms:
- Search and replace misses matches. Searching for two words separated by a normal space does not find them when the space between them is an NBSP.
- Strings that look equal are not equal, which breaks comparisons, lookups and de-duplication.
- Code fails to run. Pasting code with an NBSP in it can produce errors such as Python's invalid non-printable character U+00A0, or a JSON parser that rejects the input.
- Spreadsheet
TRIMdoes not clean it. TheTRIMfunction removes ordinary spaces only, so a cell can still look padded after trimming. - Lines refuse to wrap in a place where you expected them to.
Other unusual spaces
NBSP has several cousins. All of them look like a gap but are different characters:
| Code | Name |
|---|---|
U+00A0 | No-break space |
U+202F | Narrow no-break space |
U+2009 | Thin space |
U+2003 | Em space |
U+3000 | Ideographic space (full-width) |
How to type a non-breaking space
- Mac: press
Option+Space. - Windows: hold
Altand type0160on the numeric keypad. - HTML: write
.
How to find and replace non-breaking spaces
In the AI Text Cleaner
Paste your text. Any NBSP appears in the Characters found list as U+00A0. Keep Replace unusual spaces switched on and every one becomes a normal space.
In Microsoft Word
Open Find and Replace (Ctrl+H on Windows, Cmd+Shift+H on Mac). In the Find box, type ^s, which stands for a non-breaking space, and put a normal space in the Replace box.
In a spreadsheet
=SUBSTITUTE(A1, UNICHAR(160), " ")
Wrap it in TRIM if you also want to remove extra spaces afterwards:
=TRIM(SUBSTITUTE(A1, UNICHAR(160), " "))
In Python
clean = text.replace("\u00a0", " ")
In JavaScript
const clean = text.replace(/\u00a0/g, " ");
In Google Docs
Use Find and replace with Match using regular expressions ticked, search for \x{00A0} and replace it with a normal space.
When you should keep it
If you typeset a document on purpose, for instance a report where every number stays with its unit, those non-breaking spaces are doing their job. Replace them only in text that you will paste into code, a data file, a form or a system that compares strings.
Quick answers
What does nbsp stand for? Non-breaking space.
Is nbsp the same as a tab or several spaces? No. It is a single character that looks like one space but cannot wrap.
Why does copied text from a web page contain nbsp? Web pages often use for spacing, and the browser copies it as an NBSP character.
Can I just use find and replace with a normal space? Not if you type a normal space in the Find box; it will not match an NBSP. You need to search for the NBSP itself, as shown above.