Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling of non breaking space: <p>&nbsp;</p> vs. <p> </p>

Tags:

html

css

space

&nbsp; is a non breaking space, which represents an empty space where no line break occurs.

If I use

<p>&nbsp;</p> 

I have a space between two passages (bigger break). If I use

<p> </p> 

I only have a new line between the two passage (no break). Why?

like image 413
grabner Avatar asked Sep 05 '12 10:09

grabner


People also ask

What is p >& NBSP?

&nbsp; is a non breaking space, which represents an empty space where no line break occurs. If I use <p>&nbsp;</p> I have a space between two passages (bigger break). If I use <p> </p> I only have a new line between the two passage (no break).

What is the code you would use for a non-breaking space?

Alternatively called a fixed space or hard space, NBSP (non-breaking space) is used in programming and word processing to create a space in a line that cannot be broken by word wrap. With HTML, &nbsp; lets you create multiple spaces that are visible on a web page and not only in the source code.

What does a non-breaking space do?

A nonbreaking space is the same width as a word space, but it prevents the text from flowing to a new line or page. It's like invisible glue between the words on either side.

What is &nbsp example?

A non-breaking space prevents line breaks from occurring at a particular point in an HTML document. To use a non-breaking space, you would use the following: &nbsp; For example, if you wanted the words "Mr."


1 Answers

In HTML, elements containing nothing but normal whitespace characters are considered empty. A paragraph that contains just a normal space character will have zero height. A non-breaking space is a special kind of whitespace character that isn't considered to be insignificant, so it can be used as content for a non-empty paragraph.

Even if you consider CSS margins on paragraphs, since an "empty" paragraph has zero height, its vertical margins will collapse. This causes it to have no height and no margins, making it appear as if it were never there at all.

like image 54
BoltClock Avatar answered Sep 20 '22 06:09

BoltClock