Section 6.7. Relationships

Very few documents stand alone. Instead, a document is usually part of a collection of documents, each connected by one or several of the hypertext strands we describe in this chapter. One document may be a part of several collections, linking to some documents and being linked to by others. Readers move between the document families as they follow the links that interest them.

When you link two documents, you establish an explicit relationship between them. Conscientious authors use the rel attribute of the <a> tag to indicate the nature of the link. In addition, two other tags may be used within a document to further clarify the location of a document within a document family and its relationship to the other documents in that family. These tags, <base> and <link>, are placed within the body of the <head> tag. [<head>]

6.7.1 The <base> Header Element

As we previously explained, URLs within a document can be either absolute (with every element of the URL explicitly provided by the author) or relative (with certain elements of the URL omitted and supplied by the browser). Normally, the browser fills in the blanks of a relative URL by drawing the missing pieces from the URL of the current document. You can change that with the <base> tag.



Defines the base URL for other anchors in the document


href, target

End tag

None in HTML; </base> or <base ... /> in XHTML



Used in


The <base> tag should appear only in the document header, not in its body contents. The browser thereafter uses the specified base URL, not the current document's URL, to resolve all relative URLs, including those found in <a>, <img>, <link>, and <form> tags. It also defines the URL that will be used to resolve queries in searchable documents containing the <isindex> tag. [Section 6.2] The href attribute

The href attribute must have a valid URL as its value, which the browser then uses to define the absolute URL against which relative URLs are based within the document.

For example, the <base> tag in this XHTML document head:


<base href="" />



tells the browser that any relative URLs within this document are relative to the top-level document directory on, regardless of the address and directory of the machine from which the user retrieved the current document.

Contrary to what you may expect, you can make the base URL relative, not absolute. The browser should (but doesn't always) form an absolute base URL out of this relative URL by filling in the missing pieces with the URL of the document itself. This property can be used to good advantage. For instance, in this next HTML example:


<base href="/info/">



the browser makes the <base> URL into one relative to the server's /info directory, which probably is not the same directory of the current document. Imagine if you had to re-address every link in your document with that common directory. Not only does the <base> tag help you shorten those URLs in your document that have a common root, it also lets you constrain the directory from which relative references are retrieved without binding the document to a specific server. The target attribute

When working with documents inside frames, the target attribute with the <a> tag ensures that a referenced URL gets loaded into the correct frame. Similarly, the target attribute for the <base> tag lets you establish the default name of one of the frames or windows in which the browser is to display redirected hyperlinked documents. [Section 11.1]

If you have no other default target for your hyperlinks within your frames, you may want to consider using <base target=_top>. This ensures that links that are not specifically targeted to a frame or window will load in the top-level browser window. This eliminates the embarrassing and common error of having references to pages on other sites appear within a frame on your pages, instead of within their own pages. A minor bit of HTML, to be sure, but it makes life much easier for your readers. Using <base>

The most important reason for using <base> is to ensure that any relative URLs within the document will resolve into correct document addresses, even if the documents themselves are moved or renamed. This is particularly important when creating a document collection. By placing the correct <base> tag in each document, you can move the entire collection between directories and even servers without breaking all of the links within the documents. You also need to use the <base> tag for a searchable document (<isindex>) if you want user queries posed to a URL different from that of the host document.

A document that contains both the <isindex> tag and other relative URLs may have problems if the relative URLs are not relative to the desired index-processing URL. Since this is usually the case, don't use relative URLs in searchable documents that use the <base> tag to specify the query URL for the document.

6.7.2 The <link> Header Element

Use the <link> tag to define the relationship between the current document and another in a web collection.



Defines a relationship between this document and another document


charset, class, dir, href, hreflang, id, lang, media, onClick, onDblClick, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, rel, rev, style, target, title, type

End tag

None in HTML; </link> or <link ... /> in XHTML



Used in


The <link> tags belongs in the <head> content and nowhere else. The attributes of the <link> tag are used like those of the <a> tag, but their effects serve only to document the relationship between documents. The <link> tag has no content, and only XHTML supports the closing </link> tag. The href attribute

As with its other tag applications, the href attribute specifies the URL of the target <link> tag. It is a required attribute, and its value is any valid document URL. The specified document is assumed to have a relationship to the current document. The rel and rev attributes

The rel and rev attributes express the relationship between the source and target documents. The rel attribute specifies the relationship from the source document to the target; the rev attribute specifies the relationship from the target document to the source document. Both attributes can be included in a single <link> tag.

The value of either attribute is a space-separated list of relationships. The actual relationship names are not specified by the HTML standard, although some have come into common usage, as listed in Section For example, a document that is part of a sequence of documents might use:

<link href="part-14.html" rel=next rev=prev>

when referencing the next document in the series. The relationship from the source to the target is that of moving to the next document; the reverse relationship is that of moving to the previous document. The title attribute

The title attribute lets you specify the title of the document to which you are linking. This attribute is useful when referencing a resource that does not have a title, such as an image or a non-HTML document. In this case, the browser might use the <link> title when displaying the referenced document. For example:

<link href="pics/kumquat.gif" 

  title="A photograph of the Noble Fruit">

tells the browser to use the indicated title when displaying the referenced image.

The value of the attribute is an arbitrary character string, enclosed in quotation marks. The type attribute

The type attribute provides the MIME content type of the linked document. Supported by both Internet Explorer and Netscape, the HTML 4 and XHTML standard type attribute can be used with any linked document. It is often used to define the type of a linked style sheet. In this context, the value of the type attribute is usually text/css. For example:

<link href="styles/classic.css" rel=stylesheet type="text/css">

creates a link to an external style sheet within the <head> of a document. See Chapter 8 for details. How browsers might use <link>

Although the standards do not require browsers to do anything with the information provided by the <link> tag, it's not hard to envision how this information might be used to enhance the presentation of a document.

As a simple example, suppose you consistently provide <link> tags for each of your documents that define next, prev, and parent links. A browser could use this information to place at the top or bottom of each document a standard toolbar containing buttons that would jump to the appropriate related document. By relegating the task of providing simple navigational links to the browser, you are free to concentrate on the more important content of your document.

As a more complex example, suppose that a browser expects to find a <link> tag defining a glossary for the current document and that this glossary document is itself a searchable document. Whenever a reader clicked on a word or phrase in the document, the browser could automatically search the glossary for the definition of the selected phrase, presenting the result in a small pop-up window.

As the Web evolves, expect to see more and more uses of the <link> tag to define document relationships explicitly. Other <link> attributes

The HTML 4 and XHTML standards also include the ubiquitous collection of attributes related to style sheets and user events, and language for the <link> tag. You can refer to the corresponding section describing these attributes for the <a> tag for a complete description of their usage. [Section 6.3.1]

Since you put the <link> tag in the <head> section, whose contents are not displayed, it may seem that these attributes are useless. It is entirely possible that some future browser may find some way to display the <link> information to the user, possibly as a navigation bar or a set of hot-list selections. In those cases, the display and rendering information would prove useful. Currently, no browser provides these capabilities.