HTML and CSS Reference
In-Depth Information
<img src="seasonings.gif" alt="Salt & pepper" />
for it to be compliant XHTML.
16.3.8. The id and name Attributes
Early versions of HTML used the
name
attribute with the
<a>
tag to create
a fragment identifier in the document. This fragment could then be used
in a URL to refer to a particular spot within a document. The
name
attrib-
ute was later added to other tags, such as
<frame>
and
<img>
, allowing
those elements to be referenced by name from other spots in the docu-
ment.
With HTML 4.0, the W3C added the
id
attribute to almost every tag. Like
name
,
id
lets you associate an identifier with nearly any element in a doc-
ument for later reference and use, perhaps by a hyperlink or a script.
XHTML has a strong preference for the
id
attribute as the anchor of
choice within a document. The
name
attribute is defined but formally de-
precated for those elements that have historically used it. With wide-
spread support of HTML 4.0 now in place, you should begin to avoid the
name
attribute where possible and instead use the
id
attribute to bind
names to elements in your documents. If you must use the
name
attrib-
ute on certain tags, include an identical
id
attribute to ensure that the
tag will behave similarly when processed by a strict XHTML browser.