Book HomeWebmaster in a Nutshell, 3rd EditionSearch this book

2.2. HTML Syntax

For the most part, HTML document elements are simple to understand and use. Every HTML element consists of a tag name, sometimes followed by an optional list of attributes, all placed between opening and closing brackets (< and >). The simplest elements are nothing more than the tag name enclosed in brackets, such as <head> and <i>. More complicated tags have attributes, which may have specific values defined by the author to modify the behavior of an element.

Attributes belong after the tag name, each separated by one or more tab, space, or return characters. The order of attributes in a single tag is not important. An attribute's value, if it has one, follows an equal sign after the attribute name. If an attribute's value is a single word or number, you may simply add it after the equal sign. All other values should be enclosed in single or double quotation marks, especially if they contain several words separated by spaces. The length of an attribute's value is limited to 1,024 characters. Here are some examples of tags with attributes:

<a href="http://www.ora.com/catalog.html" >
<h1 align="right">
<input name="filename" size="24" maxlength="80">
<link title="Table of Contents">

Tag and attribute names are not case-sensitive, but attribute values can be. For example, it is especially important to use the proper capitalization when referencing the URLs of other documents with the href attribute.

Most HTML elements consist of start and end tags that enclose a block of content. An end tag is the same as a start tag except it has a forward slash (/) before the tag name. End tags never contain attributes. For example, to italicize text, you enclose it within the <i> tags:

<i>This text in italics.</i>

You should take care when nesting elements in a document. You must end nested elements by starting with the most recent one and working your way back out. In this example, a phrase in bold (<b>) appears in the text of a link (<a href=...>) contained in a paragraph:

<p>
This is some text in the body, with a
<a href="another_doc.html">link, a portion of which
is <b>set in bold</b></a>
</p>

There are a handful of HTML elements that do not have end tags because they are standalone elements. For example, the image element (<img>) inserts a single graphic into a document and does not require an end tag. Other standalone elements include the line break (<br>), horizontal rule (<hr>), and others that provide information about a document that doesn't affect its displayed content such as <meta> and <base>.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.