8

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?

3
  • 2
    I smell a religious argument... Commented Jan 29, 2010 at 22:43
  • what is so funny with this question? Commented Jan 29, 2010 at 22:57
  • 1
    Nothing really, but there are no 'pros' of positioning elements with &nbsp; and <br /> unless you are drawing ASCII art. This is a major reason for the existence of CSS. Commented Jan 29, 2010 at 23:12

6 Answers 6

7

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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?
@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.
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.
4

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

Comments

2

In HTML5 you also have the new http://html5doctor.com/element-index/#w

the answer is not black and white, it depends on your content, sometimes it should be
and in some cases the   so the content will be on a single line.

if you want it as block you can use

Comments

1

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 ;)

Comments

1

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

Comments

0

Using CSS margin and padding will give you greater flexibility to make adjustments later on.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.