views:

386

answers:

8

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.

+15  A: 

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>
Jonathan Sampson
Let's say I have margin, but when creating form, I want button to have bigger margin and it's quite stupid to create new class just for particular purpose.
usoban
If you must, you could just do `<p style="border-bottom: 5em;">Hello World</p>`. Better than a blank paragraph.
ceejayoz
I'd go for different classes of <p> in your case.
SurDin
+7  A: 

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

Greg
+32  A: 

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.

unwind
Yes, layout, as well as design, is to be handled by css. Html should be used only to decorate the presentation.
Mercer Traieste
Appearance in the browser should be dictated by CSS design. HTML/XHTML is meant to control meaning, not appearance.For instance, the <i> and <b> tags have been deprecated for <strong> and <em>. This way, the HTML author can dictate what he wants to emphasize, but doesn't dictate how that emphasis appears in the browser. The CSS associated with the HTML page would control how that emphasis should be shown (maybe bold text only, maybe red text on a yellow background, or any design mishmash).
taserian
Except <i> and <b> have *not* been deprecated in HTML and *are* semantic when marking up a mandated stylistic change---such as for book and article titles.
Roger Pate
+2  A: 

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

J. Pablo Fernández
+1  A: 

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.

Sam DeFabbia-Kane
+2  A: 

You should set the space between the paragraphs with css.

Fernando
+2  A: 

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.

geowa4
A: 

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.

aberrant80
Semantic markup is where the html tags confer meaning to their content. For example, semantic <p>...</p> would actually contain a paragraph of text and semantic <address>...</address> would actually contain an address. Non-semantic markup would be like the example in the question where there is an empty paragraph. In that example, the <p> tag doesn't actually describe a paragraph. Other historical examples are transparent gifs and tables to lay out the page. Here is an article describing the topic: http://www.digital-web.com/articles/writing_semantic_markup/
Peter Stephens
Just to get picky: the address element isn't for an address in the sense of a physical location; it's for "contact information for a document or a major part of a document such as a form". The example given in the HTML 4.01 spec shows links, with no address (not even an email address) in sight: http://www.w3.org/TR/html401/struct/global.html#edef-ADDRESS
NickFitz
+1, I stopped caring about semantic in HTML source a long time ago.
Joshua
Wow, I guess there's always a first time to getting so many negatives.
aberrant80
@Joshua - I agree. Look at a Drupal or Wordpress template some time and tell me that a dozen nested `DIV`s are in any way "semantic".
detly