It’s Festive Season! Enjoy 30% Off

Use code FESTIVE30 at checkout

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

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

Mobile browser support

Browser image
Chrome
All
Browser image
Firefox
4+
Browser image
Opera
All
Browser image
Safari
All