Codectionary / Developer documentation / HTML

<link>

The <link> element establishes a relationship between the current document and an external resource, most commonly a stylesheet. It lives in the <head> and is a void element. Beyond stylesheets, <link> is also used for favicons, preloading resources, and specifying alternate versions of a page.

Syntax

<link rel="stylesheet" href="styles.css">

Examples

Linking a Stylesheet

The most common use — connecting an external CSS file.

<link rel="stylesheet" href="/css/main.css">

Favicon

Setting the small icon shown in browser tabs.

<link rel="icon" type="image/png" href="/favicon.png">

Preloading a Font

Hinting the browser to fetch a critical resource earlier.

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

Attributes

  • rel (stylesheet | icon | preload | canonical): The relationship between the current document and the linked resource
  • href (URL): The path to the linked resource
  • type (string): The MIME type of the linked resource

Best practices

  • Place stylesheet <link> tags in <head> so styles are ready before content renders, avoiding a flash of unstyled content
  • Use rel="preload" sparingly, only for genuinely critical above-the-fold resources
  • Always include a favicon link — browsers will request /favicon.ico by default even without one, so being explicit avoids wasted requests
  • Use rel="canonical" to tell search engines the preferred URL when the same content is reachable from multiple paths

At a glance

Purpose
Structure and meaning for web content
File extension
.html · .htm
Runs in
Web browsers
Usually used with
CSS and JavaScript

Specifications & further reading

Related HTML documentation