ajsie
ajsie

Reputation: 79686

Spaces and new lines with HTML and CSS

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?

Upvotes: 7

Views: 67226

Answers (6)

RookVenkatesan
RookVenkatesan

Reputation: 1

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

Upvotes: 0

CodeWizard
CodeWizard

Reputation: 142114

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

Upvotes: 1

prodigitalson
prodigitalson

Reputation: 60413

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

Upvotes: 1

Robert Harvey
Robert Harvey

Reputation: 180788

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

Upvotes: 4

Januz
Januz

Reputation: 527

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

Upvotes: 1

BalusC
BalusC

Reputation: 1108732

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.

Upvotes: 7

Related Questions