Little Web Hut

HTML 4.01 and XHTML 1.0 Reference: <link> Tag

HTML <link> Tag
Syntax HTML syntax - This element does not require a closing tag.
<link>

XHTML syntax - This element is opened and closed, within a single tag, by adding a space followed by a forward slash at the end of the tag.
<link />
Usage The <link> tag is used to define a link to another web resource. It is often used to link to a style sheet. The <link> tag can only appear in the head section between the opening and closing <head> tags. It may also appear more than once.

HTML <link> example:
<link href="../stylesheets/stylehtml.css" rel="stylesheet" type="text/css">

XHTML <link> example:
<link href="../stylesheets/stylehtml.css" rel="stylesheet" type="text/css" />

The examples above link a style sheet to the current document. The href attribute holds the URL of the style sheet. The rel attribute defines the relationship of the link, which in this case is a style sheet. The type attribute defines the content type or media type, which in this case is again a style sheet.
Content Model The <link> element cannot contain any tags.

<link> Tag Attribute Summary
Required Tag Specific Core Focus Events Language
  charset href hreflang media rel rev target type id class style title   onclick ondblclick onkeydown onkeypress onkeyup onmousedown onmousemove onmouseout onmouseover onmouseup dir lang xml:lang1
Notes: 1. XHTML only.

<link> Tag Attributes
Attribute Description
charsetThe charset attribute specifies the character encoding for the web resource that is pointed to by the link.
hrefThe href attribute is used to specify the URL resource.

HTML <link> tag example:
<link href="../stylesheets/stylehtml.css" rel="stylesheet" type="text/css">

XHTML <link> tag example:
<link href="../stylesheets/stylehtml.css" rel="stylesheet" type="text/css" />
hreflangThe hreflang attribute specifies the language code of the web resource that is pointed to by the link.
mediaThe media attribute is used to specify the target medium for the style information. Possible values include "all", "aural", "braille", "handheld", "print", "projection", "screen", "tty", "tv". More than one value can be specified by separating them with commas.

The following HTML example specifies a style sheet to be used when the document is printed:
<link href="printstyle.css" media="print" rel="stylesheet" type="text/css">

The following XHTML example specifies a style sheet to be used when the document is printed:
<link href="printstyle.css" media="print" rel="stylesheet" type="text/css" />
relThe rel attribute is a space-separated list which specifies a relationship between the current web resource and the web resource that is pointed to by the link. The relationship is from the current web resource to the linked current web resource.

Possible values include "alternate", "appendix", "bookmark", "chapter", "contents", "copyright", "glossary", "help", "index", "next", "prev", "section", "start", "stylesheet", "subsection".

HTML <link> tag example:
<link href="../stylesheets/stylehtml.css" rel="stylesheet" type="text/css">

XHTML <link> tag example:
<link href="../stylesheets/stylehtml.css" rel="stylesheet" type="text/css" />
revThe rev attribute attribute is a space-separated list which specifies a relationship between the web resource that is pointed to by the link and the current web resource. The relationship is to the current web resource from the linked current web resource.

Possible values include "alternate", "appendix", "bookmark", "chapter", "contents", "copyright", "glossary", "help", "index", "next", "prev", "section", "start", "stylesheet", "subsection".
targetThe target attribute specifies a target where the link can be opened.
typeThe type attribute specifies the content type of the web resource that is pointed to by the link.

HTML <link> tag example:
<link href="../stylesheets/stylehtml.css" rel="stylesheet" type="text/css">

XHTML <link> tag example:
<link href="../stylesheets/stylehtml.css" rel="stylesheet" type="text/css" />
idThe id attribute assigns a unique name to a tag. This allows style sheets or scripts to reference the tag. See id Example
classThe class attribute assigns a class name to a tag. The class name does not need to be unique. More than one tag can have the same class name. This allows style sheets or scripts to reference multiple tags with a single class name. See class Example
styleThe style attribute specifies styles for the tag. For Cascading Style Sheets (CSS), the syntax is name:value. Each name:value pair is separated by semicolons. See style Example
titleThe title attribute specifies additional information about the tag. It is common for browsers to display the title when the pointing device stops over the object. See title Example
onclickThe onclick attribute specifies a script to be run when the object is clicked with a mouse or other pointing device. See onclick Example
ondblclickThe ondblclick attribute specifies a script to be run when the object is double clicked with a mouse or other pointing device. See ondblclick Example
onkeydownThe onkeydown attribute specifies a script to be run when a key is pressed down. See onkeydown Example
onkeypressThe onkeypress attribute specifies a script to be run when a key is pressed and released. See onkeypress Example
onkeyupThe onkeyup attribute specifies a script to be run when a key is released. See onkeyup Example
onmousedownThe onmousedown attribute specifies a script to be run when the mouse button, or other pointing device button, is pressed while over the object. See onmousedown Example
onmousemoveThe onmousemove attribute specifies a script to be run when the mouse, or other pointing device, is moved while it is over the object. See onmousemove Example
onmouseoutThe onmouseout attribute specifies a script to be run when the mouse, or other pointing device, is moved away from an object after being over it. See onmouseout Example
onmouseoverThe onmouseover attribute specifies a script to be run when the mouse, or other pointing device, is moved onto the object. See onmouseover Example
onmouseupThe onmouseup attribute specifies a script to be run when the mouse button, or other pointing device button, is released while over the object. See onmouseup Example
dirThe dir attribute tells the browser whether the text should be displayed from left-to-right or right-to-left. It does not reverse the direction of the characters, like the <bdo> tag does, but it can help the browser to determine if the text should be aligned on the left side or the right side. See dir Example
langThe lang attribute specifies a language. This attribute can help the browser to correctly display text. This attribute can also be useful for braille translation software, speech synthesizers, dictionary definitions, etc. See lang Example
xml:langThe xml:lang attribute specifies a language for XHTML documents. This attribute can help the browser to correctly display text. This attribute can also be useful for braille translation software, speech synthesizers, dictionary definitions, etc. See xml:lang Example

Note: XHTML only.