tags:

views:

636

answers:

14

Hi,

Is it something bad to use <BR/> tags? Why I ask this is, in our development team it was one of the first advices to me not use <BR/> but to use styles.

But why? Are there some negative outcomes to use <BR/> tags?

Thanks.

+21  A: 

I think your development team is refering to <br /> in place of margin spacing. To make empty space between elements, use padding / margin styling via CSS.

Bad use of <br />:

<div>
   Content
</div>
<br />
<br />
<br />
<br />
<div>
     More content...
</div>

Good use of <br />:

<style>
     div {
          margin-top:10px;
     }
</style>

<div>
   Content<br />
   Line break
</div>

<div>
     More content...
</div>
iamkoa
+1: br's are not to be used to visually add margin/padding.
BalusC
You can't just remove your <br>s and add CSS, because if you've removed your <br>s there's nothing *to* style. It's not incredibly helpful to say "remove your line breaks" without helping (literally) fill in the blanks
Gareth
@Gareth - Added examples. :}
iamkoa
+1  A: 

One issue is that this is valid in XHTML but not valid in HTML 4.0.1. In HTML 4.0.1 you would write <br>.

A second issue is that <br> is generally speaking a crude, old-fashioned way of doing formatting. The more flexible, modern way is to use <p> or <div> elements together with CSS for styling.

Stephen C
In HTML you use `<br>`.
BalusC
You commented too quickly :-)
Stephen C
I think you're missing the point.
Mark
Actually, I'm saying there could be multiple points. The only way to know what the OP's dev team really mean is to ask them!!
Stephen C
+3  A: 

Specifying the layout directly makes it difficult adapting the site for different page sizes or fonts for example.

Martin Beckett
A: 

I try to write my markup in a way that it's easily readable with CSS disabled. If you're just using BRs to add spacing, it's better to use margins and padding.

BStruthers
+3  A: 

What was meant by your team was probably not to use <br>s to split between paragraphs.

<p>I am a paragraph</p>
<p>I am a second paragraph</p>

is the better way to do that, because you can then easily adjust the spaces between paragraphs through CSS. Other than that, I can not think of anything speaking agains line breaks as such.

Pekka
+11  A: 

Generally, <br/> is an indication of poor semantic HTML. The most common case is using <br/> to declare paragraph separations, which there are much better ways to do it semantically. See Bed and BReakfast.

There are occasions where it is the proper tag to use, but it is abused often enough that people adopt a "do not use" mentality as to force better semantic thinking.

fengb
A: 

They are to be used to represent newlines. Nothing more. Not to fill up space like as at the average geocities site. There is however only one case wherein they may be useful for other purposes than putting a newline: to clear the floats.

<br style="clear: both;">
BalusC
Though used, this method isn't valid XHTML.
iamkoa
You can often get around this "hack" by using `overflow:auto` on the containing element instead.
Mark
@iamkoa: I don't use XHTML. HTML is HTML, not XML.
BalusC
@Mark: with pressure on *often*: http://www.quirksmode.org/css/clearing.html
BalusC
+6  A: 

The main reason for not using <br> is that it's not semantic. If you want two items in different visual blocks, you probably want them in different logical blocks.

In most cases this means just using different elements, for example <p>Stuff</p><p>Other stuff</p>, and then using CSS to space the blocks out properly.

There are cases where <br> is semantically valid, i.e. cases where the line break is part of the data you're sending. This is really only limited to 2 use cases - poetry and mailing addresses.

Gareth
A: 

They're fine, if used appropriately. For instance, you shouldn't use them in lieu of <p> tags or to create spacing between elements. You're probably doing something wrong if you ever have two in a row.

Mark
A: 

<br /> should be used for line breaks only, and not to apply style to a page. For example, if you need extra space between paragraphs, give them a class and apply the extra padding to the paragraphs. Don't spread out your paragraphs with <br /><br ><br />

Zoe
A: 

Don't use more than two consecutive <br> that's a signal you're using them for stylistic purposes and no, you shouldn't.

Some would say a single <br> is enough and instead of two you should use <p></p>, but i think there are situations (e.g. screenplays) in which you want to introduce a longer pause without implying a change of topic or a new period starting, like a paragraph usually does.

ZJR
A: 

I will generally always set appropriate margins and padding on elements using CSS - it's a lot less messy than loads of <br />s all over the place apart from being more semantically correct.

Probably the only time I would use a <br /> in preference to the margins and padding set by CSS, even if it's not strictly technically correct, is if it was an isolated incident where slightly more space was needed. If I'd got quite a large stylesheet and it didn't seem worth setting up an additional style just for that one occurence, I may use a <br /> as a one-off.

Like most things, <br />s aren't a bad thing providing they're used correctly.

NeonBlue Bliss
A: 

<BR/> tags are really good to use but as we know when you use things too much they look annoying and really makes no sense, so in using <BR/> tags use them sparingly.

Dwayne
+1  A: 

Same concept applies to why we don't use tables for layout - use tables for tables and CSS for layout.

Use <br/> for break lines in a block of text and CSS if you want to affect the layout.

Dieter G