9. XHTML Hypertext Module

Contents

This section is normative.

The Hypertext Module provides an element that traditionally has been used in HTML to define hypertext links to other resources. Although all elements may now play the role of a hyperlink (using the href attribute) or hyperlink anchor (using the id attribute), this element remains for explicit markup of links, though is otherwise identical in semantics to the span element.

This module supports the following element:

Element Attributes Minimal Content Model
a Common (PCDATA | Inline)*

This module adds the a element to the Inline content set of the Text Module.

Implementation: DTD

9.1. The a element

Attributes

The Common collection
A collection of other attribute collections, including: Core, Events, I18N, Bi-directional, Edit, Embedding, and Hypertext

An a element defines an anchor.

  1. The a element's content defines the position of the anchor.
  2. An href attribute makes this anchor the source anchor of exactly one link.
  3. An id attribute makes this anchor the possible target of other links.

Authors may also create an a element that specifies no anchors, i.e., that doesn't specify href, or id. Values for these attributes may be set at a later time through scripts as defined in the Scripting module.

In the example that follows, the a element defines a link. The source anchor is the text "W3C Web site" and the destination anchor is "http://www.w3.org/":

For more information about W3C, please consult the 
<a href="http://www.w3.org/">W3C Web site</a>. 

This link designates the home page of the World Wide Web Consortium. When a user activates this link in a user agent, the user agent will retrieve the resource, in this case, an XHTML document.

User agents generally render links in such a way as to make them obvious to users (underlining, reverse video, etc.). The exact rendering depends on the user agent. Rendering may vary according to whether the user has already visited the link or not. A possible visual rendering of the previous link might be:

For more information about W3C, please consult the W3C Web site.
                                                   ~~~~~~~~~~~~

Suppose we define an anchor named "anchor-one" in the file "one.html".

...text before the anchor...
<a id="anchor-one">This is the location of anchor one.</a>
...text after the anchor...

This creates an anchor around the text "This is the location of anchor one.". Usually, the contents of a are not rendered in any special way when a defines an anchor only.

Having defined the anchor, we may link to it from the same or another document. URIs that designate anchors contain a "#" character followed by the anchor name (the fragment identifier). Here are some examples of such URIs:

Thus, a link defined in the file "two.html" in the same directory as "one.html" would refer to the anchor as follows:

...text before the link...
For more information, please consult <a href="./one.html#anchor-one"> anchor one</a>.
...text after the link...

The a element in the following example specifies a link (with href) and creates a named anchor (with id) simultaneously:

I just returned from vacation! Here's a
<a id="anchor-two" 
   href="http://www.somecompany.com/People/Ian/vacation/family.png">
photo of my family at the lake.</a>.

This example contains a link to a different type of Web resource (a PNG image). Activating the link should cause the image resource to be retrieved from the Web (and possibly displayed if the system has been configured to do so).

Note. User agents are required to find anchors created by empty a elements.