Because of the way HTML defines white space, it is not possible to control where lines of text break (such as marking up a postal address as a paragraph, but wanting the visual appearance to have each part of the address appear on a separate line) by simply pressing the Return key whilst writing the text.
A line break can be introduced into the document using the <br> element. However, this should only be used to force line breaks where they are required, and never to apply more vertical spacing between paragraphs or such in a document—that is more properly done with CSS.
Sometimes it might be easier to use the preformatted text block rather than inserting br elements. Or, if one particular part of some text is desired to be on a line by itself, but this is just a styling issue, it can be surrounded by a <span> element and set to display as a block level element.
So for example you could write the Opera contact address seen earlier in this article when talking about the address element like this instead:
<p>Our company address: </p<
<address<
Opera Software ASA,<br<Waldemar Thranes gate 98,<br<
NO-0175 OSLO,<br<NORWAY
</address<
The <br> element’s purpose is very simple: it creates a line break within a block of text, leaving no padding or margins between the two blocks of text created by the line break. While it’s still perfectly valid to use this element in XHTML Strict pages (it’s not on the list of deprecated elements), you need to take care that you don’t misuse it, because:
- It can be used in a presentational manner. For example, you might use a series of
<br> elements in succession to create a new paragraph effect, instead of simply using <ar> or a <blockquote>, and applying CSS to set the layout.
- Using
<br> elements becomes a real headache if, later, you want to correct visual inconsistencies and have to sweep through hundreds of files to strip them out.
There are some exceptional cases in which you might be forced to use a <br> element:
- In poetry, a new line requires just that: a new line. You can’t use a
<p> element in this case. (Evidently poetry wasn’t high on the list of markup requirements when the HTML recommendations were thrashed out!)
- When you’re marking up a postal address, you may need to create single line breaks. However, with the advent of Microformats, there’s quite a well-established method for dealing with postal (and other) address types that avoids the use of the
<br> while offering additional semantic richness. Refer to the section titled http://reference.sitepoint.com/html/hcard/ for more.
The <br> element is a self-closing element and doesn’t contain any content or values.
A line break (<br />) is mostly a presentational tool, and should be handled by CSS rather than HTML. However, there are a few cases where line breaks can be said to have semantic meaning, for instance in poetry, song lyrics, postal addresses and computer code samples. These can constitute legitimate uses for <br />, but using <br /> to separate paragraphs (<p>) is definitely an abuse of the <br /> element.