9. XHTML Hypertext Module


This section is normative.

The Hypertext Module provides the element that is used to define hypertext links to other resources, as well as a number of attributes.

This module supports the following element:

Element Attributes Minimal Content Model
a Common, charset (Charset), hreflang (LanguageCode), rel (LinkTypes), rev (LinkTypes), type (ContentType) (PCDATA | Inline)*

This module adds the a element to the Inline content set of the Text Module, and activates the Hypertext Attribute Collection.

Implementation: DTD

9.1. The a element


The Common collection
A collection of other attribute collections, including: Core, Events, I18N, and Hypertext
charset = Charset
This attribute specifies the character encoding of the resource designated by the link. Please consult the section on character encodings for more details.
hreflang = LanguageCode
This attribute specifies the base language of the resource designated by href and may only be used when href is specified.
type = ContentType
This attribute gives an advisory hint as to the content type of the content available at the link target address. It allows user agents to opt to use a fallback mechanism rather than fetch the content if they are advised that they will get content in a content type they do not support.

Authors who use this attribute take responsibility to manage the risk that it may become inconsistent with the content available at the link target address.

For the current list of registered content types, please consult [MIMETYPES].

rel = LinkTypes
This attribute describes the relationship from the current document to the URI referred to by the element. The value of this attribute is a space-separated list of link types.
rev = LinkTypes
This attribute is used to describe a reverse link from the anchor specified by the href attribute to the current document. The value of this attribute is a space-separated list of link types.
navindex = Number
This attribute specifies the position of the current element in the navingation order for the current document. This value must be a number between 0 and 32767. User agents must ignore leading zeros.

The navigation order defines the order in which elements will receive focus when navigated by the user via the keyboard. The navigation order may include elements nested within other elements.

Elements that may receive focus should be navigated by user agents according to the following rules:

  1. Those elements that support the navindex attribute and assign a positive value to it are navigated first. Navigation proceeds from the element with the lowest navindex value to the element with the highest value. Values need not be sequential nor must they begin with any particular value. Elements that have identical navindex values should be navigated in the order they appear in the character stream.
  2. Those elements that do not support the navindex attribute or support it and assign it a value of "0" are navigated next. These elements are navigated in the order they appear in the character stream.
  3. Elements that are disabled do not participate in the navigation order.

Tabbing keys. The actual key sequence that causes navigation or element activation depends on the configuration of the user agent (e.g., the "tab" key is used for navigation and the "enter" key is used to activate a selected element).

User agents may also define key sequences to navigate the navigation order in reverse. When the end (or beginning) of the navigation order is reached, user agents may circle back to the beginning (or end).

Each a element defines an anchor.

  1. The a element's content defines the position of the anchor.
  2. The href attribute makes this anchor the source anchor of exactly one link.

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.

To tell user agents explicitly what the character encoding of the destination page is, set the charset attribute:

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

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

...text before the anchor...
<a name="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" 
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 area required to find anchors created by empty a elements.