Document Metadata

HTML <link> element

Describes a relationship to an external resource, such as a stylesheet or icon. The rel value determines the processing rules. The example uses illustrative local asset paths; supply matching files before running it. Choose rel before choosing other attributes: a stylesheet is applied to the page, a preload schedules an anticipated fetch, and a canonical link identifies a preferred URL. Resource hints are not instructions to execute scripts. It accepts global HTML attributes; individual global features may be inapplicable or restricted.

Formal Syntax & Structure

html syntaxhtml
<link rel="stylesheet" href="site.css">

Parameters & Attributes

NameTypeDescription
hrefURLSpecifies a link destination, resource URL or document base URL depending on the element. An anchor without href is not a normal navigable hyperlink. Relative URLs resolve against the document base URL.
crossoriginenumerated: anonymous, use-credentialsConfigures CORS settings for eligible resource requests. anonymous omits cross-origin credentials; use-credentials includes them. Server CORS headers must permit the request when needed.
relspace-separated relationship keywordsDefines relationships between a document and a linked resource or navigation target. Valid tokens depend on the element; stylesheet, noopener and canonical have different purposes.
asenumerated resource destinationIdentifies what kind of resource a link preload will fetch, such as script, style, image or font. It must match the later request so the browser can reuse it.
mediamedia query listSpecifies conditions under which a resource or metadata applies, such as a stylesheet's target media or a picture source's viewport condition.
hreflangBCP 47 language tagAdvises the language of a linked resource; it does not translate content or force a browser to use that language.
typeelement-dependent keyword or MIME typeSelects an element-specific kind: input control state, button behavior, ordered-list numbering, script interpretation or resource media type. Consult the element's own allowed values.
sizesresponsive source size list or icon sizesOn responsive images, describes the expected display slot width used with width-descriptor candidates. On icon links, describes icon dimensions. The grammars differ.
imagesrcsetimage candidate listProvides responsive image candidates for a link preload. Match the final image's srcset and sizes so the preload selects the appropriate resource.
imagesizesresponsive source size listSupplies source-size information for an image preload, corresponding to the sizes on the eventual image. Use with imagesrcset where width descriptors require it.
referrerpolicyreferrer policy keywordControls the referrer information sent with an eligible fetch or navigation. no-referrer omits it; strict-origin-when-cross-origin is a common default policy. It does not prevent all tracking.
integritysubresource integrity hash metadataPins eligible external resources to an expected cryptographic digest. The browser rejects mismatches. Cross-origin use requires appropriate CORS support; regenerate the digest when the resource changes.
blockingspace-separated tokensRequests eligible resource processing to block rendering; render is the relevant token. This can delay visible content, so use only when needed.
disabledbooleanDisables supported controls or elements. Disabled form controls are generally not focusable, validated or submitted. The exact effect depends on the element; disabled="false" still disables.
fetchpriorityenumerated: high, low, autoHints relative fetch priority for eligible resources. It is not a guarantee and does not replace preloading or lazy loading. Reserve high for genuinely important resources.

Return Value

HTMLLinkElement

Content model: Empty; this void element cannot contain children and must not have an end tag. No closing tag.

Working Example

Example Snippethtml
<!doctype html><html lang="en">  <head>    <title>Guide</title>    <link rel="stylesheet" href="site.css">  </head>  <body>    <p>Guide</p>  </body></html>

Browser Compatibility

Minimum supported versions across modern rendering engines

Chrome
1
Yes
Edge
12
Yes
Firefox
1
Yes
Safari
≤4
Yes
Opera
≤12.1
Yes
Checked desktop BCD snapshot: link element; individual rel values differ. Versions denote the recorded start of support (≤ means at least that early), not a guarantee of all behavior. Unresolved mirror and preview rows omitted.
HTML Living Standard
HTML Reference