Entity: Non-breaking Space

A common character entity used in HTML is the non-breaking space. Browsers will always truncate spaces in HTML pages. If you write 10 spaces in your text, the browser will remove 9 of them. To add real spaces to your text, you must use the character entity.

For a non-breaking space, use   (name) or   (number)

HTML file: Displayed by browser:
<p>Each     word     has     five     spaces     between     them.</p> <hr />

<p>Each
&nbsp;&nbsp;&nbsp;&nbsp;     word
&nbsp;&nbsp;&nbsp;&nbsp;     has
&nbsp;&nbsp;&nbsp;&nbsp;     five
&nbsp;&nbsp;&nbsp;&nbsp;     spaces
&nbsp;&nbsp;&nbsp;&nbsp;     between
&nbsp;&nbsp;&nbsp;&nbsp;     them.</p> <hr />

<p>The second paragraph has 4 space entities between each word, as well as a space. The browser still displays the space and each entity, so that gives us five spaces between each word.</p>

Each word has five spaces between them.


Each      word      has      five      spaces      between      them.


The second paragraph has 4 space entities between each word, as well as a space. The browser still displays the space and each entity, so that gives us five spaces between each word.

Remember, the browser ignores multiple spaces, which is why the first paragraph displays with only one space between each word.

Back button Table of Contents Next button