+5 votes
79 views
in Tips & Tricks by (242k points)
reopened
HTML: Write non-breaking spaces - this is how it works

1 Answer

+3 votes
by (1.6m points)
 
Best answer

Include non-breaking spaces in HTML

Would you like to write a non-breaking space with HTML? We'll show you how..

image image

Non-breaking spaces can be very useful, especially in HTML code. A non-breaking space ensures that the expressions to the right and left of the space cannot be separated by a line break. An example of the need for non-breaking spaces would be to write a number and its unit. The number and its unit must stand together, so they should not be separated by a line break. With a normal space it can happen that the number remains in the line and the unit word slides one line lower. A non-breaking space can prevent this, so that all characters are then on the same line.

Include non-breaking spaces in HTML

Creating a non-breaking space in HTML is actually very easy. You have to   insert "" instead of an actual space . This seemingly cryptic character sequence stands for "non-breaking-space", ie for a space that cannot be broken. You have thus created your non-breaking space directly. So an example would be:

Text Text Text Text 3 €

If it's not just about a single space, but a whole line of text, you can also <nobr> frame the text instead . This stands for "no breaking" and ensures that your whole line isn't broken apart. An example text would be:

<nobr>Diese Zeile wird nicht gebrochen.</nobr>


Note:
Some HTML editors have a problem with the "<nobr>" expression. Instead, you should only use the non-breaking spaces with "& nbsp;" to use.


...