Live Preview
A styled card demonstrating CSS loaded via an external stylesheet link:
External CSS Applied
The <link rel="stylesheet"> tag connects CSS files to your HTML document.

By the end of this tutorial, you’ll connect external CSS, favicons, and preloaded assets with <link> in the document head.
Use rel and href to declare linked resources.
Load external CSS with rel="stylesheet".
Set tab icons with rel="icon".
Fetch critical fonts and assets early.
Know when to use head resources vs body links.
Place links in <head> and pick correct rel values.
<link> Tag?The link element (<link>) connects external resources to an HTML document. It lives in the <head> and tells the browser about stylesheets, icons, fonts, and other assets the page needs — without displaying content on the page itself.
The <link> tag loads document resources in the head. The <a> tag creates clickable hyperlinks in the body for users to navigate. Do not confuse them.
Every modern website uses <link> for CSS files and favicons. Performance-focused sites also use it for preloading fonts, preconnecting to CDNs, and declaring canonical URLs.
<link> is a void element placed inside <head>:
<head>
<link rel="stylesheet" href="styles.css">
</head><link> inside <head>, not in the body.rel attribute describing the relationship.href to point to the resource URL or path.| rel value | Code Snippet | Purpose |
|---|---|---|
stylesheet | <link rel="stylesheet" href="styles.css"> | External CSS |
icon | <link rel="icon" href="favicon.ico"> | Browser tab icon |
preload | <link rel="preload" href="font.woff2" as="font"> | Early asset fetch |
preconnect | <link rel="preconnect" href="https://fonts.gstatic.com"> | Early connection to origin |
canonical | <link rel="canonical" href="https://…"> | Preferred URL for SEO |
alternate | <link rel="alternate" hreflang="fr" href="…"> | Language or feed alternate |
<link> vs <a>Both involve URLs, but they serve completely different roles:
| Feature | <link> | <a> |
|---|---|---|
| Location | <head> | <body> |
| Purpose | Load resources (CSS, icons, fonts) | User navigation hyperlinks |
| Visible | No — metadata only | Yes — clickable content |
| Key attribute | rel + href | href |
| Element type | Void (self-closing) | Container with closing tag |
<link> vs Inline <style>| Approach | When to use | Notes |
|---|---|---|
<link rel="stylesheet"> | Shared CSS across pages | Cached by browser, best for production |
<style> | Page-specific or critical CSS | Inline in head, not cached separately |
| Both together | Critical CSS inline + main CSS linked | Common performance pattern |
The <link> element uses relationship and resource attributes plus globals:
rel RequiredDefines the relationship: stylesheet, icon, preload, preconnect, canonical, and more.
rel="stylesheet"href Required*URL or path to the linked resource.
href="/css/main.css"type OptionalMIME type of the resource. Optional for CSS in HTML5.
type="image/png"as preloadRequired with rel="preload" — tells the browser the asset type: font, script, style, etc.
as="font"crossorigin CORSRequired for cross-origin font preloads. Use anonymous or use-credentials.
crossorigin="anonymous"media ResponsiveApply a stylesheet only for matching media queries, e.g. print or mobile layouts.
media="(max-width: 768px)"* href is required for most rel values that reference an external resource.
Stylesheets, favicons, and font preloading — the three most common <link> patterns.
A styled card demonstrating CSS loaded via an external stylesheet link:
External CSS Applied
The <link rel="stylesheet"> tag connects CSS files to your HTML document.
The most common use of <link> — connecting an external CSS file. The type attribute is optional in HTML5.
<head>
<link rel="stylesheet" href="styles.css">
</head>Use <link> for external CSS, favicons, font preloading, CDN preconnect hints, canonical URLs for SEO, alternate language pages, and web app manifest files.
Set the small icon shown in browser tabs and bookmarks with rel="icon".
<link rel="icon" type="image/png" href="favicon.png">Fetch critical assets early with rel="preload". Use as to declare the resource type and crossorigin for cross-origin fonts.
<link rel="preload" href="font.woff2" as="font" type="font/woff2" crossorigin>The <link> tag itself has no visual appearance. It loads external CSS that styles your page content:
rel="stylesheet" Loads external CSSmedia Conditional stylesheetspreload Faster font/CSS loadpreconnect Early CDN connection/* Main stylesheet for all screens */
<link rel="stylesheet" href="main.css">
/* Print-only stylesheet */
<link rel="stylesheet" href="print.css" media="print">
/* Mobile layout stylesheet */
<link rel="stylesheet" href="mobile.css" media="(max-width: 768px)">Styled card (simulates linked CSS result)
Typography & Colors
External CSS controls fonts, spacing, colors, and layout across your entire site.
Although <link> is not interactive, it affects how users experience your page:
media thoughtfully — load print or mobile stylesheets without hiding essential content from any user group.<a> in the body for user-facing links so keyboard and screen reader users can interact with them.Declare rel and href for each external resource.
Determines whether to fetch CSS, an icon, or preload an asset.
Browser downloads the file from href and applies or stores it.
CSS styles the layout, favicons brand the tab, and preloaded assets render faster.
The <link> element is fully supported in all browsers. Modern rel values like preload and preconnect are supported in all current browsers.
Stylesheets, favicons, and document relationships via <link> are supported from legacy IE through the latest mobile browsers.
Bottom line: Use <link> confidently for CSS, favicons, and resource hints in every production environment today.
The <link> tag is essential for connecting external resources to your HTML documents. From stylesheets and favicons to performance hints like preload and preconnect, it keeps your head metadata organized and your pages fast and styled.
Remember: place links in <head>, choose the correct rel value, and use <a> — not <link> — for user-facing navigation.
<link> elements inside <head>rel="stylesheet" for external CSS filescrossorigin when preloading cross-origin fonts/css/main.css on your site<link> with <a> for navigation<link> in the body for standard resourcestype="text/css" as if it were required<link>Bookmark these before you ship — they’ll keep your head metadata correct and your pages fast.
<link> connects external files to a document.
rel="stylesheet" loads external CSS.
Link is for resources; anchor is for navigation.
Comparisonrel="icon" sets the browser tab icon.
Fetch critical fonts and assets early.
PerformanceWorks in every browser, including legacy IE.
Compatibility<head>.<head>. It is metadata, not visible page content.<link> loads resources in the head. <a> creates clickable links in the body for users.type is optional for stylesheets because CSS is the default.as to specify the asset type, such as font or script.Try stylesheets, favicons, and font preloading in the interactive editor.
6 people found this page helpful