HTML <link> Tag

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

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.

HTML Syntax

syntax.html
<link rel="stylesheet" href="styles.css">

In HTML5 write <link …>. In XHTML, self-close as <link … />. There is no </link> end tag.

Attributes

The attributes you will use most often on <link>:

AttributeDescriptionTry it
hrefURL of the linked resource (absolute or relative)Try it
relRelationship type — e.g. stylesheet, iconTry it
mediaMedia type or query — load only when it matchesTry it
sizesIcon sizes when rel includes iconTry it
typeMIME type hint; omit for normal CSS stylesheetsOptional
asRequired with rel="preload" — resource class (font, style, …)Advanced
charset / revObsolete — do not useAvoid

Global Attributes

The <link> tag also supports the Global Attributes in HTML.

Live Preview

Pick a common rel value and see the matching <link> markup.

Markup

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — External Stylesheet

The most common use: load CSS with rel="stylesheet".

HTML
<head>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <p>Styled by the linked CSS file.</p>
</body>
Try It Yourself

How It Works

  1. Place <link> in <head> before body content.
  2. Set rel="stylesheet" so the browser treats the file as CSS.
  3. Point href at your CSS file path.
  4. 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.

HTML
<head>
  <link rel="icon" href="favicon.ico" sizes="any">
  <link rel="apple-touch-icon" href="apple-touch-icon.png">
</head>
Try It Yourself

How It Works

  1. Use rel="icon" for the general favicon.
  2. Set href to the image file (ICO, PNG, SVG, …).
  3. Optional sizes helps the browser pick the right icon.
  4. 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.

HTML
<head>
  <link rel="stylesheet" href="print.css" media="print">
  <link rel="stylesheet" href="mobile.css" media="screen and (max-width: 600px)">
</head>
Try It Yourself

How It Works

  1. Keep rel="stylesheet" and add media.
  2. Use a media type like print, or a full media query.
  3. The browser may skip fetching sheets that do not match (performance win).
  4. 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 hyperlink

Users 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.

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.

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.

Default CSS Settings

<link> is metadata and does not paint a box by itself:

default.css
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

The link element relates the current document to an external resource — most often a CSS stylesheet or a site icon (favicon).
No. a creates a clickable hyperlink for users. link is a void metadata element that connects resources (usually in the head).
Prefer the head. Some link types are allowed in the body, but keeping resource links in the head is clearer and standard practice.
No. For stylesheets it is recommended to omit type — CSS is the web’s stylesheet language.
href is the URL of the resource. rel names the relationship (for example stylesheet or icon).
No. Both are obsolete. Use HTTP Content-Type for encoding, and use rel with the correct link type instead of rev.

Next: listing

See the obsolete listing element and what to use instead.

listing tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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