NBSP vs Regular Space: What’s the Difference?

At first glance, a non-breaking space (NBSP) looks identical to a regular space. However, under the hood, these are two completely different Unicode characters. Understanding the distinction between U+00A0 and U+0020 is essential for modern software development.

Regular Space (U+0020)

The standard space character used in ASCII and Unicode.

  • Code point: U+0020
  • Allowed in JSON whitespace
  • Breaks lines normally
  • 1 byte in UTF-8

Non-Breaking Space (U+00A0)

The non-breaking space prevents automatic line breaks. It is commonly inserted by HTML editors and rich text systems.

  • Code point: U+00A0
  • NOT valid JSON whitespace
  • Prevents line wrapping
  • 2 bytes in UTF-8

Why They Cause Bugs

Example of a broken JSON snippet:

{
 "name" : "admin"
}

If those spaces are U+00A0 instead of U+0020, JSON.parse() throws:

SyntaxError: Unexpected token

String Comparison Issues

"hello world" !== "hello world"

Even though they look identical, they are different byte sequences.

How NBSP Gets Inserted

  • Copying from Word or Google Docs
  • HTML content using  
  • CMS editors
  • Email copy-paste
  • AI generated formatted text

How To Detect NBSP

if (text.includes("\u00A0")) {
  console.log("Non-breaking space found");
}

How To Remove NBSP

text = text.replace(/\u00A0/g, " ");

Or clean automatically using:

Conclusion

NBSP (U+00A0) and regular space (U+0020) may appear identical, but they behave differently in parsers and string logic. Replacing non-breaking spaces with standard spaces prevents invisible debugging headaches.