-->
Previous | Table of Contents | Next |
The <HTML> and </HTML> tags are used to tell a Web browser that the document its processing is written in HTML. The <HTML> tag should be the first tag in your document, and the </HTML> tag should be the last.
An HTML document is divided into a header and a body section. The header contains information about the document, and the body contains the document information itself. As you may have guessed, the header section is surrounded by the <HEAD> and </HEAD> tags, whereas the body is surrounded by the <BODY> and </BODY> tags. Several tags can be placed in the header section, but now only the <TITLE> tag is widely used. The document titlewhatever is enclosed with the <TITLE> and </TITLE> tagsappears in the title bar of a Web browser.
HTML provides several different ways to format text for display. Remember that the actual formatting of the text in your Web page is controlled by the Web browser used to view the page.
Headings
HTML supports six levels of headings that you can display in a document by using the <H1> through <H6> tags. Figure 32.2 shows how these headings may appear in a Web browser (Netscape in this case). Remember that these headings are displayed differently on different browsersthe font and size may not appear the same with your Web browser. Listing 32.2 shows the source.
FIG. 32.2 Heading levels as displayed in Netscape.
Listing 32.2 Example Heading Style Source
<HTML> <HEAD> <TITLE>Heading example</TITLE> </HEAD> <BODY> <H1>Heading 1</H1> <H2>Heading 2 </H2> <H3>Heading 3 </H3> <H4>Heading 4</H4> <H5>Heading 5</H5> <H6>Heading 6</H6> This is plain text. </BODY> </HTML>
Look at the location of the level 2 and level 3 heading tags in Listing 32.2. HTML doesnt care whether the tags are at the end of the line, or where they occur. These tags just tell the browser that all the text between them is in the particular heading level that they define. Also, notice that the line This is plain text has no tags around it. This line will be displayed as generic text by a browser.
TIP: Its usually a good idea to use only three levels of headings in a Web document. If you need more than three levels of headings, consider using additional pages.
Regular Text
HTML gives you several ways to format normal text in your documents. For one thing, Web browsers completely ignore where the text lines end in your HTML file. Carriage returns also are ignored, so you have to use special tags to indicate where line breaks and paragraphs are to begin. The <BR> tag causes the browser thats displaying your document to insert a line break. Think of this as inserting a carriage return at that point in the line. Subsequent text is moved down to the next line.
If you want to create a new paragraph, use the <P> tag instead. <P> has the same effect as <BR>, except that most browsers insert a blank line as part of a paragraph break to visually separate one block of text from another. Because browsers control the text display, the actual behavior of the <P> tag can vary. With the <P> tag, you usually dont need a </P> ending tag. However, it is required if you use any of the <P> attributes.
Sometimes youll want to visually separate different sections of the same page. To do so, HTML provides a way to draw a horizontal line across the document display. The <HR> tag, which stands for horizontal rule, is used to draw a horizontal line. It inserts a paragraph break before the line so you dont need the <P> tag. As with the <P> tag, no ending tag is needed for <HR>.
Youve seen several ways to control the format of text on an HTML page. Now look at another short HTML sample to see the effect of line breaks, paragraph marks, and horizontal rules on the text display. Listing 32.3 shows an HTML sample that uses these formatting tags.
Listing 32.3 An HTML Sample Showing Basic Text Formatting
<HTML> <HEAD> <TITLE>A Sample Text Formatting Page</TITLE> </HEAD>6 <BODY> <H2>Text Sample 1</H2> Here is some sample text that is written on separate lines without using line breaks. <P> <H2>Text Sample 2</H2> This sample text has a<BR> line break in the middle.<P> <H2>Text Sample 3</H2> Text before a paragraph mark.<P> Text after a paragraph mark.<HR> Text after a horizontal rule mark. </BODY> </HTML>
Figure 32.3 shows this sample displayed in Mosaic.
FIG. 32.3 Text formatting as displayed in Mosaic.
Suppose that you want to display some text, such as a table, and that you want the carriage returns and spacing to be kept exactly as you entered them. You can use the <PRE> and </PRE> tags to define preformatted text. Any text that you surround with these tags is displayed in a monospace font, and all returns and spaces are used exactly as they were entered.
To some degree, you can define the way text is displayed. HTML provides tags that tell browsers to display text in boldface, underline, or italic. These tags are known as physical styles. The tags for boldfaced text are <B> and </B>, the tags for underline are <U> and </U>, and the tags for italic are <I> and </I>. Enclose the text that you want to format with the starting and ending tag of the style that you want.
HTML also provides some logical styles for formatting text. The <EM> and </EM> tags are used to mark emphasized text, which is usually shown in italic. The <STRONG> and </STRONG> tags are used to indicate stronger emphasis, which is usually shown in boldface.
Figure 32.4 shows how different text formats may appear.
FIG. 32.4 Examples of text formatting as displayed n Netscape.
Previous | Table of Contents | Next |