<link>
Links an external resource to the page: a stylesheet, the site icon, a font.
Syntax
<link rel="stylesheet" href="style.css">Attributes
| Parameter | Type | Description |
|---|---|---|
| rel | stylesheet | icon | preload | canonical | … | What kind of file is linked. |
| href | URL | The address of the file. |
| media | media query | Optional. 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
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.