HTML Tags 71
HTML
Overview
HTML Tags
Web Design in a Nutshell, eMatter Edition
HTML Tags
Every HTML tag is made up of a tagname, sometimes followed by an optional list
of attributes, all of which appears between angle brackets < >. Nothing within the
brackets will be displayed in the browser. The tag name is generally an abbrevia-
tion of the tag’s function (this makes them fairly simple to learn). Attributes are
properties that extend or refine the tag’s function.
The name and attributes within a tag are not case sensitive. <BODY
BGCOLOR=white> will work the same as
values for particular attributes may be case sensitive, particularly URLs and
filenames.
Containers
Most HTML tags are containers, meaning they have a beginning (also called
“opener” or “start”) tag and an end tag. The text enclosed within the tags will
follow the tag’s instructions, as in the following example:
The weather is <I>gorgeous</I> today.
Result: The weather isgorgeous today.
An end tag contains the same name as the start tag, but it is preceded by a slash
(/). You can think of it as an “off” switch for the tag. End tags never contain
attributes.
For some tags, the end tag is optional and the browser determines when the tag
ends by context. This practice is most common with the
(paragraph) tag.
Browsers have supported the
tag without its end tag, so many web authors
take advantage of the shortcut. Not all tags allow this, however, and not all
browsers are forgiving, so when in doubt include the end tag. This is especially
important when using Cascading Style Sheets (discussed in Chapter 23,Cascading
Style Sheets) with your document.
In the HTML charts that appear in this book, container tags are indicated with the
syntax< >...</>. If the end tag is optional, it will be so noted in the tag’s
explanation.
Standalone Tags
A few tags do not have end tags because they are used to place standalone
elements on the page. The image tag () is such a tag and it simply plops a
graphic into the flow of the page. Other standalone tags include the linebreak
(
), horizontal rule (
), and tags that provide information about a docu-
ment and don’t affect its displayed content, such as the and
Attributes
Attributes are added within a tag to extend or modify the tag’s actions. You can
add multiple attributes within a single tag. Tag attributes, if any, belong after the
tag name, each separated by one or more spaces. Their order of appearance is not
important.