Encodera

Thanks for reading!

Donate to the site — we work hard for you.

HTML & CSS reference

<link>

Links an external resource to the page: a stylesheet, the site icon, a font.

Syntax

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

Attributes

ParameterTypeDescription
relstylesheet | icon | preload | canonical | …What kind of file is linked.
hrefURLThe address of the file.
mediamedia queryOptional. Which screens the styles apply to.

Examples

Styles, an icon and a canonical link:

<!DOCTYPE html>
<html lang="en">
  <head>
    <link rel="stylesheet" href="/css/style.css">
    <link rel="icon" href="/favicon.ico">
    <link rel="canonical" href="https://example.com/menu">
    <title>Menu</title>
  </head>
  <body>
    <p>The link tags work in the background.</p>
  </body>
</html>

Notes

The tag is single and goes into <head>. An external stylesheet is the main way to add CSS: one file is cached by the browser and shared by every page of the site. With media="print" you can link separate styles for printing.

See also

  • <head> — The service part of the page: encoding, tab title, linked styles and scripts.
  • <style> — Embeds CSS right into the HTML page.
  • <meta> — Page metadata: encoding, phone settings, a description for search engines.
  • href — The address an `<a>` link leads to or a `<link>` points at.

Related recipes

In the tutorial

  • What is CSS — How a CSS rule works, where to write styles, how to attach a separate file and why comments are useful.

Thanks for reading!

Donate to the site — we work hard for you.