Links 

Contents

  1. Path information: the BASE element
  2. Links and anchors
    1. Definitions of links and anchors
    2. The A element
    3. Anchors with the id attribute
    4. The LINK element
    5. Link types
    6. Links and external style sheets
    7. Links and search engines
Up to now, the specification has dealt with HTML constructs that add structure to a single document. In this section, we introduce concepts and constructs that allow authors to create links between documents.

Path information: the BASE element 

<!ELEMENT BASE - O EMPTY>
<!ATTLIST BASE
  href        %URL       #REQUIRED
  target      CDATA      #IMPLIED  -- where to render linked resource --
  >

Start tag: required, End tag: forbidden

Attribute definitions

href = url
This attribute specifies an absolute URL that acts as the base URL for resolving relative URLs.

Attributes defined elsewhere

It is important to consider the issue of paths when linking to another document or including an object. In HTML, path information is always specified by a URL. Relative URLs are resolved according to a base URL, which may come from a variety of sources (see the section on relative URLs for information about sources of base URLs). The BASE element allows authors to specify a document's base URL explicitly.

When present, the BASE element must appear in the HEAD section of an HTML document. The scope of the BASE element is the current document only.

For example, given the following BASE declaration:

<HTML>
<HEAD>
<BASE href="http://www.barre.fr/fou/intro.html">
</HEAD>
...
</HTML>

the relative URL "../gee/foo.html" would resolve to:

http://www.barre.fr/gee/foo.html

Links and anchors 

A HTML link is a connection from one Web resource to another. Though a very simple concept, links have been one of the key reasons the Web has been so successful.

Definitions of links and anchors 

An HTML link has two ends and a direction. The link starts at the "source" end and points to the "destination" end.

Every link definition specifies both the source and the destination of the link. One end is always defined as the location where the link definition occurs. The other end is specified by an attribute in the link definition.

A link end refers to some Web resource, such as an HTML document, an image, a video clip, a sound, a program, the current document, etc. A link end may also refer to an anchor. An anchor is a named zone within an HTML document. The zone may include text or other objects.

Uses of links 

Defined this way, links have no inherent semantics; they just associate a source and a destination. However, links also include type information that allows user agents to interpret them in interesting ways.

Of course, by far the most common use of a link is to retrieve another Web resource (e.g., by clicking with a mouse, activating the link with a voice command, etc.).

Web-surfing is not the only use of links, however. For instance, authors may define links that specify the "next" and "previous" documents in a series of documents. User agents can render such links with navigation tools rather than as part of the document's contents.

Similarly, authors may use links to define a print order for a series of documents. User agents may follow these links to produce a coherent printed version of a manual or book.

Making heads and tails of links 

As defined, a link has two ends (the source and the destination), one of which is specified by the location where the link definition occurs. But is this end the source or the destination of the link?

Imagine you are the author of a book written in HTML, and you want your readers to be able to read the book from beginning to end, chapter by chapter. If each chapter is in a separate HTML document, you can represent the order information with links: each document would include two links, one pointing to the previous chapter and one to the next. The link designating the previous chapter has its destination in the current document and its source in the preceding chapter. The link designating the next chapter has its source in the current document and its destination in the next chapter. By recording this structural information in the link definitions, you enable user agents to present the ordered relationships in interesting ways, such as navigation buttons, menus, etc.

The rel attribute specifies that the link being defined has its source in the current document. The rev attribute specifies that the link being defined has its destination in the current document. Furthermore, the values of these attributes give user agents some information about the type of resource located at the other end of the link. Examples illustrating their use are given below.

Elements that define links 

There are two HTML elements that define links: LINK and A.

LINK may only appear in the HEAD section of an HTML document. It defines a relationship between the current document and another resource. Although LINK has no content, the relationships it defines may be rendered by some user agents.

The A element may only appear in the BODY of a document. It defines a relationship between a zone within the current document and another resource. A has content (text, images, etc.) that may be rendered with the rest of the document's contents. User agents generally highlight this content to indicate the presence of a link.

The other important distinction between these two elements is that a link defined by A is generally interpreted by user agents to mean "retrieve the resource at the other end of this link". The retrieved resource may be handled by the user agent in several ways: by opening a new HTML document in the same user agent window, opening a new HTML document in a different window, starting a new program to handle the resource, etc.

The title attribute may be set for these elements to add information about the nature of a link. This information may be spoken by a user agent, rendered as a tool tip, cause a change in cursor image, etc.

Elements that define anchors 

There are two ways to specify anchors in an HTML document:

Links and anchors together. The A element is used to define both links and anchors. It is possible, and even economical, to use the same A element to define a link and an anchor.

Internationalization and links 

Since links may point to documents written in different languages (possibly with different writing order) and using different character encodings, the A and LINK elements support the lang (language), dir (writing direction), and charset (character encoding) attributes. These attributes allow authors to advise user agents about the nature of the data at the other end of the link.

Armed with this additional knowledge, user agents should be able to avoid presenting "garbage" to the user. Instead, they may either locate resources necessary for the correct presentation of the document or, if they cannot locate the resources, they should at least warn the user that the document will be unreadable and explain the cause.

The A element 

<!ELEMENT A - - (%inline)* -(A)>
<!ATTLIST A
  %attrs;                          -- %coreattrs, %i18n, %events --
  charset     CDATA      #IMPLIED  -- char encoding of linked resource --
  name        CDATA      #IMPLIED  -- named link end --
  href        %URL       #IMPLIED  -- URL for linked resource --
  target      CDATA      #IMPLIED  -- where to render resource --
  rel         CDATA      #IMPLIED  -- forward link types --
  rev         CDATA      #IMPLIED  -- reverse link types --
  accesskey   CDATA      #IMPLIED  -- accessibility key character --
  shape       %Shape     rect      -- for use with OBJECT SHAPES --
  coords      %Coords    #IMPLIED  -- for use with OBJECT SHAPES --
  tabindex    NUMBER     #IMPLIED  -- position in tabbing order --
  >

Start tag: required, End tag: required

Attribute definitions

name = cdata
This attribute indicates that the element is being used to define an anchor. The value of this attribute is a unique anchor name. The scope of this name is the current document. Note that this attribute shares the same name space as the id attribute.
href = url
This attribute indicates that the element is being used to define a link. The value of this attribute is the location of one end of the link (the other end being defined by the location of this element).
rel = cdata
This attribute indicates that the source of the link being defined is at the current location. The value of href in this case designates the destination of the link. The value of rel specifies the type of the link. This attribute may take a space-separated list of link types.
rev = cdata
This attribute indicates that the destination of the link being defined is at the current location. The value of href in this case designates the source of the link. The value of rev specifies the type of the link. This attribute may take a space-separated list of link types.
charset = cdata
This attribute specifies the character encoding of the data designated by the link. The value of this attribute must be the name of a "charset" as defined in [RFC2045] (e.g., "euc-jp"). The default value for this attribute is "ISO-8859-1".

Attributes defined elsewhere

The A element may define an anchor, a link, or both.

This example illustrates the definition of a link.

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 HTML document.

User agents generally render links in such a way as to make them obvious to users (underlining, reverse video, etc.). Rendering depends on the user agent. Rendering may vary according to whether the user has already visited the link or not. One possible 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> 

The following example illustrates the definition of an anchor. 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 definition assigns an anchor to the entire document zone that contains 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. URLs that designate anchors end with "#" followed by the anchor name. Here are some examples of such URLs:

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 an anchor and a link simultaneously:

I just returned from vacation! Here's a
<A name="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: Some user agents fail to find anchors represented by empty A elements. For example, some user agents may not find the "empty-anchor" in the following HTML fragment:

<A name="empty-anchor"></A>
<EM>...some HTML...</EM>
<A href="#empty-anchor">Link to empty anchor</A>

Syntax of link attribute values 

Values of the name, rel, and rev attributes observe the following:

Mailto links 

Authors may create links that do not lead to another document but instead cause email to be sent to an email address. When the link is activated, user agents should cause a mail program to open that includes the destination email address in the "To:" field.

To cause email to be sent when a link is activated, specify a MAILTO URL as the value of the href attribute.

In this example, when the user activates the link, the user agent should open a mail program with the address "joe@somplace.com" in the "To:" field.

...this is text...
For all comments, please send email to 
<A href="mailto:joe@someplace.com">Joe Cool</A>.

Nested links 

Links and anchors defined by the A element may not be nested.

ILLEGAL EXAMPLE:
The following example illustrates nested links. Nested links are not permitted.

This text contains 
<A name="outer-anchor" href="next-outer.html">an outer anchor and
and link and <A name="inner-anchor" href="next-inner.html">an inner
anchor and link.</A></A>

Anchors with the id attribute 

The id attribute may be used to position an anchor at the start tag of any 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
Please refer to <A href="#section2">Section Two</A> above
for more details.
The id and name attributes share the same name space (see [ISO10646]). This means that they cannot both define an anchor with the same name in the same document.

ILLEGAL EXAMPLE:
The following excerpt is illegal HTML since these attributes declare the same name twice in the same document.

<BODY>
<A href="#a1">...</A>
...
<H1 id="a1">
...pages and pages...
<A name="a1"></A>
</BODY>

Because of its specification in the HTML DTD, the name attribute may contain entities. Thus, the value D&#xfc;rst is a valid name. The id attribute, on the other hand, may not contain entities.

The LINK element 

<!ELEMENT LINK - O EMPTY>
<!ATTLIST LINK
  %attrs;                          -- %coreattrs, %i18n, %events --
  href        %URL       #IMPLIED  -- URL for linked resource --
  rel         CDATA      #IMPLIED  -- forward link types --
  rev         CDATA      #IMPLIED  -- reverse link types --
  type    %ContentType  #IMPLIED  -- advisory Internet content type --
  media       CDATA      #IMPLIED  -- for rendering on these media --
  target      CDATA      #IMPLIED  -- where to render linked resource --
  >

Start tag: required, End tag: forbidden

Attributes defined elsewhere

This element, which must appear in the HEAD section of a document (any number of times), defines a media-independent link. Although LINK has no content, it conveys relationship information that may be rendered by some user agents in a variety of ways (e.g., a toolbar with a drop-down menu of links).

This example illustrates how several LINK definitions may appear in the HEAD section of a document. The rel and rev attributes specify where the source and destination are for each link. The values "Index", "Next", and "Previous" are explained in the section on link types.

<HTML>
<HEAD>
<LINK rel="Index"    href="../index.html">
<LINK rel="Next"     href="Chapter_3.html">
<LINK rev="Previous" href="Chapter_1.html">
</HEAD>
...the rest of the document...

When should I use rel and rev? It is not always necessary to identify which end is the destination and which is the source of a link. For the A element, you are not required to specify the rel and rev attributes. For the LINK element, you must choose one or the other. See the descriptions above on the distinction between rel and rev.

Link types 

The rel and rev attributes specify which end of a link definition is the destination and which is the source. In both cases, the value or values of the attribute describe the nature of the link. Both attributes may be specified in the same element start tag.

Authors may use the following recognized link types, listed here with their conventional interpretations.

User agents, search engines, etc. may interpret these link types in a variety of ways. For example, user agents may provide access to linked documents through a navigation bar. Or, when the link type is "Next", user agents may preload the next document to save access time.

Contents
The link refers to a document serving as a table of contents.
Index
The link refers to a document providing an index for the current document.
Glossary
The link refers to a document providing a glossary of terms that pertain to the current document.
Copyright
The link refers to a copyright statement for the current document.
Next
The link refers to the next document in an ordered series of documents. This value is generally used with rel.
Previous
The link refers to the previous document in an ordered series of documents. This value is generally used with rev.
Start
The link refers to the first document in a collection of documents. This link type tells search engines which document in a collection is considered by the author to be the starting point of the collection.
Help
The link refers to a document offering help (more information, links to other sources information, etc.)
Bookmark
The link refers to a bookmark. A bookmark is a link to a key entry point within an extended document. The title attribute may used, for example, to label the bookmark. Note that several bookmarks may be defined in each document.
Stylesheet
The link refers to an external style sheet. See the section on external style sheets for details.
Alternate
The link refers to different versions of the same document. When used in tandem with the lang attribute, implies a translated version of the same document. When used in tandem with the media attribute, implies a version for a different medium.

Links and external style sheets 

When the LINK element links an external style sheet to a document, the type attribute specifies the style sheet language and the media attribute specifies the destination medium or media. User agents may save time by retrieving from the network only those style sheets that apply to the current device.

Media types are further discussed in the section on style sheets.

Links and search engines 

Authors may use the LINK element to provide a variety of information to search engines, including:

The examples below illustrate how language information, media types, and link types may be combined to improve document handling by search engines.

In the following example, we tell search engines where to find Dutch, Portuguese, and Arabic versions of a document.

<HEAD>
<LINK lang="nl" title="The manual in Dutch"
      rel="alternate"
      href="http://someplace.com/manual/dutch.html">
<LINK lang="pt" title="The manual in Portuguese"
      rel="alternate"
      href="http://someplace.com/manual/portuguese.html">
<LINK lang="ar" title="The manual in Arabic"
      dir="rtl"
      rel="alternate"
      href="http://someplace.com/manual/arabic.html">
</HEAD>

In the following example, we tell search engines where to find the printed version of a manual.

<HEAD>
<LINK media="print" title="The manual in postscript"
      rel="alternate"
      href="http://someplace.com/manual/postscript.ps">
</HEAD>

In the following example, we tell search engines where to find the front page of a collection of documents.

<HEAD>
<LINK rel="Start" title="The first page of the manual"
      href="http://someplace.com/manual/postscript.ps">
</HEAD>