🔥 $100K Hit! Where Will Bitcoin Go Next? Find Out Live!

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.

DataCamp
Pros
  • Easy to use with a learn-by-doing approach
  • Offers quality content
  • Gamified in-browser coding experience
  • The price matches the quality
  • Suitable for learners ranging from beginner to advanced
Main Features
  • Free certificates of completion
  • Focused on data science skills
  • Flexible learning timetable
Udacity
Pros
  • Simplistic design (no unnecessary information)
  • High-quality courses (even the free ones)
  • Variety of features
Main Features
  • Nanodegree programs
  • Suitable for enterprises
  • Paid Certificates of completion
edX
Pros
  • A wide range of learning programs
  • University-level courses
  • Easy to navigate
  • Verified certificates
  • Free learning track available
Main Features
  • University-level courses
  • Suitable for enterprises
  • Verified certificates of completion

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