tags:

views:

70

answers:

4

Should I use <br /> and &nbsp; in HTML to position elements, or should I just use CSS display:inline with padding/margin for positioning and all styling? what are pros and cons with both?

+2  A: 

<br /> has its uses, but if you find yourself using &nbsp a lot, I would consider finding better ways to align things. &nbsp; is just ugly and clunky.

If it's tabular data, use a table. Your life will be much happier.

If it's not tabular data, use css, as BalusC suggests.

Robert Harvey
+3  A: 

Use <br> to represent a linebreak inside a block element and use &nbsp; to represent a non-breaking space inside an inline element. Nothing more. For the remnant just use CSS the smart way with help of under each the display, float, padding and/or margin properties.

BalusC
when i use display:inline on a span element another element is still positioned to the right of the span element. shouldnt that one be in the next line?
weng
@noname: no a `span` is an inline element and thus display inline does nothing to it. if you want the element on a new line use `display: block`.
prodigitalson
A `span` is by default already inline. Either use a linebreak, or a block element, or close the parent block element and start a new block element.
BalusC
+1  A: 

Ideally you should position everything with css, and only use <br /> (line break) and &nbsp; inside <p>s. But this isn't an ideal world ;)

Januz
it still has IE 6 in it...
CrazyJugglerDrummer
+1  A: 

<br /> Can really go either way. But if you find yourself using it to adjsut paragraph spacing orsomething like this then you really have to ask yourself "is there a reason why im using breaks instead of applying a class to adjust margins?" &nbsp; on the other rarely if ever makes any kind of sense outside of a paragraph (<p />) and half the time theres not much use for it ther any how as using text-indent is preferable for indenting the first paragraph and much to the chigirn of Editors everywhere im completely opposed to the double space prepending of senetences on the web - as far as im concerned that is a print only thing.

prodigitalson