**`<link>`** is a void element, almost always placed in `<head>`, that connects the current document to an external resource. The **`rel`** attribute defines the relationship: `rel="stylesheet"` loads CSS, `rel="icon"` sets the favicon, `rel="canonical"` tells search engines the preferred URL for duplicate/similar content, and `rel="preload"` hints the browser to fetch a critical resource earlier than it normally would.
1Understanding <link>
`<link>` is a void element, almost always placed in <head>, that connects the current document to an external resource. The `rel` attribute defines the relationship: rel="stylesheet" loads CSS, rel="icon" sets the favicon, rel="canonical" tells search engines the preferred URL for duplicate/similar content, and rel="preload" hints the browser to fetch a critical resource earlier than it normally would.
rel="canonical" is one of the most important SEO tags on a site with any URL variations (with/without trailing slash, query params, etc.) — it tells Google which version is the 'real' one to index and rank.
<head>
<link rel="stylesheet" href="/styles.css">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<link rel="canonical" href="https://example.com/page">
</head>2Practical Example
Here is a real-world application of <link> showing how it is used in production HTML.
<!-- Preloading a critical font for faster rendering -->
<link rel="preload" href="/fonts/main.woff2" as="font" type="font/woff2" crossorigin>3Best Practices
Follow these guidelines when working with <link>:
1. Load your main stylesheet via <link rel="stylesheet"> in <head> so styles apply before content paints
2. Always set a favicon with <link rel="icon">
3. Use <link rel="canonical"> on pages that could be reached via multiple URLs to avoid duplicate-content SEO issues
Tip: rel="canonical" is one of the most important SEO tags on a site with any URL variations (with/without trailing slash, query params, etc.) — it tells Google which version is the 'real' one to index and rank.
<head>
<link rel="stylesheet" href="/styles.css">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<link rel="canonical" href="https://example.com/page">
</head>