What Is  ? The Non-Breaking Space Explained

Try the HTML Entity Encoder
Article illustration: What Is  ? The Non-Breaking Space Explained

  is the HTML entity for a non-breaking space — a space character that the browser treats as part of a word rather than as a place where text can wrap or collapse. It is the single most-searched HTML entity, and also the one most often used by accident. This guide covers what it does, when it is the right tool, and the messes it tends to create.

The name says it all: it is a space that will not break. Where a normal space lets the browser wrap to a new line and collapses runs of whitespace down to one, a non-breaking space does neither. It glues the characters on either side together and is preserved exactly as written.


The Two Things   Actually Does

1. It prevents line breaks

The browser will never wrap a line at a non-breaking space. The text on both sides stays on the same line, even if that pushes past the edge of the container.

<!-- "10" and "kg" can end up on different lines -->
<p>The package weighs 10 kg.</p>

<!-- "10 kg" is now guaranteed to stay together -->
<p>The package weighs 10&nbsp;kg.</p>

This is the legitimate, intended use: keeping units, names, dates, or short phrases from being split awkwardly across lines — Mr.&nbsp;Smith, 100&nbsp;km/h, Figure&nbsp;3.

2. It does not collapse

HTML collapses any run of regular whitespace — spaces, tabs, newlines — down to a single rendered space. Non-breaking spaces are exempt, so they are preserved one-for-one.

<!-- renders as a single space -->
<p>Hello&#32;&#32;&#32;World</p>

<!-- renders as four visible spaces -->
<p>Hello&nbsp;&nbsp;&nbsp;&nbsp;World</p>

This second behavior is why &nbsp; gets abused as a layout tool — and why it causes so many problems, which we will get to.


&nbsp; vs &#160; vs &#xA0; vs U+00A0

These are four ways of writing the exact same character. There is no rendering difference whatsoever:

Notation Form Where it comes from
&nbsp; Named entity HTML's friendly name
&#160; Decimal entity Unicode code point 160 in base 10
&#xA0; Hex entity Code point 160 in base 16 (A0)
U+00A0 The raw character The actual byte(s) in a UTF-8 file

The character is Unicode code point U+00A0, "NO-BREAK SPACE". &nbsp; is simply the easiest of the four to read and type, which is why it dominates. If you ever see &#160; or &#xA0; in someone's source and wonder what it is, paste it into the HTML entity decoder — it will resolve to a non-breaking space.

A subtle point: U+00A0 is not the only non-breaking space in Unicode. There is also a narrow no-break space (U+202F) and a word joiner (U+2060). For ordinary web work, &nbsp; / U+00A0 is the one you want.


How to Type a Non-Breaking Space

You rarely type the raw character; you usually write the entity. But when you do need the literal character:

  • In HTML/source code: write &nbsp; — this is almost always the right answer.
  • Windows: hold Alt and type 0160 on the numeric keypad.
  • macOS: press Option + Space.
  • Word / Google Docs: Ctrl + Shift + Space (Windows) or Option + Space (Mac) inserts one as you type.
  • In a JavaScript string: use ' '.

The catch with the keyboard shortcuts is that they insert the invisible raw character, which looks identical to a normal space in your editor. That is the root of an entire category of bugs.


The Pitfalls: Where &nbsp; Goes Wrong

Rich-text editors and pasting from Word

This is the big one. When you paste content from Microsoft Word, Google Docs, or a WYSIWYG/CMS editor (TinyMCE, CKEditor, the WordPress block editor), those tools frequently convert ordinary spaces into non-breaking spaces — especially multiple spaces, spaces after a sentence, or spaces used for indentation.

The result is source code peppered with &nbsp; or invisible U+00A0 characters where plain spaces belong:

<p>This&nbsp;looks&nbsp;normal&nbsp;but&nbsp;every&nbsp;space&nbsp;is&nbsp;an&nbsp;nbsp.</p>

Symptoms include text that refuses to wrap properly, justified text with strange gaps, search that fails to find a phrase (because the "space" is not a real space), and string comparisons that fail for no visible reason.

Using &nbsp; for layout

Because non-breaking spaces do not collapse, people use strings of them to indent paragraphs, create gaps between elements, or push content around:

<!-- Don't do this -->
<p>&nbsp;&nbsp;&nbsp;&nbsp;Indented the wrong way.</p>

This is fragile and inaccessible. Screen readers may announce the spaces, the spacing breaks at different font sizes, and it is impossible to maintain. Use CSS instead — margin, padding, text-indent, or gap. Reserve &nbsp; for keeping words together, never for visual spacing.

Invisible characters in data

A U+00A0 hiding at the end of a form field, a CSV cell, or a database value will quietly break trim(), equality checks, and lookups, because the standard whitespace trimmers in many languages do not strip it by default. If a value "looks right" but comparisons fail, suspect a stray non-breaking space.


How to Find and Clean Up Stray &nbsp;

Decode to see what is really there

Paste suspect text into the encoder/decoder tool. Encoding the text will reveal hidden non-breaking spaces as visible &nbsp; or &#160; tokens, so you can see exactly where they are before deciding what to do.

Replace in code

To collapse non-breaking spaces back to ordinary spaces:

// JavaScript: replace the raw U+00A0 character
text = text.replace(/ /g, ' ');

// Also normalize the literal entity if present
text = text.replace(/&nbsp;/g, ' ');
// PHP
$text = str_replace("\xC2\xA0", ' ', $text); // UTF-8 bytes for U+00A0
$text = str_replace('&nbsp;', ' ', $text);
# Python
text = text.replace(' ', ' ').replace('&nbsp;', ' ')

Trim that catches it too

In JavaScript, the built-in String.prototype.trim() already removes U+00A0. In other languages you may need an explicit character class — for example Python's str.strip() does strip U+00A0 because it counts as whitespace, but a naive custom regex like [ \t] will not.


FAQ

Is &nbsp; the same as a regular space?

No. They look identical on screen but behave differently. A regular space allows line wrapping and collapses with adjacent whitespace; a non-breaking space does neither. They are also different characters at the byte level (U+0020 vs U+00A0), which is why one can be found by search and the other cannot.

When should I actually use &nbsp;?

To keep two pieces of text on the same line: between a number and its unit (5&nbsp;MB), inside a name or title (Dr.&nbsp;Lee), before a trailing reference (see&nbsp;§4), or to stop a single short word from dropping to a line by itself. That is essentially the whole list. For spacing and indentation, use CSS.

Why does my page have so many &nbsp; I did not add?

They almost certainly came from pasting content out of Word, Google Docs, or a rich-text/CMS editor, all of which convert spaces to non-breaking spaces under various conditions. Paste the content into the decoder to find them, then clean them with a find-and-replace as shown above.

Does &nbsp; affect SEO or accessibility?

Used correctly, no. Abused as a layout hack, it can hurt accessibility — screen readers may read out runs of spaces, and content reflow breaks at different zoom levels. Search engines also normalize whitespace, so phrases stitched together with non-breaking spaces can read oddly to a crawler. Keep it to its intended job.

What is the Unicode value of a non-breaking space?

It is U+00A0 (decimal 160), named "NO-BREAK SPACE". In HTML you can write it as &nbsp;, &#160;, or &#xA0; — all three are the same character. Other no-break variants exist in Unicode (such as the narrow U+202F), but U+00A0 is the standard one.

How do I type a non-breaking space without writing the entity?

On Windows, hold Alt and type 0160 on the numeric keypad. On macOS, press Option + Space. In word processors, Ctrl + Shift + Space usually works. Be aware these insert the invisible raw character, which is easy to lose track of in source — writing &nbsp; is clearer.

Encode HTML Entities Instantly

Encode and decode HTML entities with named, decimal, and hex output, Unicode support, and client-side processing.

Open HTML Entity Encoder