<link ...>

HTML4 HTML5

The <link> tag belongs to the document metadata (information about the document) and is placed alongside other metadata in the HEAD section[cite: 3]. It links the document to an external resource[cite: 3]. It is used to attach external stylesheets[cite: 3].

The opening tag is mandatory, the closing tag does not exist[cite: 3].

Attributes:

href="..." - URL of the attached resource[cite: 3].

rel="..." - (alternate, author, dns-prefetch, help, icon, license, next, pingback, preconnect, refetch, preload, prerender, prev, search, stylesheet) specifies the relationship type between the current and attached document[cite: 3]. Mandatory attribute[cite: 3].

hreflang="..." - specifies the language of the attached document[cite: 3].

rev="..." - specifies the relationship between the attached and current document[cite: 3]. Not supported in HTML5[cite: 3].

type="..." - specifies the type of the attached document[cite: 3].

media="..." - specifies on which device the document will be displayed (screen, paper, projection, braille, speech, all)[cite: 3].

target="..." - default display location for the document (_self - open in the same window/frame, _blank - open in a new window, _parent - open in the parent window/frame, _top - open in the main frame (replace all frames))[cite: 3]. Not supported in HTML5[cite: 3].

sizes="..." - (widthxheight, any)[cite: 3]. Can only occur when the rel="icon" attribute is present[cite: 3].

Example

<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" type="text/css" href="http://alg24.com/css/styles.css">  
</head>
<body>
 <h1>Chapter title formatted according to the definition in the styles.css file.</h1>
 <p>And this is a paragraph!</p>
</body>
</html>

Contents of the styles.css file:

body {
  background-color: powderblue;
}
h1 {
  color: blue;
}
p {
  color: red;