O'Reilly logo

Web Design in a Nutshell, 2nd Edition by Jennifer Niederst Robbins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Linking Documents with <link>

The <link> tag is used to define a relationship between the current document and another external document. It is always placed in the header (<head>) of the document. There can be multiple <link> tags in a document. The most important attributes are href, which points to the linked file, and rel, which describes the relationship from the source document to the target document. The rev attribute describes the reverse relationship (from the target back to the source).

A variety of attributes make the <link> tag very versatile, but it is not currently used to its full potential. The most popular application of the <link> tag is for referring to an external style sheet. In this example, the type attribute identifies the MIME content type of the linked document as a cascading style sheet:

<HEAD>
<LINK HREF="wholesite.css" REL="stylesheet" TYPE="text/css">
</HEAD>

Another use as recommended in the HTML 4.01 specification is to refer to an alternate version of the document in another language. The following example creates a link to a French version of the document:

<HEAD>
<LINK REL="alternate" HREF="translations/french.html" 
      TYPE="text/html" HREFLANG="fr">
</HEAD>

By using the next and prev values for the rel attribute, you can establish the document’s position in a sequence of documents, as shown in the following example. This information could be used by browsers and other tools to build navigation menus, tables of contents, or other link collections.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required