Chapter 2: Understanding HTML

Introducing Tags


[ Comments ] [ Copyright ] [ Chapter contents ] [ Book contents ]


HTML actually contains two kinds of tags; ones that describe attributes of text in the document, and those that define meta-information about the document itself. These don't show up when you view a document in a browser, although you can see them if you examine the HTML source of the file. They provide the browser with information about the document and its relationship to other documents in the world-wide web, hence the prefix meta- ; the tags provide information about the information in the document. (In SGML, as opposed to HTML, you can define your own tags using a special file called a DTD, or document type definition. This effectively defines the structure of a document and the relationship between its components. In HTML, the tag definitions are fixed, making it a lot simpler to deal with - HTML 2.0 is, in fact, defined by an SGML DTD.)

Tags generally follow a simple format:

<TAG_NAME [tag attributes ...] > </TAG_NAME>

or

<TAG_NAME [ tag attributes ...] > ... tagged text ...

The first format is used to delimit a block of text; <TAG_NAME> indicates that text following the tag has some attribute, while </TAG_NAME> ends the application of that attribute to the text. For example:

<B>This text is tagged in the B (boldface) tag.</B>

For some types of tag, the "end" tag </TAG_NAME> is optional; this is usually the case where text tagged by a "start" tag can be implicitly closed by the presence of some other "start" tag. For example:

<P>

This is a new paragraph, as indicated by the preceding P tag.

Paragraphs are implicitly closed by another "start" paragraph tag,

or by some other type of text block (such as a list, table, or form.)

<P>

This second paragraph implicitly closes the previous paragraph.

The second format is used for some commands. Rather than applying an attribute to the text following it, it embeds some kind of object in the text or indicates some kind of mark-point. The tag parameters are simply additional commands within the tag; they vary and we'll discuss them in due course.

For example:

<!-- this is a comment; it will not be displayed by the browser -->

<IMG SRC="../gifs/photograph.gif" ALT="A photograph of myself">


[ Comments ] [ Copyright ] [ Chapter contents ] [ Book contents ]