<link> Tag in HTML

Quick facts

CategoryMetadata content (and phrasing content for body-allowed types such as stylesheet)
Content modelEmpty — it’s a void element
Tag omissionVoid element — no end tag, ever
Permitted parentsA <head> element (stylesheet and preload links may also appear in the body)
DOM interfaceHTMLLinkElement

Syntax

<link rel="stylesheet" href="style.css"> <link rel="icon" href="/favicon.ico"> <link rel="canonical" href="https://example.com/page/">

Live example

Edit the code below and watch the preview update instantly.

index.html
Preview

Attributes

AttributeDescription
relThe relationship: stylesheet, icon, canonical, preload, preconnect, alternate, manifest…
hrefThe URL of the linked resource
asWith preload: what kind of file it is, e.g. font, image, script
typeThe file’s format, e.g. image/svg+xml for an SVG icon
mediaOnly applies the resource for a media query, e.g. a print stylesheet
sizesIcon sizes, e.g. 180x180 for an Apple touch icon
hreflangWith alternate: the language of a translated version of the page
crossorigin / integritySecurity options for files loaded from another domain

Common examples

A complete favicon set

An SVG icon for modern browsers, a PNG fallback, and an Apple touch icon for iPhone home screens.

<link rel="icon" href="/favicon.svg" type="image/svg+xml"> <link rel="icon" href="/favicon-32.png" sizes="32x32" type="image/png"> <link rel="apple-touch-icon" href="/apple-touch-icon.png">

A canonical URL

Tell search engines which address is the main one when the same page is reachable at several URLs (with tracking parameters, for example).

<link rel="canonical" href="https://example.com/blog/html-tips/">

Preload a web font

Fonts are discovered late, so preloading the main one avoids a flash of fallback text. Font preloads need crossorigin, even on your own domain.

<link rel="preload" href="/fonts/inter.woff2" as="font" type="font/woff2" crossorigin>

<link rel=”stylesheet”> vs CSS @import

Both load a CSS file, but they behave differently. A <link rel="stylesheet"> in the HTML is found immediately, so the browser can download several stylesheets in parallel. An @import inside a CSS file is only discovered after that first file has downloaded, so the files load one after another and the page appears later.

For page speed, prefer <link> tags. @import is still handy inside build tools that combine your CSS into a single file before it ever reaches the browser.

<link rel=”stylesheet”>@import
Where it goesHTML <head>Inside a CSS file
DownloadsIn parallelOne after another
Page speedBetterSlower

Common mistakes to avoid

  • Wrong paths or capital letters. Style.css and style.css are different files on most servers; a broken path fails silently and the page loses its styles.
  • Preloading too much. Preload only the one or two files the page needs straight away; preloading everything slows down the important ones.
  • A canonical that points to the wrong page. Pointing every page at the homepage, or at a page that redirects, can drop your pages from Google. Use the page’s own full URL.
  • Font preloads without crossorigin. The browser then downloads the font twice.

Accessibility & SEO tips

  • Use absolute URLs (starting with https://) in rel="canonical" and rel="alternate" links.
  • For translated pages, add <link rel="alternate" hreflang="es" href="…"> so Google shows each visitor the right language.
  • Add <link rel="preconnect"> for important third-party hosts such as a font service, to save time on the first request.

Browser support

Supported in every browser. Newer rel values such as preload and preconnect work in all current browsers; older browsers simply ignore values they don’t know.

Related tags

Frequently asked questions

What is the difference between <link> and <a>?
<a> creates a clickable link for visitors. <link> is an invisible connection for the browser, such as loading a stylesheet or declaring an icon, and goes in the <head>.
What does rel="canonical" do?
It tells search engines which URL is the main version of a page, for example when the same content is reachable at several addresses. Google then concentrates ranking signals on that one URL.
What is the difference between preload and preconnect?
preload downloads a specific file early because the page will definitely need it, such as a font. preconnect only opens the connection to another server in advance, which saves time when files from that server are requested later.
How do I add a favicon to my website?
Upload the icon file and add <link rel="icon" href="/favicon.svg" type="image/svg+xml"> (or a PNG/ICO) in the <head> of every page. On WordPress, you can also set a "Site Icon" in Appearance → Customize.
Does the order of <link> tags matter?
For stylesheets, yes: when two files set the same property, the one loaded later wins. Put your own stylesheet after any framework or theme CSS you want to override.
Can <link> tags go in the <body>?
Stylesheet links are allowed in the body, but CSS that arrives late can make the page flash or shift. Keep them in the <head> whenever you can.