We've moved!

TechKnack.blogspot.com has officially moved to TechKnack.net. You should be redirected in 3-5 seconds. Thank you.

April 9, 2008

Do we really need the br element?

Add this post to Del.icio.us. Del.icio.us (0 saved)

Do we really need the lowly <br/> element? Apparently the W3C thinks so, with HTML5 containing the element. I mean, seriously, what does it do that a span styled with display:block; can't?

The last two times I've seen it used were in articles about creating a tableless photo gallery and making a CSS block nav menu. In both instances, the br was used to drop down the descriptive text to the next line. In both instances, a span surrounding the descriptive text, and with its display set to block, does the exact same thing.

I suppose an argument could be made about users with CSS turned off. In my opinion, though, if you have CSS turned off, you're willing to deal with a few minor inconveniences. If you're that worried about them, throw in a space before the span for readability. And if you really insist on giving them the extra lines of text -- there's always the naturally-block-level <div>.

And what about screenreaders? I doubt they'd be affected either way (it is whitespace, after all -- right?), but I really have no clue. Perhaps someone who uses a screenreader could tell me, after chewing me out about my own blog's (actually Blogger's) screenreader-friendliness. :o


Anonymous said...

The <br /> element is both unnecessary and incorrect in both the examples you cited, but there are places where it's needed, like addresses and other things that must appear on multiple lines but are logically part of the same line of text:

John Doe<br />
123 Main St.<br />
Anytown, USA 12345

Or line breaks within paragraphs, which are common in longer books (there are a few in every reference book on my shelf) but aren't seen very often on the web. I'm fairly certain this use is the whole reason the element exists in the first place.

EterniCode said...

Anonymous, to address your address example, I believe that it would be acceptable (even appropriate) to encapsulate the separate parts in separate spans (or divs, as the case may be, to allow sensible CSS-lessness). In fact, there's even an address microformat that does this (also check out the Microformats.org explanation of <address>).

I would agree about needing it for line breaks within a paragraph, however. This seems to be the only place where it is needed.