Code has been added to clipboard!

HTML link Tag

Reading time 2 min
Published Jun 29, 2017
Updated Oct 2, 2019
  • By using HTML link tag, you can set a link between a document and an external resource.
  • Unlike the <a> tag which is written in the <body> element, HTML link tag has to be placed in the <head>.
  • HTML link tag is typically used to link CSS to HTML for external stylesheets.
  • You don't need to use the ending tag.

Using the link tag, HTML document can be linked with an external resource:

Example
<link rel="stylesheet" type="text/css" href="style_file.css">

This tag is often used to link stylesheet to a document that needs to be styled. However, by including link tag, HTML icons can be established as well.

The href attribute adds a path (URL) to the external document:

Example
<link rel="stylesheet" type="text/css" href="style_file.css">

hreflang sets the linked document's language:

Example
<link rel="stylesheet" type="text/css" hreflang="en" href="style_file.css">

Note: you can only use hreflang alongside href.

media defines what type of device the linked material is optimized for:

Example
<link rel="stylesheet" type="text/css" href="print.css" media="print">

rel defines the current document's and the linked document's relationship:

Example
<link rel="stylesheet" type="text/css" href="theme.css">

sizes sets the size for the icon in the linked resource:

Example
<link rel="icon" href="character.gif" type="image/gif" sizes="20x20">

Note: you can only use sizes when HTML rel has a value of an icon.

target specifies where the linked document is to be loaded:

Example
<link rel="parent" href="character.htm" target="_blank">

Note: usually this attribute is assigned for the linked page to load in another tab (not on the current page). The value needed in this case is _blank.

charset defined the linked document's character encoding:

Example
<link charset="UTF-8" href="file">

Tip: instead of charset, you can include a Content-Type HTTP header in the external file.

rev defined the linked document's and the current document's relationship:

Example
<link rev="parent" href="doggo.htm">

Tip: instead of rev, you can use HTML rel.

Browser support

Chrome
1+
Edge
All
Firefox
1+
IE
All
Opera
All
Safari
All

Mobile browser support

Chrome
All
Firefox
4+
Opera
All
Safari
All
Basics
Introduction
Syntax
Editors
Basic Examples
Head Section
<!DOCTYPE>
Tags and Elements
Semantic Elements
Tags Reference
Attributes
Comments
Block and Inline Elements
Forms
Form Elements
Input
Responsive Web Design
Inline Scripts
Uniform Resource Locator
Redirect
XHTML
Geolocation
Drag and Drop
Local Storage
Web Workers
Server-Sent Events
Character Encoding
Text Formatting
Quotation and Citation Elements
Headings
Paragraphs
Links
Tables
Lists
Symbols
Space
Tab
Styles
Computer Code
Layout
Classes
Colors
Images
iframes
Audio Player
Video Player
YouTube Videos
Multimedia
Canvas
SVG
<!-- -->
<a>
<abbr>
<acronym> DEPRECATED
<address>
<applet> DEPRECATED
<article>
<aside>
<audio>
<b>
<base>
<basefont> DEPRECATED
<bdi>
<bdo>
<big> DEPRECATED
<blink> DEPRECATED
<blockquote>
<body>
<br>
<button>
<canvas>
<caption>
<center> DEPRECATED
<cite>
<code>
<col>
<colgroup>
<datalist>
<dd>
<del>
<details>
<dfn>
<dialog>
<dir> DEPRECATED
<div>
<dl>
<dt>
<em>
<embed>
<fieldset>
<figcaption>
<figure>
<font> DEPRECATED
<footer>
<form>
<frame> DEPRECATED
<frameset> DEPRECATED
<h1> – <h6>
<head>
<header>
<hr>
<html>
<i>
<iframe>
<img>
<input>
<ins>
<kbd>
<keygen> DEPRECATED
<label>
<legend>
<li>
<link>
<main>
<map>
<mark>
<menu>
<menuitem> DEPRECATED
<meta>
<meter>
<nav>
<noframes> DEPRECATED
<noscript>
<object>
<ol>
<optgroup>
<option>
<output>
<p>
<param>
<pre>
<progress>
<q>
<rp>
<rt>
<ruby>
<s>
<samp>
<script>
<section>
<select>
<small>
<source>
<span>
<strike> DEPRECATED
<strong>
<style>
<sub>
<summary>
<sup>
<table>
<tbody>
<td>
<tfoot>
<th>
<thead>
<time>
<title>
<tr>
<track>
<tt> DEPRECATED
<u>
<ul>
<var>
<video>
<wbr>