HTML <link> Tag

The <link> element defines the relationship between the document and external source. It may be used for defining a relational framework for navigation.

This tag is mostly used to link to stylesheets.

<link> element, which is an empty element, contains only attributes. It is used only in <head> section, but it can appear many times.

Syntax

The <link> tag is a no end tag and doesn't require a closing tag.

However, in XHTML the <link> tag must be properly closed (<link />).

Example

<!DOCTYPE html>
<html>
   <head>
      <link rel="stylesheet" type="text/css" href="style.css">
   </head>
   <body>
      <h1>This text is linked with style sheet.</h1>
      <p>So does this!</p>
   </body>
</html>

Result


Attributes

Attribute Value Description
charset char_encoding Defines character encoding for the linked document. It is not used anymore in HTML5.
href URL Defines linked document's location.
hreflang language_code Defines the text language in the linked document.
media media_query Defines on what device the linked document will be displayed.
rel alternate
archives
author
bookmark
external
first
help
icon
last
license
next
nofollow
noreferrer
pingback
prefetch
prev
search
sidebar
stylesheet
tag
up
Is a required attribute and defines the relationship between the current document and the linked document.
rev reversed relationship Defines the relationship between the current document and the linked document.It is not used anymore in HTML5.
sizes HeightxWeight It defines the linked resource's size but it is used only for rel="icon"
target _blank
_self
_top
_parent
frame_name
Defines where the linked document will be located.It is not used anymore in HTML5.
type media_type Defines the linked document's media type.

The <link> tag also supports the Global Attributes.