HTML Tags – Link Tag


What is the HTML <link> tag ?

HTML <link> tag defines the relationship between the current HTML document and an external resource.

HTML <link> tag represents the relationship between a current document and one or more external CSS stylesheets.

HTML <link> tags is placed inside the <head> section of the document.

How HTML <link> tag works ?

HTML <link> tag is most often used to link to external style sheets.

HTML <link> tag loads the external CSS style sheet files along with the HTML document.

HTML <link> tag is also used to establish site icons like “favicon”, “style icons” and other “icons” inside the home screen.

Why is the HTML <link> tag used ?

HTML <link> tag is used to load an external stylesheets into an HTML document.

CSS properties can be written inside the HTML document but if its a big website and it contains lot of UI components, then we have to write lot of code inside the same HTML document and this results in a lengthy HTML document.

To avoid this lengthy HTML document, HTML <link> tag is used to have the CSS codes in separate file and we can load the CSS files along with the HTML document.


HTML <link> tag helps us in debugging the CSS properties easily.

HTML beginners tutorial !!!

Click to Learn More about – HTML Tutorial for beginners

Syntax :

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

Example :


<!DOCTYPE html>
<html>

<head>
    <title>HTML Link Tag</title>
    <link rel="stylesheet" type="text/css" href="styles.css">
</head>

<body>
    <h1>Welcome to CStechbook</h1>
    <h2>HTML Link Tag</h2>
</body>
</html>

CSS

h1 {
    color: blue;
}

h1, h2{
    text-align: left;
}

Output :

<link> Tag Attributes

HTML <link> tag support following specific attributes.

SnoAttributesValueDescription
1crossoriginanonymous
use-credentials
Specify how to handle CORS.
anonymous Cross-origin request perform without any credential.
use-credentials Cross-origin request perform with sent credential.
2hrefURLSpecify the URL of the external linked resource.
3hreflanglang_codeSpecify the language of the text in the external linked resource.
4mediaall
print
screen
speech
Specify the media device, external resource will be displayed for that device.
The default value is all.
5relalternate
author
canonical
help
icon
license
manifest
next
pingback
prefetch
preload
prerender
prev
search
shortlink
stylesheet
Required. Specify the relationship of the external linked document.
6sizesHEIGHTxWIDTH
any
Specify the size of icons (favicons) that are linked externally. Example: sizes=”any” (any size)
sizes=”16×16″ (1 size)
sizes=”16×16 32×32 64×64″ (3 sizes)
7typeMIME_typeSpecify the mime type of the external linked document.
Following attribute has been removed in HTML5.
8charsetcharsetSpecify the character encoding of the external linked document.
9revalternate
author
canonical
help
icon
license
manifest
next
pingback
prefetch
preload
prerender
prev
search
shortlink
stylesheet
Specify the reverse relationship of the external linked resource to current document.
10target_blank
_parent
_self
_top
Specify the location where to load external linked document.

Global Attributes

HTML <link> tag does not support any global attributes.

Event Attributes

HTML <link> tag does not support any event attributes.

Browser Compatibility

SnoBrowserSupport
1ChromeYes
2FirefoxYes
3EdgeYes
4OperaYes
5SafariYes
6Internet ExplorerYes