This wiki has been archived and is now read-only.


From HTML Wiki
Jump to: navigation, search


The <link> element allows authors to link their document to other resources.


  • A link element must have rel attribute.

HTML Attributes

  • href = URL potentially surrounded by spaces
    Specifies a URL that provides the destination of the link.

  • rel = set of space-separated tokens
    Specifies a list of tokens that specify the relationship between the document containing the link and the destination indicated by the link.Two categories of links can be created using the link element: Links to external resources and hyperlinks:
Link type Category Description
alternate Hyperlink Gives alternate representations of the current document.
archives Hyperlink Provides a link to a collection of records, documents, or other materials of historical interest.
author Hyperlink Gives a link to the current document's author.
first Hyperlink Indicates that the current document is a part of a series, and that the first document in the series is the referenced document.
help Hyperlink Provides a link to context-sensitive help.
icon External Resource Imports an icon to represent the current document.
index Hyperlink Gives a link to the document that provides a table of contents or index listing the current document.
last Hyperlink Indicates that the current document is a part of a series, and that the last document in the series is the referenced document.
license Hyperlink Indicates that the main content of the current document is covered by the copyright license described by the referenced document.
next Hyperlink Indicates that the current document is a part of a series, and that the next document in the series is the referenced document.
pingback External Resource Gives the address of the pingback server that handles pingbacks to the current document.
prefetch External Resource Specifies that the target resource should be preemptively cached.
prev Hyperlink Indicates that the current document is a part of a series, and that the previous document in the series is the referenced document.
search Hyperlink Gives a link to a resource that can be used to search through the current document and its related pages.
stylesheet External Resource Imports a stylesheet.
sidebar Hyperlink Specifies that the referenced document, if retrieved, is intended to be shown in the browser's sidebar (if it has one).
tag Hyperlink Gives a tag (identified by the given address) that applies to the current document.
up Hyperlink Provides a link to a document giving the context for the current document.

  • media = media-query list
    The media for which the destination of the hyperlink was designed.
    If the link is a hyperlink then the media attribute is purely advisory, and describes for which media the document in question was designed.
    However, if the link is an external resource link, then the media attribute is prescriptive. The user agent must apply the external resource when the media attribute's value matches the environment and the other relevant conditions apply, and must not apply it otherwise.
    The default, if the media attribute is omitted, is "all", meaning that by default links apply to all media.

  • hreflang = language tag
    The language of the destination of the hyperlink.
    A valid language tag, as defined in [BCP47].

  • type = A valid MIME type that destination of the hyperlink.
    gives the MIME type of the linked resource.
    The default value for the type attribute, which is used if the attribute is absent, is "text/css".

  • sizes = icon sizes
    The sizes attribute is used with the icon link type. The attribute must not be specified on link elements that do not have a rel attribute that specifies the icon keyword.

  • Also, the title attribute has special semantics on this element. The exception is for style sheet links, where the title attribute defines alternative style sheet sets.

See also global attributes.


Example A

Here, a set of link elements provide some style sheets:

<!-- a persistent style sheet -->
<link rel="stylesheet" href="default.css">

<!-- the preferred alternate style sheet -->
<link rel="stylesheet" href="green.css" title="Green styles">

<!-- some alternate style sheets -->
<link rel="alternate stylesheet" href="contrast.css" title="High contrast">
<link rel="alternate stylesheet" href="big.css" title="Big fonts">
<link rel="alternate stylesheet" href="wide.css" title="Wide screen">

Example B

The following example shows how you can specify versions of the page that use alternative formats, are aimed at other languages, and that are intended for other media:

<link rel=alternate href="/en/html" hreflang=en type=text/html title="English HTML">
<link rel=alternate href="/fr/html" hreflang=fr type=text/html title="French HTML">
<link rel=alternate href="/en/html/print" hreflang=en type=text/html media=print title="English HTML (for printing)">
<link rel=alternate href="/fr/html/print" hreflang=fr type=text/html media=print title="French HTML (for printing)">
<link rel=alternate href="/en/pdf" hreflang=en type=application/pdf title="English PDF">
<link rel=alternate href="/fr/pdf" hreflang=fr type=application/pdf title="French PDF">

HTML Reference

The HTML5 specification defines the <link> element in 4.2.5 The link element.