Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<p> instead of <br />

I've been wondering if I can use <p>&nbsp;</p> (just space in paragraph) instead of <br />

Because I love to keep my code semantic and thought if this is right has been bothering me for a while now. I have seen WYSIWSG editors (TinyMCE) use this, but I still rather ask then do it wrong.

like image 556
usoban Avatar asked Jul 09 '09 12:07

usoban


People also ask

Is P same as BR?

The p tag is a block level element, and is mainly used to add content, whereas the br tag is used to force a line-break within the element.

Can you put BR in P?

The br tag It's an inline element, and does not need a closing tag. We use it to create a new line inside a p tag, without creating a new paragraph. And compared to creating a new paragraph, it does not add additional spacing.

What is use of P and BR tag in HTML?

When it comes to learning HTML, two tags that most people learn early on are the paragraph and line break tags, which are <p> and <br /> respectively. These tags put natural breaks in your text so that your web page's content is easier to read.

Does P need </ p?

The <p> element is used to identify blocks of paragraph text. The closing <p> tag is optional and is implied by the opening tag of the next HTML element encountered in an HTML document after an opening <p> tag.


3 Answers

That is not "semantic", an empty paragraph is something that more or less cannot exist, semantically. It contains no information, i.e. no semantic content. All it does is change the visual layout, i.e. the presentation.

You're far better off using styling to change the margins, borders or padding to achieve the effect you're after.

like image 180
unwind Avatar answered Nov 24 '22 03:11

unwind


What's wrong with using the margins of the paragraphs for vertical-spacing instead?

<p>Hello World</p>
<p>This is much cleaner than using empty tags with non-breaking spaces.</p>
like image 30
Sampson Avatar answered Nov 24 '22 03:11

Sampson


The right way to do it is with CSS: use the margin-top or margin-bottom.

<p>&nbsp;</p> is pretty horrible... I'd rather see <br> than that (even though it may be less "correct").

like image 30
Greg Avatar answered Nov 24 '22 02:11

Greg