Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

HTML 4.0 Sourcebook
(Publisher: John Wiley & Sons, Inc.)
Author(s): Ian S. Graham
ISBN: 0471257249
Publication Date: 04/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Summary

1.  HTML documents are divided into elements. Elements are usually marked by start and end tags, and take the form <NAME>.. some text ..</NAME>, where the enclosed text is the content of the element. Some elements do not affect a block of text and are hence called “empty” elements. Empty elements do not require end tags.
2.  Some elements can take attributes, which appear within the start tag and define properties of the element. For example, heading elements can take the ALIGN attribute to specify how the heading should be aligned on the display (e.g. <H1 ALIGN=“center”> text .. </H1> to center-align a heading).
3.  Elements names and attribute names are case-insensitive. Thus, <NAME ATTRIBUTE=“string”>, <NamE ATtRiButE="“string”>, and <name attribute=“string”> are equivalent. However, the attribute value (here the string string) may be case-sensitive. If you suspect the value is case-sensitive, you should enclose it inside double quotation marks (“...”).
4.  The placement of elements in a document must obey the HTML nesting rules that specify where elements can and cannot appear. For example, a heading element, such as H1, cannot contain a list or another heading, but can contain a hypertext anchor. In addition, elements cannot overlap. Details of the nesting rules for HTML elements are provided in Chapters 6 and 7.

Example 1: A Simple HTML Document

At this point, it is easiest to get a feel for the language and for HTML documents by looking at some examples; the details of the language are found in Chapter 6. Figure 1.1 shows a simple but complete HTML document and is designed to illustrate both the basic document structure and some of the simpler markup elements. This document was created using a simple text editor and was saved in a file named ex1.html. The .html filename extension is important, as browsers and Web/HTTP servers understand files with this suffix to be HTML documents as opposed to “plain” text documents. On PCs running Windows 3.1 or DOS (yes—some people still use DOS), the extension is .htm, since four-letter extensions are not possible. More will be said later about extension names and what they mean.

The rendering of Figure 1.1 by two different browsers is shown in Figures 1.2 and 1.3. All browsers allow you to load and view files created on your own computer, even if you are not connected to the Internet, simply by giving the browser the name of the local file. To view the example using the lynx browser, you type

lynx ex1.html

at the command prompt. With graphical browsers like Netscape Navigator and Microsoft Internet Explorer, start the program, select the “Open File...” or other similar menu, usually from the “File” pull-down menu at the top of the window, and then select the desired file.


Figure 1.1 Contents of the example HTML document ex1.html. The rendering of this document by different browsers is shown in Figures 1.2 and 1.3.

<HTML>

<HEAD>
<TITLE> This is the Title of the Document </TITLE>
</HEAD>
<BODY>
<H1> This is a Heading</H1>


<P>Hello.  This is not a very exciting document.
I
    bet you were expecting <EM>poetry</EM>, or

some kind of <STRONG>exciting <BR> fact</STRONG> about the Internet and
the World Wide Web.

<P>Sorry.  No such luck.       This document
does
contain examples of HTML markup, for example, here is an “unordered
list”:
<UL>
   <LI>One item of the list,
   <LI>A second list item  <LI>A third list item that goes on and on and
   on to indicate that the lists can wrap right around the page and still
   be nicely formatted by the browsers.
   <LI>The final item.
</UL>
<p>Lists are exciting. You can also have ordered lists (the items are numbered)
and description lists.
<HR>
<p>And you can draw horizontal lines, which are useful for dividing
sections.
</BODY>
</HTML>

Figures 1.2 and 1.3 show this document rendered by two different WWW browsers. Figure 1.2 shows the document as displayed by the graphical Netscape Navigator browser, while Figure 1.3 shows what you get from the character-based browser lynx.


Figure 1.2  Netscape Navigator 3.0 rendering of the HTML document ex1.html (the HTML document is listed in Figure 1.1).


Figure 1.3  Lynx rendering of the HTML document ex1.html (the HTML document is listed in Figure 1.1).

Document Structure: The HTML Element

Since HTML is a structural language, the tags and elements are best analyzed by starting from the outside and working in. The outermost element, which encompasses the entire document, is named HTML. This element indicates that the enclosed text is an HTML document. This may seem unnecessary, but it is useful in some contexts where the content of a file cannot be determined from the filename—there are actually several other markup languages that look superficially like HTML. The HTML tag lets software easily distinguish between these different types of documents.

The Document HEAD

The next element inside the HTML element is named HEAD. The HEAD element is a container for information about the document, such as the TITLE. HEAD information, if it is displayed, is not presented as part of the document. Looking at Figures 1.2 and 1.3, notice that the content of the TITLE element is displayed apart from the text. With Netscape Navigator the title is displayed in the frame of the window, while with lynx, the name is displayed at the top of the screen and to the right.

The HEAD must be the first element inside the document, right after the <HTML> tag.

Document TITLE—Short and Descriptive

Because it is displayed separately from the text and usually in a restricted space such as a window title bar, a small fixed-size text box, or as a single line at the top of a text screen, the TITLE should be both descriptive and short. If a TITLE is too long, it will simply not fit. The TITLE should be descriptive because when users store a visited location in a Web browser’s bookmark or favorites list, they are actually recording the location of the document along with the TITLE. The TITLE is then the only stored information that describes the item referenced by the bookmark. Authors should thus create TITLEs to be descriptive of the documents, so that the pages can be easily located and identified in a bookmark list.

The Document BODY

After the HEAD, comes the BODY. This element contains all the text and other material that is to be displayed. Notice how this is true in Figure 1.1, where all the displayed material lies between the <BODY> and </BODY> tags.

Why a HEAD and a BODY?

Why bother with this HEAD/BODY separation? Recall that HTML is designed to organize documents in a logical way. It then makes sense to separate the document itself (the BODY) from information about the document (the HEAD). In addition to TITLE, there are several other HEAD elements (discussed in Chapter 6) that describe the relationships between a document and other documents (the LINK element) or provide indexing or other meta-information about the document (the META element). These can be extremely useful for indexing and cataloging document collections as well as for other organizational purposes.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.