Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1123613 of <link>

  • Revision slug: Web/HTML/Element/link
  • Revision title: <link>
  • Revision id: 1123613
  • Created:
  • Creator: fscholz
  • Is current revision? Yes
  • Comment bug 1264165

Revision Content

{{HTMLRef}}

The HTML <link> element specifies relationships between the current document and an external resource. Possible uses for this element include defining a relational framework for navigation. This Element is most used to link to style sheets.

The {{htmlattrxref("rel", "link")}} can be set to a lot of different values. They are listed in a separate page.

Content categories Metadata content. If {{htmlattrxref("itemprop", "link")}} is present: flow content and phrasing content
Permitted content None, it is an {{Glossary("empty element")}}.
Tag omission As it is a void element, the start tag must be present and the end tag must not be present
Permitted parent elements Any element that accepts metadata elements. If {{htmlattrxref("itemprop", "link")}} is present: any element that accepts phrasing content.
DOM interface {{domxref("HTMLLinkElement")}}

Attributes

This element includes the global attributes.

{{htmlattrdef("charset")}}{{obsolete_inline}}
This attribute defines the character encoding of the linked resource. The value is a space- and/or comma-delimited list of character sets as defined in {{rfc(2045)}}. The default value is iso-8859-1.
Usage note: This attribute is obsolete and must not be used by authors. To achieve its effect, use the Content-Type HTTP header on the linked resource.
{{htmlattrdef("crossorigin")}}
This enumerated attribute indicates whether CORS must be used when fetching the related image. CORS-enabled images can be reused in the {{HTMLElement("canvas")}} element without being tainted. The allowed values are:
"anonymous"
A cross-origin request (i.e. with Origin: HTTP header) is performed. But no credential is sent (i.e. no cookie, no X.509 certificate and no HTTP Basic authentication is sent). If the server does not give credentials to the origin site (by not setting the Access-Control-Allow-Origin: HTTP header) the image will be tainted and its usage restricted.
"use-credentials"
A cross-origin request (i.e. with Origin: HTTP header) is performed with credential is sent (i.e. a cookie, a certificate and HTTP Basic authentication is performed). If the server does not give credentials to the origin site (through Access-Control-Allow-Credentials: HTTP header), the image will be tainted and its usage restricted.
When not present, the resource is fetched without a CORS request (i.e. without sending the Origin: HTTP header), preventing its non-tainted used in {{HTMLElement('canvas')}} elements. If invalid, it is handled as if the enumerated keyword anonymous was used. See CORS settings attributes for additional information.
{{htmlattrdef("disabled")}} {{Non-standard_inline}}
This attribute is used to disable a link relationship. In conjunction with scripting, this attribute could be used to turn on and off various style sheet relationships.

Note: While there is no disabled attribute in the HTML standard, there is a disabled attribute on the HTMLLinkElement DOM object.

The use of disabled as an HTML attribute is non-standard and only used by some browsers (W3 #27677). Do not use it. To achieve a similar effect, use one of the following techniques:

  • If the disabled attribute has been added directly to the element on the page, do not include the {{HTMLElement("link")}} element instead;
  • Set the disabled property of the StyleSheet DOM object via scripting.
{{htmlattrdef("href")}}
This attribute specifies the {{glossary("URL")}} of the linked resource. A URL might be absolute or relative.
{{htmlattrdef("hreflang")}}
This attribute indicates the language of the linked resource. It is purely advisory. Allowed values are determined by BCP47. Use this attribute only if the {{htmlattrxref("href", "a")}} attribute is present.
{{htmlattrdef("integrity")}} {{experimental_inline}}
Contains inline metadata, a base64-encoded cryptographic hash of a resource (file) you’re telling the browser to fetch, that a user agent can use to verify that a fetched resource has been delivered free of unexpected manipulation. See Subresource Integrity.
{{htmlattrdef("media")}}
This attribute specifies the media which the linked resource applies to. Its value must be a media query. This attribute is mainly useful when linking to external stylesheets by allowing the user agent to pick the best adapted one for the device it runs on.
Usage note:
  • In HTML 4, this can only be a simple white-space-separated list of media description literals, i.e., media types and groups, where defined and allowed as values for this attribute, such as print, screen, aural, braille. HTML5 extended this to any kind of media queries, which are a superset of the allowed values of HTML 4.
  • Browsers not supporting the CSS3 Media Queries won't necessarily recognize the adequate link; do not forget to set fallback links, the restricted set of media queries defined in HTML 4.
{{htmlattrdef("methods")}} {{Non-standard_inline}}
The value of this attribute provides information about the functions that might be performed on an object. The values generally are given by the HTTP protocol when it is used, but it might (for similar reasons as for the title attribute) be useful to include advisory information in advance in the link. For example, the browser might choose a different rendering of a link as a function of the methods specified; something that is searchable might get a different icon, or an outside link might render with an indication of leaving the current site. This attribute is not well understood nor supported, even by the defining browser, Internet Explorer 4. See Methods Property (MSDN).
{{htmlattrdef("referrerpolicy")}} {{experimental_inline}}
A string indicating which referrer to use when fetching the resource:
  • 'no-referrer' meaning that the {{HTTPHeader("Referer")}} header will not be sent.
  • 'no-referrer-when-downgrade' meaning that no {{HTTPHeader("Referer")}} header will be sent when navigating to an origin without TLS (HTTPS). This is a user agent’s default behavior, if no policy is otherwise specified.
  • 'origin' meaning that the referrer will be the origin of the page, that is roughly the scheme, the host and the port.
  • 'origin-when-cross-origin' meaning that navigating to other origins will be limited to the scheme, the host and the port, while navigating on the same origin will include the referrer's path. 
  • 'unsafe-url' meaning that the referrer will include the origin and the path (but not the fragment, password, or username). This case is unsafe because it can leak origins and paths from TLS-protected resources to insecure origins.
{{htmlattrdef("rel")}}
This attribute names a relationship of the linked document to the current document. The attribute must be a space-separated list of the link types values. The most common use of this attribute is to specify a link to an external style sheet: the rel attribute is set to stylesheet, and the href attribute is set to the URL of an external style sheet to format the page. WebTV also supports the use of the value next for rel to preload the next page in a document series.
{{htmlattrdef("rev")}}{{obsolete_inline}}
The value of this attribute shows the relationship of the current document to the linked document, as defined by the {{htmlattrxref("href", "link")}} attribute. The attribute thus defines the reverse relationship compared to the value of the rel attribute. Link types values for the attribute are similar to the possible values for {{htmlattrxref("rel", "link")}}.
Usage note: This attribute is obsolete in HTML5. Do not use it. To achieve its effect, use the {{htmlattrxref("rel", "link")}} attribute with the opposite link types values, e.g. made should be replaced by author. Also this attribute doesn't mean revision and must not be used with a version number, which is unfortunately the case on numerous sites.
{{htmlattrdef("sizes")}}
This attribute defines the sizes of the icons for visual media contained in the resource. It must be present only if the {{htmlattrxref("rel","link")}} contains the icon link types value. It may have the following values:
  • any, meaning that the icon can be scaled to any size as it is in a vectorial format, like image/svg+xml.
  • a white-space separated list of sizes, each in the format <width in pixels>x<height in pixels> or <width in pixels>X<height in pixels>. Each of these sizes must be contained in the resource.
Usage note:
  • Most icon format are only able to store one single icon; therefore most of the time the {{htmlattrxref("sizes")}} contains only one entry. MS's ICO format does, as well as Apple's ICNS. ICO being more ubiquitous, you should use it.
  • Apple's iOS does not support this attribute, hence Apple's iPhone and iPad use special, non-standard link types values to define icon to be used as Web Clip or start-up placeholder: apple-touch-icon and apple-touch-startup-icon.
{{htmlattrdef("target")}}{{Non-standard_inline}}
Defines the frame or window name that has the defined linking relationship or that will show the rendering of any linked resource.
{{htmlattrdef("title")}}
The title attribute has special semantics on the <link> element. When used on a <link rel="stylesheet"> it defines a preferred or an alternate stylesheet. Incorrectly using it may cause the stylesheet to be ignored.
{{htmlattrdef("type")}}
This attribute is used to define the type of the content linked to. The value of the attribute should be a MIME type such as text/html, text/css, and so on. The common use of this attribute is to define the type of style sheet linked and the most common current value is text/css, which indicates a Cascading Style Sheet format.

Examples

Including a stylesheet

To include a stylesheet in a page, use the following syntax:

<link href="style.css" rel="stylesheet">

Providing alternative stylesheets

You can also specify alternative style sheets.

The user can choose which style sheet to use by choosing it from the View>Page Style menu. This provides a way for users to see multiple versions of a page.

<link href="default.css" rel="stylesheet" title="Default Style">
<link href="fancy.css" rel="alternate stylesheet" title="Fancy">
<link href="basic.css" rel="alternate stylesheet" title="Basic">

Stylesheet load events

You can determine when a style sheet has been loaded by watching for a load event to fire on it; similarly, you can detect if an error has occurred while processing a style sheet by watching for an error event:

<script>
function sheetLoaded() {
  // Do something interesting; the sheet has been loaded
}

function sheetError() {
  alert("An error occurred loading the stylesheet!");
}
</script>

<link rel="stylesheet" href="mystylesheet.css" onload="sheetLoaded()" onerror="sheetError()">
Note: The load event fires once the stylesheet and all of its imported content has been loaded and parsed, and immediately before the styles start being applied to the content.

Notes

  • A <link> tag can occur only in the head element; however, there can be multiple occurrences of <link>.
  • HTML 3.2 defines only the href, rel, rev, and title attributes for the link element.
  • HTML 2 defines the href, methods, rel, rev, title, and urn attributes for the <link> element. The methods and urn attributes were later removed from the specifications.
  • The HTML and XHTML specifications define event handlers for the <link> element, but it is unclear how they would be used.
  • Under XHTML 1.0, empty elements such as <link> require a trailing slash: <link />.

Specifications

Specification Status Comment
{{SpecName('Subresource Integrity', '#htmlscriptelement', '<script>')}} {{Spec2('Subresource Integrity')}} Added the integrity attribute.
{{SpecName('HTML WHATWG', 'semantics.html#the-link-element', '<link>')}} {{Spec2('HTML WHATWG')}} No changes from latest snapshot
{{SpecName('HTML5 W3C', 'document-metadata.html#the-link-element', '<link>')}} {{Spec2('HTML5 W3C')}} Added crossorigin and sizes attributes; extended values of media to any media queries; added numerous new values for rel.
{{SpecName('HTML4.01', 'struct/links.html#h-12.3', '<link>')}} {{Spec2('HTML4.01')}}  

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 {{CompatGeckoDesktop("1.0")}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
Alternative stylesheets {{CompatUnknown}} {{CompatGeckoDesktop("1.9")}} {{CompatUnknown}} {{CompatVersionUnknown}} {{CompatUnknown}}
disabled attribute {{Non-standard_inline}} {{CompatNo}} {{CompatNo}} {{CompatVersionUnknown}} {{CompatNo}} {{CompatNo}}
methods attribute {{Non-standard_inline}} {{CompatNo}} {{CompatNo}} 4.0 {{CompatNo}} {{CompatNo}}
sizes attribute {{CompatNo}} {{CompatNo}} {{bug("441770")}} {{CompatNo}} {{CompatNo}} {{CompatNo}}
load and error events

19 (Webkit: 535.23)

({{webkitbug(38995)}})

{{CompatGeckoDesktop("9.0")}} {{CompatUnknown}} 11.60 {{CompatUnknown}}
crossorigin attribute {{CompatChrome("25")}} {{CompatGeckoDesktop("18.0")}} {{CompatUnknown}} {{CompatOpera("15")}} {{CompatUnknown}}
integrity attribute {{CompatChrome(45.0)}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatNo}}[1]
referrerpolicy attribute {{CompatUnknown}} {{CompatGeckoDesktop("50.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
Feature Android Android Webview Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatGeckoMobile("1.0")}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
Alternative stylesheets {{CompatUnknown}} {{CompatUnknown}} {{CompatGeckoMobile("2.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
disabled attribute {{Non-standard_inline}} {{CompatNo}} {{CompatUnknown}} {{CompatNo}} {{CompatUnknown}} {{CompatNo}} {{CompatNo}} {{CompatUnknown}}
methods attribute {{Non-standard_inline}} {{CompatNo}} {{CompatUnknown}} {{CompatNo}} 4.0 {{CompatNo}} {{CompatNo}} {{CompatUnknown}}
sizes attribute {{CompatNo}} {{CompatUnknown}} {{CompatNo}} {{bug("441770")}} {{CompatNo}} {{CompatNo}} {{CompatNo}} {{CompatUnknown}}
load and error events {{CompatUnknown}} {{CompatUnknown}} {{CompatGeckoMobile("9.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
crossorigin attribute {{CompatUnknown}} {{CompatUnknown}} {{CompatGeckoMobile("18.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
integrity attribute {{CompatNo}} {{CompatChrome(45.0)}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatChrome(45.0)}}
referrerpolicy attribute {{CompatUnknown}} {{CompatUnknown}} {{CompatGeckoMobile("50.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}  

[1] {{WebKitBug(148363)}} tracks WebKit implementation of Subresource Integrity (which includes the integrity attribute).

See also

Revision Source

<p id="Summary">{{HTMLRef}}</p>

<p>The <strong>HTML <code>&lt;link&gt;</code> element</strong> specifies relationships between the current document and an external resource. Possible uses for this element include defining a relational framework for navigation. This Element is most used to link to style sheets.</p>

<div class="note">
<p>The {{htmlattrxref("rel", "link")}} can be set to a lot of different values. They are <a href="/en-US/docs/Web/HTML/Link_types">listed</a> in a separate page.</p>
</div>

<table class="properties">
 <tbody>
  <tr>
   <th><a href="/en-US/docs/Web/HTML/Content_categories">Content categories</a></th>
   <td>Metadata content. If {{htmlattrxref("itemprop", "link")}} is present: <a href="/en-US/docs/Web/HTML/Content_categories#Flow_content">flow content</a> and <a href="/en-US/docs/Web/HTML/Content_categories#Phrasing_content">phrasing content</a></td>
  </tr>
  <tr>
   <th>Permitted content</th>
   <td>None, it is an {{Glossary("empty element")}}.</td>
  </tr>
  <tr>
   <th>Tag omission</th>
   <td>As it is a void element, the start tag must be present and the end tag must not be present</td>
  </tr>
  <tr>
   <th>Permitted parent elements</th>
   <td>Any element that accepts metadata elements. If {{htmlattrxref("itemprop", "link")}} is present: any element that accepts <a href="/en-US/docs/Web/HTML/Content_categories#Phrasing_content">phrasing content</a>.</td>
  </tr>
  <tr>
   <th>DOM interface</th>
   <td>{{domxref("HTMLLinkElement")}}</td>
  </tr>
 </tbody>
</table>

<h2 id="Attributes">Attributes</h2>

<p>This element includes the <a href="/en-US/docs/Web/HTML/Global_attributes">global attributes</a>.</p>

<dl>
 <dt>{{htmlattrdef("charset")}}{{obsolete_inline}}</dt>
 <dd>This attribute defines the character encoding of the linked resource. The value is a space- and/or comma-delimited list of character sets as defined in {{rfc(2045)}}. The default value is <code>iso-8859-1</code>.
 <div class="note"><strong>Usage note:</strong> This attribute is obsolete and <em>must</em> <strong>not be used by authors</strong>. To achieve its effect, use the <span style="font-family:courier new">Content-Type</span>&nbsp;HTTP header on the linked resource.</div>
 </dd>
 <dt>{{htmlattrdef("crossorigin")}}</dt>
 <dd>This enumerated attribute indicates whether CORS must be used when fetching the related image. <a href="/en-US/docs/Web/HTML/CORS_Enabled_Image">CORS-enabled images</a> can be reused in the {{HTMLElement("canvas")}} element without being <em>tainted</em>. The allowed values are:
 <dl>
  <dt><code>"anonymous"</code></dt>
  <dd>A cross-origin request (i.e. with <code>Origin:</code> HTTP header) is performed. But no credential is sent (i.e. no cookie, no X.509 certificate and no HTTP Basic authentication is sent). If the server does not give credentials to the origin site (by not setting the <code>Access-Control-Allow-Origin:</code> HTTP header) the image will be <em>tainted</em> and its usage restricted.</dd>
  <dt><code>"use-credentials"</code></dt>
  <dd>A cross-origin request (i.e. with <code>Origin:</code> HTTP header) is performed with credential is sent (i.e. a cookie, a certificate and HTTP Basic authentication is performed). If the server does not give credentials to the origin site (through <code>Access-Control-Allow-Credentials:</code> HTTP header), the image will be <em>tainted</em> and its usage restricted.</dd>
 </dl>
 When not present, the resource is fetched without a CORS request (i.e. without sending the <code>Origin:</code> HTTP header), preventing its non-tainted used in {{HTMLElement('canvas')}} elements. If invalid, it is handled as if the enumerated keyword <strong>anonymous</strong> was used. See <a href="/en-US/docs/Web/HTML/CORS_settings_attributes">CORS settings attributes</a> for additional information.</dd>
 <dt>{{htmlattrdef("disabled")}} {{Non-standard_inline}}</dt>
 <dd>This attribute is used to disable a link relationship. In conjunction with scripting, this attribute could be used to turn on and off various style sheet relationships.
 <div class="note">
 <p><strong>Note: </strong>While there is no <code>disabled</code> attribute in the HTML standard, there <strong>is</strong> a <code>disabled</code> attribute on the <code>HTMLLinkElement</code> DOM object.</p>

 <p>The use of <code>disabled</code> as an HTML attribute is non-standard and only used by some browsers (<a href="https://www.w3.org/Bugs/Public/show_bug.cgi?id=27677">W3 #27677</a>). <strong style="font-weight:bold">Do not use it</strong>. To achieve a similar effect, use one of the following techniques:</p>

 <ul>
  <li>If the <code>disabled</code> attribute has been added directly to the element on the page, do not include the {{HTMLElement("link")}} element instead;</li>
  <li>Set the <code>disabled</code> <strong>property</strong> of the <code>StyleSheet</code> DOM object via scripting.</li>
 </ul>
 </div>
 </dd>
 <dt>{{htmlattrdef("href")}}</dt>
 <dd>This attribute specifies the {{glossary("URL")}} of the linked resource. A URL might be absolute or relative.</dd>
 <dt>{{htmlattrdef("hreflang")}}</dt>
 <dd>This attribute indicates the language of the linked resource. It is purely advisory. Allowed values are determined by <a href="https://www.ietf.org/rfc/bcp/bcp47.txt">BCP47</a>. Use this attribute only if the {{htmlattrxref("href", "a")}} attribute is present.</dd>
 <dt>{{htmlattrdef("integrity")}} {{experimental_inline}}</dt>
 <dd>Contains inline metadata, a base64-encoded&nbsp;cryptographic hash of a resource (file) you’re telling the browser to fetch,&nbsp;that a user agent can use to verify that a fetched resource has been delivered free of unexpected manipulation. See <a href="/en-US/docs/Web/Security/Subresource_Integrity">Subresource Integrity</a>.</dd>
 <dt>{{htmlattrdef("media")}}</dt>
 <dd>This attribute specifies the media which the linked resource applies to. Its value must be a <a href="/en-US/docs/CSS/Media_queries">media query</a>. This attribute is mainly useful when linking to external stylesheets by allowing the user agent to pick the best adapted one for the device it runs on.
 <div class="note"><strong>Usage note: </strong>
 <ul>
  <li>In HTML 4, this can only be a simple white-space-separated list of media description literals, i.e., <a href="/en-US/docs/CSS/@media">media types and groups</a>, where defined and allowed as values for this attribute, such as <code>print</code>, <code>screen</code>, <code>aural</code>, <code>braille</code>. HTML5 extended this to any kind of <a href="/en-US/docs/CSS/Media_queries">media queries</a>, which are a superset of the allowed values of HTML 4.</li>
  <li>Browsers not supporting the <a href="/en-US/docs/CSS/Media_queries">CSS3 Media Queries</a> won't necessarily recognize the adequate link; do not forget to set fallback links, the restricted set of media queries defined in HTML 4.</li>
 </ul>
 </div>
 </dd>
 <dt>{{htmlattrdef("methods")}} {{Non-standard_inline}}</dt>
 <dd>The value of this attribute provides information about the functions that might be performed on an object. The values generally are given by the HTTP protocol when it is used, but it might (for similar reasons as for the <strong>title</strong> attribute) be useful to include advisory information in advance in the link. For example, the browser might choose a different rendering of a link as a function of the methods specified; something that is searchable might get a different icon, or an outside link might render with an indication of leaving the current site. This attribute is not well understood nor supported, even by the defining browser, Internet Explorer 4. See <a href="https://msdn.microsoft.com/en-us/library/ms534168%28VS.85%29.aspx" rel="external nofollow" target="_blank">Methods Property (MSDN)</a>.</dd>
 <dt>{{htmlattrdef("referrerpolicy")}} {{experimental_inline}}</dt>
 <dd>A string indicating which referrer to use when fetching the resource:
 <ul>
  <li><code>'no-referrer'</code> meaning that the {{HTTPHeader("Referer")}} header will not be sent.</li>
  <li><code>'no-referrer-when-downgrade'</code> meaning that no&nbsp;{{HTTPHeader("Referer")}} header will be sent when navigating to an origin without TLS (HTTPS).&nbsp;This is a user agent’s default behavior, if no policy is otherwise specified.</li>
  <li><code>'origin'</code> meaning that the referrer will be the origin of the page, that is roughly the scheme, the host and the port.</li>
  <li><code>'origin-when-cross-origin'</code> meaning that navigating to other origins will be limited to the scheme, the host and the port, while navigating on the same origin will include the referrer's path.&nbsp;</li>
  <li><code>'unsafe-url'</code> meaning that the referrer will include the origin and the path (but not the fragment, password, or username). This case is unsafe because it can leak origins and paths from TLS-protected resources to insecure origins.</li>
 </ul>
 </dd>
 <dt>{{htmlattrdef("rel")}}</dt>
 <dd>This attribute names a relationship of the linked document to the current document. The attribute must be a space-separated list of the <a href="/en-US/docs/Web/HTML/Link_types">link types values</a>. The most common use of this attribute is to specify a link to an external style sheet: the <strong>rel</strong> attribute is set to <code>stylesheet</code>, and the <strong>href</strong> attribute is set to the URL of an external style sheet to format the page. WebTV also supports the use of the value <code>next</code> for <strong>rel</strong> to preload the next page in a document series.</dd>
 <dt>{{htmlattrdef("rev")}}{{obsolete_inline}}</dt>
 <dd>The value of this attribute shows the relationship of the current document to the linked document, as defined by the {{htmlattrxref("href", "link")}} attribute. The attribute thus defines the reverse relationship compared to the value of the <strong>rel</strong> attribute. <a href="/en-US/docs/Web/HTML/Link_types">Link types values</a> for the attribute are similar to the possible values for {{htmlattrxref("rel", "link")}}.
 <div class="note"><strong>Usage note: </strong>This attribute is obsolete in HTML5. <strong>Do not use it</strong>. To achieve its effect, use the {{htmlattrxref("rel", "link")}} attribute with the opposite <a href="/en-US/docs/Web/HTML/Link_types">link types values</a>, e.g. <span style="font-family:courier new">made</span> should be replaced by <span style="font-family:courier new">author</span>. Also this attribute doesn't mean <em>revision</em> and must not be used with a version number, which is unfortunately the case on numerous sites.</div>
 </dd>
 <dt>{{htmlattrdef("sizes")}}</dt>
 <dd>This attribute defines the sizes of the icons for visual media contained in the resource. It must be present only if the {{htmlattrxref("rel","link")}} contains the <span style="font-family:courier new">icon</span> <a href="/en-US/docs/Web/HTML/Link_types">link types value</a>. It may have the following values:
 <ul>
  <li><code>any</code>, meaning that the icon can be scaled to any size as it is in a vectorial format, like <code>image/svg+xml</code>.</li>
  <li>a white-space separated list of sizes, each in the format <span style="font-family:courier new"><em>&lt;width in pixels&gt;</em>x<em>&lt;height in pixels&gt;</em></span> or <span style="font-family:courier new"><em>&lt;width in pixels&gt;</em>X<em>&lt;height in pixels&gt;</em></span>. Each of these sizes must be contained in the resource.</li>
 </ul>

 <div class="note"><strong>Usage note: </strong>

 <ul>
  <li>Most icon format are only able to store one single icon; therefore most of the time the {{htmlattrxref("sizes")}} contains only one entry. MS's ICO format does, as well as Apple's ICNS. ICO being more ubiquitous, you should use it.</li>
  <li>Apple's iOS does not support this attribute, hence Apple's iPhone and iPad use special, non-standard <a href="/en-US/docs/Web/HTML/Link_types">link types values</a> to define icon to be used as Web Clip or start-up placeholder: <span style="font-family:courier new">apple-touch-icon</span> and <span style="font-family:courier new">apple-touch-startup-icon</span>.</li>
 </ul>
 </div>
 </dd>
 <dt>{{htmlattrdef("target")}}{{Non-standard_inline}}</dt>
 <dd>Defines the frame or window name that has the defined linking relationship or that will show the rendering of any linked resource.</dd>
 <dt>{{htmlattrdef("title")}}</dt>
 <dd>The <code>title</code> attribute has special semantics on the <code>&lt;link&gt;</code> element. When used on a <code>&lt;link rel="stylesheet"&gt;</code> it defines a <a href="/en-US/docs/Web/CSS/Alternative_style_sheets">preferred or an alternate stylesheet</a>. Incorrectly using it may <a href="/en-US/docs/Correctly_Using_Titles_With_External_Stylesheets">cause the stylesheet to be ignored</a>.</dd>
 <dt>{{htmlattrdef("type")}}</dt>
 <dd>This attribute is used to define the type of the content linked to. The value of the attribute should be a MIME type such as <strong>text/html</strong>, <strong>text/css</strong>, and so on. The common use of this attribute is to define the type of style sheet linked and the most common current value is <strong>text/css</strong>, which indicates a Cascading Style Sheet format.</dd>
</dl>

<h2 id="Examples">Examples</h2>

<h3 id="Including_a_stylesheet">Including a stylesheet</h3>

<p>To include a stylesheet in a page, use the following syntax:</p>

<pre class="brush: html">
&lt;link href="style.css" rel="stylesheet"&gt;
</pre>

<h3 id="Providing_alternative_stylesheets">Providing alternative stylesheets</h3>

<p>You can also specify <a href="/en-US/docs/Web/CSS/Alternative_style_sheets">alternative style sheets</a>.</p>

<p>The user can choose which style sheet to use by choosing it from the View&gt;Page Style menu. This provides a way for users to see multiple versions of a page.</p>

<pre class="brush: html">
&lt;link href="default.css" rel="stylesheet" title="Default Style"&gt;
&lt;link href="fancy.css" rel="alternate stylesheet" title="Fancy"&gt;
&lt;link href="basic.css" rel="alternate stylesheet" title="Basic"&gt;
</pre>

<h3 id="Stylesheet_load_events">Stylesheet load events</h3>

<p>You can determine when a style sheet has been loaded by watching for a <code>load</code> event to fire on it; similarly, you can detect if an error has occurred while processing a style sheet by watching for an <code>error</code> event:</p>

<pre class="brush: html">
&lt;script&gt;
function sheetLoaded() {
  // Do something interesting; the sheet has been loaded
}

function sheetError() {
  alert("An error occurred loading the stylesheet!");
}
&lt;/script&gt;

&lt;link rel="stylesheet" href="mystylesheet.css" onload="sheetLoaded()" onerror="sheetError()"&gt;
</pre>

<div class="note"><strong>Note:</strong> The <code>load</code> event fires once the stylesheet and all of its imported content has been loaded and parsed, and immediately before the styles start being applied to the content.</div>

<h2 id="Notes">Notes</h2>

<ul>
 <li>A <code>&lt;link&gt;</code> tag can occur only in the head element; however, there can be multiple occurrences of <code>&lt;link&gt;</code>.</li>
 <li>HTML 3.2 defines only the <strong>href</strong>, <strong>rel</strong>, <strong>rev</strong>, and <strong>title</strong> attributes for the link element.</li>
 <li>HTML 2 defines the <strong>href</strong>, <strong>methods</strong>, <strong>rel</strong>, <strong>rev</strong>, <strong>title</strong>, and <strong>urn</strong> attributes for the <code>&lt;link&gt;</code> element. The <strong>methods</strong> and <strong>urn</strong> attributes were later removed from the specifications.</li>
 <li>The HTML and XHTML specifications define event handlers for the <code>&lt;link&gt;</code> element, but it is unclear how they would be used.</li>
 <li>Under XHTML 1.0, empty elements such as <code>&lt;link&gt;</code> require a trailing slash: <code>&lt;link /&gt;</code>.</li>
</ul>

<h2 id="Specifications" name="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('Subresource Integrity', '#htmlscriptelement', '&lt;script&gt;')}}</td>
   <td>{{Spec2('Subresource Integrity')}}</td>
   <td>Added the <code>integrity</code> attribute.</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML WHATWG', 'semantics.html#the-link-element', '&lt;link&gt;')}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>No changes from latest snapshot</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML5 W3C', 'document-metadata.html#the-link-element', '&lt;link&gt;')}}</td>
   <td>{{Spec2('HTML5 W3C')}}</td>
   <td>Added <code>crossorigin</code> and <code>sizes</code> attributes; extended values of <code>media</code> to any media queries; added numerous new values for <code>rel</code>.</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML4.01', 'struct/links.html#h-12.3', '&lt;link&gt;')}}</td>
   <td>{{Spec2('HTML4.01')}}</td>
   <td>&nbsp;</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<div>{{CompatibilityTable}}</div>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>1.0</td>
   <td>{{CompatGeckoDesktop("1.0")}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
  <tr>
   <td>Alternative stylesheets</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoDesktop("1.9")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>disabled</code> attribute {{Non-standard_inline}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
  <tr>
   <td><code>methods</code> attribute {{Non-standard_inline}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>4.0</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
  <tr>
   <td><code>sizes</code> attribute</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}} {{bug("441770")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
  <tr>
   <td><code>load</code> and <code>error</code> events</td>
   <td>
    <p>19 (Webkit: 535.23)</p>

    <p>({{webkitbug(38995)}})</p>
   </td>
   <td>{{CompatGeckoDesktop("9.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>11.60</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>crossorigin</code> attribute</td>
   <td>{{CompatChrome("25")}}</td>
   <td>{{CompatGeckoDesktop("18.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatOpera("15")}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>integrity</code> attribute</td>
   <td>{{CompatChrome(45.0)}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatNo}}<sup>[1]</sup></td>
  </tr>
  <tr>
   <td><code>referrerpolicy</code> attribute</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoDesktop("50.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Android Webview</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
   <th>Chrome for Android</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoMobile("1.0")}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
  <tr>
   <td>Alternative stylesheets</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoMobile("2.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>disabled</code> attribute {{Non-standard_inline}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>methods</code> attribute {{Non-standard_inline}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatNo}}</td>
   <td>4.0</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>sizes</code> attribute</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatNo}} {{bug("441770")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>load</code> and <code>error</code> events</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoMobile("9.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>crossorigin</code> attribute</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoMobile("18.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>integrity</code> attribute</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatChrome(45.0)}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatChrome(45.0)}}</td>
  </tr>
  <tr>
   <td><code>referrerpolicy</code> attribute</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoMobile("50.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>&nbsp;</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] {{WebKitBug(148363)}} tracks WebKit implementation of Subresource Integrity (which includes the <code>integrity</code> attribute).</p>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="https://pieisgood.org/test/script-link-events/">Ryan Grove's &lt;script&gt; and &lt;link&gt; node event compatibility chart</a></li>
</ul>
Revert to this revision