Advertisement
Advertisement


What's the difference between " " and " "?


Question

Both of them mean space, but is there any difference?

2009/08/31
1
150
8/31/2009 12:25:57 PM

Accepted Answer

One is non-breaking space and the other is a regular space. A non-breaking space means that the line should not be wrapped at that point, just like it wouldn’t be wrapped in the middle of a word.

Furthermore as Svend points out in his comment, non-breaking spaces are not collapsed.

2012/02/01
199
2/1/2012 8:10:46 AM

The entity   produces a non-breaking space, which is used when you don't want an automatic line break at that position. The regular space has the character code 32, while the non-breaking space has the character code 160.

For example when you display numbers with space as thousands separator: 1 234 567, then you use non-breaking spaces so that the number can't be split on separate lines. If you display currency and there is a space between the amount and the currency: 42 SEK, then you use a non-breaking space so that you don't get the amount on one line and the currency on the next.

2009/08/31

In addition to the other answers here, non-breaking spaces will not be "collapsed" like regular spaces will. For example, both

<p>Word1          Word2</p>

and

<p>Word1 Word2</p>

will render the same on any browser, while

<p>Word1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Word2</p>

will keep the spaces when rendered.

2014/03/05

Not an answer as much as examples...

Example #1:

<div style="width:45px; height:45px; border: solid thin red; overflow: visible">
    Hello&nbsp;There
</div>  

Example #2:

<div style="width:45px; height:45px; border: solid thin red; overflow: visible">
    Hello There
</div>

And link to the fiddle.

2019/06/27

You can see a working example here:

http://codepen.io/anon/pen/GJzBxo

and

http://codepen.io/anon/pen/LVqBQo

Same div, same text, different "spaces"

<div style="width: 500px; background: red"> [loooong text with spaces]</div>

vs

<div style="width: 500px; background: red"> [loooong text with &nbsp;]</div>
2015/08/06

Multiple normal white space characters (space, tabulator and line break) are treated as one single white space character:

For all HTML elements except PRE, sequences of white space separate "words" (we use the term "word" here to mean "sequences of non-white space characters"). When formatting text, user agents should identify these words and lay them out according to the conventions of the particular written language (script) and target medium.

So

foo    bar

is displayed as

foo bar

But no-break space is always displayed. So

foo&‍nbsp;&‍nbsp;&‍nbsp;bar

is displayed as

foo   bar
2009/08/31

Source: https://stackoverflow.com/questions/1357078
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]