Question

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.

Was it helpful?

Solution

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>

OTHER TIPS

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.

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").

<p>&nbsp;</p> is not semantic, so I don't know how that helps you.

You should set the space between the paragraphs with css.

I advocate wrapping items in block-level tags, such as divs and ps. This way I don't need either. If you want to space out elements, you should be using margins. You can be more accurate with margins anyway.

In a situation where you're forced to have a line break, use <br />: it, unlike empty paragraph tags, actually does mean 'line break'. There's almost always a better way to do things though.

It's HTML. You can use whatever it wants as long as you're sure it will render the way you wanted on all the browsers you're gonna use. I don't understand what you mean by "keep my code semantic" so I'm not sure what your issue with <br> is. But if you're talking about formatting and such, turn to CSS.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top