Sams Teach Yourself HTML 4 in 24 Hours

Sams Teach Yourself HTML 4 in 24 Hours

By Dick Oliver

Paragraphs and Line Breaks

When a Web browser displays HTML pages, it pays no attention to line endings or the number of spaces between words. For example, the top poem in Figure 2.3 appears with a single space between all words in Figure 2.4. When the text reaches the edge of the Netscape window, it automatically wraps down to the next line, no matter where the line breaks were in the original HTML file.

02fig03.gif

Figure 2.3 In HTML, extra spaces and line breaks (like those in the top poem here) are ignored.

02fig04.gif

Figure 2.4 When the HTML in Figure 2.3 is viewed as a Web page, line and paragraph breaks only appear where there are <br /> and <p> tags.

You must use HTML tags to control where line and paragraph breaks actually appear. To skip a line between paragraphs, put a <p> tag at the beginning of each paragraph and a </p> tag at the end.

The <br> tag forces a line break within a paragraph. Unlike the other tags you've seen so far, <br> doesn't require a closing </br> tag. To conform to the new XML and XHTML standards (see Hour 24, "Planning for the Future of HTML" ), you should always include a / within any opening tag that doesn't have a closing tag, like this: <br /> .

The second poem in Figures 2.3 and 2.4 shows the <br /> and <p> tags being used to separate the lines and verses of a nursery rhyme and to separate two paragraphs of text commenting on the rhyme.

You might have also noticed the <hr /> tag in Figure 2.3, which causes a horizontal rule line to appear in Figure 2.4. Inserting a horizontal rule with the <hr /> tag also causes a line break, even if you don't include a <br /> tag along with it. For a little extra blank space above or below a horizontal rule, you can put a <p> tag before the <hr /> tag and a </p> tag after it.

Like <br />, the <hr /> horizontal rule tag never gets a closing </hr> tag.

Share ThisShare This

Informit Network