Home HTML Tags <link> HTML <link> Tag Definition
Definition and Usage The <link> element describes a relationship between the current document and an external resource . It is most often used for CSS stylesheets and site icons (favicons).
It is a void element (no end tag). Put it in <head> with rel and href . Do not confuse it with <a> , which creates a clickable hyperlink.
Baseline · Widely available. Core uses (stylesheet, icon) are stable since about July 2015. Some newer values (preload, blocking) have varying support.
Obsolete: charset and rev. Do not use charset or rev on <link>. Prefer HTTP headers and the correct rel value instead.
Non-standard: target. A target attribute on <link> is non-standard. Do not rely on it in new pages.
Syntax
HTML Syntax <link rel="stylesheet" href="styles.css"> In HTML5 write <link …>. In XHTML, self-close as <link … />. There is no </link> end tag.
Reference
Attributes The attributes you will use most often on <link>:
Attribute Description Try it hrefURL of the linked resource (absolute or relative) Try itrelRelationship type — e.g. stylesheet, icon Try itmediaMedia type or query — load only when it matches Try itsizesIcon sizes when rel includes icon Try ittypeMIME type hint; omit for normal CSS stylesheets Optional asRequired with rel="preload" — resource class (font, style, …) Advanced charset / revObsolete — do not useAvoid
Try it
Live Preview Pick a common rel value and see the matching <link> markup.
Code
HTML Examples Short, copy-ready snippets. Use Try It Yourself for a live editor.
1. Stylesheet 2. Favicon 3. media query Example 1 — External Stylesheet The most common use: load CSS with rel="stylesheet".
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<p>Styled by the linked CSS file.</p>
</body> Styled by the linked CSS file. (In a real page, styles come from styles.css.)
How It Works Place <link> in <head> before body content.Set rel="stylesheet" so the browser treats the file as CSS.Point href at your CSS file path.Omit type for normal CSS — it is not required.Example 2 — Site Icon (Favicon) Tell the browser which image to use as the tab / bookmark icon.
<head>
<link rel="icon" href="favicon.ico" sizes="any">
<link rel="apple-touch-icon" href="apple-touch-icon.png">
</head> Favicon linked with rel="icon" (demo).
How It Works Use rel="icon" for the general favicon.Set href to the image file (ICO, PNG, SVG, …).Optional sizes helps the browser pick the right icon.Add platform icons (e.g. apple-touch-icon) when you need them.Example 3 — Conditional Styles with media Load a stylesheet only when a media query matches.
<head>
<link rel="stylesheet" href="print.css" media="print">
<link rel="stylesheet" href="mobile.css" media="screen and (max-width: 600px)">
</head> How It Works Keep rel="stylesheet" and add media.Use a media type like print, or a full media query.The browser may skip fetching sheets that do not match (performance win).Prefer one responsive sheet for simple sites; split sheets when files stay focused. Edge Cases & Pitfalls Most link bugs are wrong element choice, missing rel, or obsolete attributes.
confusion link is not a hyperlinkUsers click <a href>. <link> wires up resources for the browser.
rel Missing or wrong rel Without a correct relationship, the browser may ignore the resource. Use stylesheet or icon on purpose.
obsolete Do not use charset or rev Both are obsolete. Encoding comes from HTTP; reverse relations use the right rel.
paths Broken href paths A typo or wrong folder means no styles and no icon. Check DevTools Network for 404s.
body Prefer head over body Some link types are body-ok, but putting stylesheets in head is clearer and usual practice.
Compatibility
Browser Support The <link> element is core HTML in every browser. It is not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
<link> Widely available since about July 2015. stylesheet and icon work everywhere. preload / blocking features vary by browser.
98% Global support (approx.)
Google Chrome All
Full support
Mozilla Firefox All
Full support
Apple Safari All
Full support
Microsoft Edge All
Full support
Opera All
Full support
Samsung Internet All
Full support
Internet Explorer All
Supported <link> Widely supported
Bottom line: Safe for everyday CSS and icons. Treat preload and blocking as progressive enhancement.
Remember
Key Takeaways Role: <link> connects external resources; <a> is for navigation.
Basics: set rel + href in the head.
Common: stylesheet for CSS, icon for favicons.
Obsolete: never use charset or rev on link.
One line: <link rel="…" href="…"> in the head wires up CSS and icons.
UA style
Default CSS Settings <link> is metadata and does not paint a box by itself:
link {
display: none; /* typical — not shown on the page */
} What users see comes from the resources you link (CSS rules, icons), not from styling link itself.
Frequently Asked Questions What is the HTML link tag used for? The link element relates the current document to an external resource — most often a CSS stylesheet or a site icon (favicon).
Is link the same as the a tag? No. a creates a clickable hyperlink for users. link is a void metadata element that connects resources (usually in the head).
Where should I put link? Prefer the head. Some link types are allowed in the body, but keeping resource links in the head is clearer and standard practice.
Do I need type="text/css" on a stylesheet link? No. For stylesheets it is recommended to omit type — CSS is the web’s stylesheet language.
What do rel and href do? href is the URL of the resource. rel names the relationship (for example stylesheet or icon).
Are charset and rev still valid? No. Both are obsolete. Use HTTP Content-Type for encoding, and use rel with the correct link type instead of rev.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
11 people found this page helpful
Helpful Share Copy link Suggestion