The id attribute may be used to create an anchor at the start tag of any element (including the A element).
This example illustrates the use of the id attribute to position an anchor in an H2 element. The anchor is linked to via the A element. You may read more about this in <A href="#section2">Section Two</A>.
...later in the document
<H2 id="section2">Section Two</H2>
...later in the document
<P>Please refer to <A href="#section2">Section Two</A> above
for more details.
The following example names a destination anchor with the id attribute: I just returned from vacation! Here's a
<A id="anchor-two">photo of my family at the lake.</A>.
The id and name attributes share the same name space. This means that they cannot both define an anchor with the same name in the same document. It is permissible to use both attributes to specify an element's unique identifier for the following elements: A, APPLET, FORM, FRAME, IFRAME, IMG, and MAP. When both attributes are used on a single element, their values must be identical.
ILLEGAL EXAMPLE: The following excerpt is illegal HTML since these attributes declare the same name twice in the same document. <A href="#a1">...</A>
...
<H1 id="a1">
...pages and pages...
<A name="a1"></A>
The following example illustrates that id and name must be the same when both appear in an element's start tag: <P><A name="a1" id="a1" href="#a1">...</A>
Because of its specification in the HTML DTD, the name attribute may contain character references. Thus, the value Dürst is a valid name attribute value, as is Dürst . The id attribute, on the other hand, may not contain character references.
Use id or name? Authors should consider the following issues when deciding whether to use id or name for an anchor name:
- The id attribute can act as more than just an anchor name (e.g., style sheet selector, processing identifier, etc.).
- Some older user agents don't support anchors created with the id attribute.
- The name attribute allows richer anchor names (with entities).
|