home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeWeb Design in a NutshellSearch this book

8.2. HTML Tags

Elements in the HTML specification are indicated by tags. An HTML tag is made up of the element name followed by an optional list of attributes, all of which appears between angle brackets (< >). Nothing within the brackets is displayed in the browser. The tag name is generally an abbreviation of the element's name or the tag's function (this makes them fairly simple to learn). Attributes are properties that extend or refine the tag's function.

In the current specification, the name and attributes within a tag are not case sensitive. <BODY BGCOLOR=white> works the same as <body bgcolor=white>. However, values for particular attributes may be case sensitive, particularly URLs and filenames.

TIP

Because tags are not case-sensitive in the HTML 4.01 specification, the tags in sample code throughout this book are written in all uppercase letters for improved readability. In future iterations of HTML (namely XHTML, discussed in Chapter 31, "XHTML"), tags and attributes will be required to be all lowercase. While it is recommended that developers begin the good habit of coding in all lowercase immediately, this book follows the conventions for tag display established within the HTML 4.01 specification itself.

8.2.3. Attributes

Attributes are added within a tag to extend or modify the tag's actions. Attributes always go in the start tag only (end tags never contain attributes). You can add multiple attributes within a single tag. Tag attributes, if any, go after the tag name, each separated by one or more spaces. Their order of appearance is not important.

Most attributes take values, which follow an equals sign (=) after the attribute's name. Most browsers cannot handle attribute values more than 1,024 characters in length. Values may be case-sensitive, particularly filenames or URLs.

The syntax for a container tag with attributes is as follows:

<ELEMENT ATTRIBUTE="value">Affected text</ELEMENT>

The following are examples of tags that contain attributes:

<IMG SRC="graphics/pixie.gif" WIDTH="45" HEIGHT="60">
<BODY BGCOLOR="#000000">...</BODY>
<FONT FACE="Trebuchet MS, Arial, Helvetica" SIZE="4">...</FONT>

The HTML 4.01 specification recommends that all attribute values be enclosed in quotation marks, but it acknowledges that in some cases, they may be omitted. If the value is a single word containing only letters (a-z or A-Z), digits (0-9), hyphens (-), periods (.), underscores ( _ ), and colons (:), then it can be placed directly after the equals sign without quotation marks. If you are still unsure, using quotation marks consistently for all values works just fine and is definitely a good idea. In the XHTML specification, all attribute values must be enclosed in quotation marks in order to be well-formed.

TIP

Be careful not to leave out the closing quotation mark, or all the content from the opening quotation mark until the browser encounters a subsequent quotation mark will be interpreted as part of the value and won't display in the browser. This is a simple mistake that can cause hours of debugging frustration.



Library Navigation Links

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