HTML entity for a non-breaking space

  /   /  

  is the HTML entity for a non-breaking space, U+00A0 NO-BREAK SPACE.   and   are the same character as decimal and hex references, and in UTF-8 it’s the two bytes C2 A0. It looks like a space, but a line never breaks there, and HTML doesn’t collapse it into the spaces around it.

Character    U+00A0 NO-BREAK SPACE
Named              (HTML5 also reads  )
Numeric             
UTF-8        C2 A0

Find the ones you can’t see

You can’t see a non-breaking space in an editor, so it’s one of the few characters worth writing as an entity even in a UTF-8 page. Encoding 10 km from St. Louis, with U+00A0 after 10 and after St., shows where they are:

10 km from St. Louis

They often arrive by paste, from word processors and web pages, and they break exact matches: '\u00A0' === ' ' is false. JavaScript’s trim() and \s do count U+00A0 as white space, and so do Python’s str.split() and str.isspace().

When to use it

Use it to keep together what shouldn’t be split across lines: a number and its unit (10 km), an abbreviation and what follows (Fig. 3, § 5), an initial and a surname. Don’t stack     to indent or space things out; that’s what margin, padding and gap are for.

For a phrase longer than two words, CSS is tidier than a chain of entities. white-space: nowrap keeps the whole element on one line:

<span style="white-space: nowrap">New York City</span>

In JSX, Markdown, CSS and XML

JSX decodes &nbsp; in text and in quoted attributes when it compiles, but a string in braces is plain JavaScript, so {'&nbsp;'} renders those six characters. Write {'\u00A0'} there. The similar-looking {' '} is the JSX idiom for an ordinary space between elements, because JSX drops the whitespace at line breaks.

<p>10&nbsp;km</p>          // 10 km, joined
<p>{'10&nbsp;km'}</p>      // the text 10&nbsp;km
<p>{'10\u00A0km'}</p>      // 10 km, joined

CommonMark decodes &nbsp; in Markdown text, but inside a code span it stays literal. In CSS generated content the character is \a0, and the escape swallows one space after it: content: "10\a0 km" is 10, U+00A0 and km, with no second space. &nbsp; is an HTML name, not an XML one: an RSS feed or a standalone SVG file needs &#160;.

Try it in the HTML Entity Encoder & Decoder

Encoded

2 characters become a reference, named where a name exists and &#x…; where one doesn’t.

Encoding always escapes &amp;, &lt;, &gt;, &quot; and &#39; — the characters that mean something to an HTML parser.

Runs in your browser. Nothing you enter is sent anywhere.