W3docs

HTML <link> Tag

The <link> tag contains a link pointing to the external file with the CSS styles or scripts. Tag description, attributes and using examples.

HTML <link> Tag

The <link> tag sets the relationship between the current document and an external resource. It is generally used to link to an external CSS stylesheet.

The <link> tag can be used to link different versions of a page. This is useful if there are several translations of content.

An HTML document can have several <link> elements for loading different types of resources, such as stylesheets, icons, or preloaded content. All these <link> elements should be placed in the <head> section of the document (commonly before the closing </head> tag). Multiple <link> elements can be used in a single document.

Syntax

The <link> tag is empty, which means that the closing tag isn’t required. It contains only attributes. But in XHTML, the <link> tag must be closed (<link/>).

HTML <link> Tag

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <h1>The appearance of the header is determined by the CSS styles specified in the external file.</h1>
    <p>The appearance of the paragraph is determined by the CSS styles specified in the external file.</p>
  </body>
</html>

Result

link tag example

Attributes

AttributeValueDescription
ascontent_typeSpecifies the type of content being loaded. Required when rel="preload".
charsetchar_encodingDefines the coding of the linked document. Obsolete in HTML5.
crossoriginanonymous use-credentialsConfigures CORS settings for the linked resource.
hrefURLDefines the URL of the external file.
hreflanglanguage_codeDefines the text language of the linked document.
integrityhash_valueEnables subresource integrity to verify fetched resources.
mediamedia_queryDefines the device, for which the styles will be applied.
relalternate author bookmark dns-prefetch first help icon last license next nofollow noreferrer pingback preload prefetch prev search stylesheet tag preconnect manifest modulepreloadDefines the relationship between the current document and the linked file. Common values: stylesheet (links a CSS file), icon (links a favicon), preload (preloads a resource), alternate (links to an alternate version of the document).
revreversed relationshipDefines the relationship between the current and linked documents. Obsolete in HTML5.
sizesWidth x HeightSets the size of associated icons. Used only with rel="icon".
typemedia_typeDefines the MIME-type (specification for network transfer of various types of files) of the linked document. Note: When linking a stylesheet, type="text/css" is optional and defaults to CSS.

The <link> tag also supports Global Attributes and the Event Attributes.

Practice

Practice

What are the attributes of the HTML <a> tag?