HTML

HTMLLinkElement

HTMLLinkElement <link>

The HTMLLinkElement interface represents the relationship of external resources to a document and  as well as reference data for those resources (corresponds to the <link> element; not to be mistaken with <a>, which is represented by HTMLAnchorElement). The HTMLElement interface's whole set of attributes and methods are inherited by this object.

The relationship between the current document and an outside resource is specified using the <link> tag. Adding a favicon to your website or linking to external style sheets are two common uses for the <link> tag. Only attributes are present in the <link> element, which is an empty element.

Attribute Value Description Example
crossorigin anonymous Specifies how the element handles cross-origin requests
use-credentials
href URL Specifies the location of the linked document
    Possible values:
  • An absolute URL - points to another web site (like href="http://www.example.com/theme.css")
  • A relative URL - points to a file within a web site (like href="/themes/theme.css")
  • <link rel="stylesheet" href="styles.css">
    hreflang language_code Specifies the language of the linked document <link href="tag_link.asp" rel="parent" rev="subsection" hreflang="en">
    media media_query Specifies on what device the linked document will be displayed <a href="att_a_media.asp?output=print" <head> <link rel="stylesheet" type="text/css" href="theme.css"> <link rel="stylesheet" type="text/css" href="print.css" media="print"> </head>
    referrerpolicy no-referrer No referrer information will be sent along with a request <iframe src="https://w3schools.com/" referrerpolicy="no-referrer"></iframe>
    no-referrer-when-downgrade Default. The referrer header will not be sent to origins without HTTPS
    origin Send only scheme, host, and port to the request client
    origin-when-cross-origin For cross-origin requests: Send only scheme, host, and port. For same-origin requests: Also include the path
    same-origin For same-origin requests: Referrer info will be sent. For cross-origin requests: No referrer info will be sent
    strict-origin-when-cross-origin Send full path when performing a same-origin request. Send only origin when the security level stays the same (e.g. HTTPS to HTTPS). Send no header to a less secure destination (HTTPS to HTTP)
    unsafe-url Send origin, path and query string (but not fragment, password, or username). This value is considered unsafe
    rel alternate Provides a link to an alternate representation of the document (i.e. print page, translated or mirror) <link rel="stylesheet" href="styles.css">
    author Provides a link to the author of the document
    dns-prefetch Specifies that the browser should preemptively perform DNS resolution for the target resource's origin
    help Provides a link to a help document. Example: <link rel="help" href="/help/">
    icon Imports an icon to represent the document. Example: <link rel="icon" href="favicon.ico" type="image/x-icon">
    license Provides a link to copyright information for the document
    next Provides a link to the next document in the series
    pingback Provides the address of the pingback server that handles pingbacks to the current document
    preconnect Specifies that the browser should preemptively connect to the target resource's origin.
    prefetch Specifies that the browser should preemptively fetch and cache the target resource as it is likely to be required for a follow-up navigation
    preload Specifies that the browser agent must preemptively fetch and cache the target resource for current navigation according to the destination given by the "as" attribute (and the priority associated with that destination).
    prerender Specifies that the browser should pre-render (load) the specified webpage in the background. So, if the user navigates to this page, it speeds up the page load (because the page is already loaded). Warning! This wastes the user's bandwidth! Only use prerender if you are absolutely sure that the webpage is required at some point in the user's journey
    prev Indicates that the document is a part of a series, and that the previous document in the series is the referenced document
    search Provides a link to a resource that can be used to search through the current document and its related pages.
    stylesheet Imports a style sheet
    title Defines a preferred or an alternate stylesheet <a href="https://www.google.com" type="text/html">Google</a>
    type media_type Specifies the media type of the linked document <head> <link rel="stylesheet" type="text/css" href="styles.css"> </head>

    Browser Compatibility

    Element Chrome Edge Firefox Safari Opera
    <link> Yes Yes Yes Yes Yes