Search this site...

Specifying line breaks — blank lines

Sometimes it becomes necessary to add a line break within a webpage. The effect of adding a line break to a web page is similar to pressing the enter key in a word processing software such as Microsoft Word. When you press the enter key in MS word, the current line is ended and the cursor moves to the next line. Similarly, when you add a line break into a webpage, the web browser renders that line break by ending the current line and starts a new line. If there is any content after the line break, the content will be automatically displayed on the next line. You may also add more than one line break for your web pages by simply using more than one line break tag.

Like in HTML, XHTML has the <br> tag to add a line break to a web page document. In XHTML, however, this tag must be closed; any one of the following versions are acceptable for adding blank lines to a web page:

  1. <br></br>
  2. <br />

In the first version above we open and close this tag separately. Because the <br> is an empty tag, we can open it and close it simultaneously as <br />. The <br /> tag is referred to as an empty tag because it does not contain any content inside. The shorter version saves you a few key strokes and still yields a valid XHTML document.

The following shows am example of the <br /> tag in use:

<p>
John decided to shop.<br />
He drove to a local shopping center.<br />
He discovered huge sales in his favorite stores.<br />
He went to a clothing store nearby.<br />
He purchased clothes for himself and his wife.<br />
He returned home.<br />
What did he say to his wife?<br />
Honey, I just purchased clothes...<br />
I saved over $1030 and spent only $375.<br />
Does she believe that?<br />
Time to see what is in the shopping bags.<br />
</p>

In this markup, we have added a <br /> tag to the end of each line. As a result, the browser renders this paragraph by placing each line on its own:

John decided to shop.
He drove to a local shopping center.
He discovered huge sales in his favorite stores.
He went to a clothing store nearby.
He purchased clothes for himself and his wife.
He returned home.
What did he say to his wife?
Honey, I just purchased clothes...
I saved over $1030 and spent only $375.
Does she believe that?
Time to see what is in the shopping bags.

Although you may add as many line breaks as you want to separate each line, it is suggested the use of style sheets to have more precise control over the amount of spacing used between lines.