Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spaces and new lines with HTML and CSS

Tags:

html

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?

like image 232
ajsie Avatar asked Jan 29 '10 22:01

ajsie


2 Answers

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.

like image 98
BalusC Avatar answered Oct 23 '22 18:10

BalusC


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

like image 39
Robert Harvey Avatar answered Oct 23 '22 19:10

Robert Harvey