Home / Learn HTML / Link rel Values and Resource Hints

Link rel Values and Resource Hints

The rel attribute tells the browser how a linked file relates to your page. Some values make pages load faster.

In shortpreload what you need now, prefetch what you need next, preconnect to other servers.

Theory in plain words

Early hintspreconnectpreloadprefetchFaster page
Early hints

What it is

Resource hints such as preload, preconnect and prefetch tell the browser what it will need soon.

Why we use it

They make pages load faster by starting work early.

How it works

link rel values give hints. The browser may start connections or downloads before it needs them.

Where it is used

  • Preloading fonts
  • Connecting to CDNs
  • Prefetching next pages

Common rel values

relUse it for
stylesheetA CSS file
icon, apple-touch-iconFavicon and phone home-screen icon
manifestThe web app manifest
canonicalThe preferred URL of a page (SEO)
alternateOther versions: language (hreflang), RSS feed
prev, nextPages in a series
author, licenseWho wrote it and under which licence
searchAn OpenSearch description
nofollow, sponsored, ugcOn links: hints for search engines
noopener, noreferrerOn links that open a new tab: safety and privacy

Resource hints: load faster

HintWhat it doesWhen
preloadDownload now with high priorityA font, hero image or key script used on this page
prefetchDownload later with low priorityThe next page the visitor will probably open
preconnectOpen the connection (DNS, TCP, TLS) earlyA CDN or font server you will use soon
dns-prefetchOnly look up the DNS nameA cheaper hint for many third-party hosts
modulepreloadDownload and parse a JavaScript moduleModules used on this page
Examples in the head
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="preload" href="/fonts/inter.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" as="image" href="/img/hero.webp" fetchpriority="high">
<link rel="prefetch" href="/next-page.html">
<link rel="modulepreload" href="/js/app.js">
Careful:A font preload needs crossorigin, even for your own domain. Without it the file is downloaded twice. Do not preload everything: too many hints slow the page down.

Import maps and speculation rules

Import map: short names for modules
<script type="importmap">
{ "imports": { "lodash": "https://cdn.jsdelivr.net/npm/lodash-es@4/lodash.js" } }
</script>
<script type="module">
  import { chunk } from "lodash";
  console.log(chunk([1, 2, 3, 4], 2));
</script>
Speculation rules: prerender a likely next page (Chrome)
<script type="speculationrules">
{ "prerender": [ { "urls": ["/pricing.html"] } ] }
</script>
Fetch priority on an imageTry it Yourself

fetchpriority="high" tells the browser this image matters most.

Quick quiz

1. Which hint downloads a file needed on THIS page right now?

2. Why does a font preload need crossorigin?

3. Which rel gives the preferred URL for SEO?

Common questions

Which hint downloads a file needed on THIS page right now?

preload. preload is high priority for the current page.

Why does a font preload need crossorigin?

Fonts are always fetched in CORS mode. Without it the file is fetched twice.

Which rel gives the preferred URL for SEO?

canonical. rel=canonical tells search engines the main version.

My notes
Ask a question about this lesson