What Is a Non-Breaking Space and Why Does It Break Copy-Paste?

A non-breaking space is a space character, U+00A0, that tells software not to break a line at that position. On screen it is indistinguishable from the ordinary space typed with the space bar, U+0020. To a computer the two are as different as a and b. That is the whole problem: copied text looks correct, yet it will not match, split, trim or sort as expected, because some of its spaces are not the character your formula, search or code is looking for.

The fix is to replace U+00A0 with U+0020 wherever text is going to be treated as data, and to leave it alone where it is doing its typographic job.

What a non-breaking space is for

When a line of text is wrapped, an ordinary space is a place where the line may end. A non-breaking space is a space where it may not, so the words on either side stay together. In the examples below, [NBSP] stands for the character:

10[NBSP]km
Mr.[NBSP]Smith
§[NBSP]5
7[NBSP]October

Without it, a paragraph can end one line with 10 and start the next with km.

Two relatives behave the same way at a different width. The narrow no-break space, U+202F, is a thinner version; French typography uses it as the thin unbreakable space set next to certain punctuation marks. The figure space, U+2007, is as wide as a digit and keeps a number together. Unicode’s line breaking rules treat all three as “glue” that holds its neighbours on one line.

Where non-breaking spaces come from

  • HTML. The entity   is the most common source. A browser collapses a run of ordinary spaces into one, so web pages and rich-text editors use   to keep two spaces in a row, to pad table cells and to indent. Copy from such a page into a document or a spreadsheet and the character can come along.
  • Word processors. In Word, Ctrl+Shift+Space inserts one on Windows and Option+Space does on a Mac. A shortcut that close to the plain space bar is easy to press by accident.
  • Number formatting. Software that formats numbers for French, Swedish, Polish and a number of other languages groups thousands with a no-break space, as in 1[NBSP]250,50.
  • PDFs and typeset documents, where a typesetter put them in on purpose.

What breaks, and why

Where What goes wrong
Search and find-and-replace Looking for New York does not find New[NBSP]York in any tool that compares characters exactly
Excel TRIM Leading and trailing [NBSP] stay in the cell. Microsoft documents that TRIM was designed for the 7-bit ASCII space, value 32, and does not remove the non-breaking space, value 160, by itself
Lookups and joins A lookup formula, a database join or a dictionary key treats Ana[NBSP]Silva and Ana Silva as two different values
Splitting Splitting on a space leaves 10[NBSP]km as one piece instead of two
Collapsing spaces A rule that turns two or more ordinary spaces into one does not touch a run made of space, [NBSP], space
Numbers 1[NBSP]250 is text, not a number, until the separator is gone
Code and data files JSON allows only space, tab and line breaks between values, and Python rejects U+00A0 in source code, so one stray [NBSP] produces a syntax error on a line that looks fine

Handling is not even consistent between tools, which is a large part of the confusion. JavaScript lists U+00A0 among its white space characters, so trim() removes it there; Excel’s TRIM does not. Whether \s in a regular expression matches it depends on the engine. The safe assumption is that it will not be treated as a space.

How to tell whether your text has them

  • In a spreadsheet, count them. =LEN(A2)-LEN(SUBSTITUTE(A2,UNICHAR(160),"")) returns the number of non-breaking spaces in A2. A cell that looks trimmed but is one character longer than expected is the usual sign.
  • In Word, search for ^s, which is Word’s Find code for a non-breaking space.
  • In a URL, a non-breaking space is encoded as %C2%A0, where an ordinary space is %20.
  • In garbled text, a stray  in front of a space means a UTF-8 non-breaking space was read with an older single-byte encoding.
  • In code, print an escaped form of the string. Python’s repr() shows the character as \xa0.
  • In the Text Cleaner, paste the text and press Clean Text. The summary lists only the changes that were actually made, so an entry such as 6 non-breaking spaces converted tells you they were there.

How to replace non-breaking spaces

In the Text Cleaner

  1. Paste the text into the Input Text box.
  2. Leave the preset on General Clean. Its Normalize non-breaking spaces option is on by default and converts U+00A0, U+202F and U+2007 into an ordinary space.
  3. Press Clean Text and copy the result.

The conversion happens before trailing spaces are trimmed and repeated spaces are collapsed, so those steps then apply to the converted characters as well.

Before

Ana[NBSP]Silva[NBSP]
Total:[NBSP][NBSP]1[NBSP]250[NBSP]kg

After

Ana Silva
Total: 1 250 kg

For this example the summary reads 6 non-breaking spaces converted, 1 line trimmed and 1 extra space removed. The cleaning runs in your browser and the text is not uploaded.

If your text contains the six literal characters   instead of the character itself, that is an HTML entity. Tick Decode HTML entities as well, or use the Plain Text preset: entities are decoded first, and the resulting non-breaking spaces are then converted. The guide to converting HTML to plain text covers the rest.

In Excel or Google Sheets

Replace the character first, then trim:

=TRIM(SUBSTITUTE(A2,UNICHAR(160)," "))

UNICHAR(160) is the non-breaking space by its Unicode number, and UNICHAR(8239) is the narrow no-break space if you need to replace that too. Many published formulas use CHAR(160) instead. That gives the same character in Excel for Windows and in Google Sheets, but Microsoft documents CHAR as using the Macintosh character set on a Mac, so UNICHAR is the safer spelling.

In Word

Open Find and Replace, type ^s in the Find box, type one ordinary space in the Replace box and replace all.

In code

Replace it before trimming or splitting:

JavaScript:  text.replace(/[\u00A0\u202F\u2007]/g, " ")
Python:      text.replace("\u00A0", " ")

When to keep it

Do not strip non-breaking spaces from prose that is going to be published as typeset text: a book or article manuscript, a page where numbers must stay with their units, French text with its punctuation spacing. There they prevent awkward line endings, and removing them undoes deliberate work. In the Text Cleaner, untick Normalize non-breaking spaces in the Whitespace card before cleaning that kind of text.

Convert them when the text is headed for a spreadsheet, a database, a form field, code, a search index or anything else that compares characters. The conversion never changes a word. The only cost is that a line may now wrap between 10 and km.

Non-breaking spaces rarely travel alone. Text from a word processor usually brings other passengers, described in the guide to cleaning text copied from Word and Google Docs. Characters with no width at all are covered in invisible Unicode characters, and ordinary doubled spaces and tabs in removing extra spaces and tabs.

Sources

  1. TRIM function — Microsoft Support
  2. CHAR function — Microsoft Support
  3. UAX #14: Unicode Line Breaking Algorithm — Unicode Consortium
  4. Lexical grammar — MDN Web Docs
  5. white-space CSS property — MDN Web Docs

This guide was drafted with AI assistance and reviewed by the publisher. See the editorial policy for how guides are written and corrected.