Go to main content
Bypass navigation bar HTML Reference HTML Tags HTML Tutorials
Bypass language selection
Bypass location bar

Location: Home > HTML Reference > HTML Tags > HTML link tag

Bypass main content

HTML link tag

Note: If you don't know what an element/tag is and/or how you must use it we recommend you to read our HTML tags and attributes tutorial that you can find in our HTML tutorials section.

Bypass main content

Description

The HTML link element is very similar to the HTML a element because it's used to link a document to other resources. But unlike it, the HTML link element can only be defined in the head section of the document (HTML head element) and is used to provide global relational information about the document.

For example, authors can link to a document that acts as index for the current document, to an alternate version in other language, or an alternate version designed for other media (e.g., a printer).

A particular and very common use for the HTML link tag is to provide an external style sheets file for the document. To find extra information about this practice, visit our "Cascading Style Sheets" tutorial.

Examples

In the next example, the following relational information about the current document is provided: an index, the previous document in the sequence, the next socument in the sequence, an alternate version for printer, an alternate version in spanish and a file containg style sheets information.

<head>
<title>Chapter two</title>
<link rel="index" href="../index.html" />
<link rel="prev" href="chapter1.html" />
<link rel="next" href="chapter3.html" />
<link rel="alternate" media="print" href="chapter2-printer.html" />
<link rel="alternate" hreflang="es" href="chapter2-es.html" />
<link type="text/css" href="basic.css" media="screen" />
</head>
...Document's body...

Attributes

id (name)

The "id" attribute assigns an identifier to the associated element. This identifier must be unique in the document and can be used to refer to that element in other instances (e.g., from client-side scripts).

<p id="paragraph1">This is the first paragraph, named "paragraph1". To dynamically change its properties use this identifier.</p>

class (cdata)

The "class" attribute assigns a class name (or a list of class names separated by spaces) to the container element. It's used together with style sheets and tells the browser the class (or classes) to which the element is associated with.

A class gives presentational attributes to elements (read more at the Cascading Style Sheets tutorial).

<p class="references">This article is based on the book "Wind in the trees" by Jhon L. Brooks</p>
<p class="references important">This article is based on the book "Wind in the trees" by Jhon L. Brooks... and is more important than the one before.</p>

style (style)

This attribute is used to define presentational attributes for the containing element, and its value should be composed by style sheets properties. Although, in some cases, it can become useful, a better practice is to place presentational attributes in external files, relating them to elements with the "class" attribute. This way you keep the semantic and presentational parts of your document separated.

You can find more information about presentational attributes at the Cascading Style Sheets tutorial.

<p style="color: #0000FF; font-size: 12pt">This is a paragraph with a defined style.</p>
<p>And this is another text without style.</p>

title (text)

The purpose of this attribute is to provide a title for the element. Its value must be a short and accurate description of the element. Browsers usually render it as a "tool tip" when the user put the mouse pointer over the element for a small period of time.

Code
<a title="HTMLQuick.com" href="http://www.htmlquick.com">HTML code</a>
View

lang (langcode)

Specifies the language of an element's content. The default value in "unknown".

When writing XHTML 1.0 documents, the attribute used to specify the language of an elements is "xml:lang". For forward and backward compatibility both attributes can be used simultaneously like in the example below. Note, that in XHTML 1.1 the "lang" attribute has been completely replaced by "xml:lang" and its use is no longer valid.

<p lang="en" xml:lang="en">This is a paragraph in english.</p>
<p lang="es" xml:lang="es">Este es un párrafo en español.</p>

dir

This attribute indicates the direction in which the texts of the element must be read. This includes content, attribute values and tables. It has two possible values that are case-insensitive:

  • RTL: Right to left.
  • LTR: Left to right.
<q lang="he" dir="rtl">...an Hebrew quotation...</q>

charset (charset)

Specifies the character encoding of the destination document. For more information on how to fill this attribute, refer to the character encodings reference.

<link charset="utf-8" href="http://www.htmlquick.com/" rel="index" />

href (uri)

The "href" attribute specifies the destination resource, which the element is linking to. It may specify a resource in the same website or in an external one.

Link to page on this site: <a href="http://www.htmlquick.com/tutorials/links.html">Links in HTML tutorial</a>
Link to external site: <a href="http://www.w3.org">World Wide Web Consortium</a>

hreflang (langcode)

States the language the destination document is written in. This attribute may only be used when the "href" attribute is present in the element.

<link hreflang="en" href="english-version.html" />

type (content-type)

This attribute Provides information about the content type of the destination resource, telling wether it's an HTML document, a JPG image, an Excel document, etc. Its value should be one of the MIME types.

<a href="logo.gif" type="image/gif">Check out our logo</a><br />
<a href="article.html" type="text/html">Read the article</a>

rel (link-types)

Describes the relationship that keeps the current document with the destination resource. In other words (more specific) states the meaning of the referred resource for the actual document.

<link rel="prev" href="article1.html" />
<link rel="next" href="article3.html" />
<link rel="copyright" href="copyright.html" />
<link rel="alternate" href="english-version.html" hreflang="en" />

rev (link-types)

Establishes a relationship between the destination resource and the current document. In other words (more specific), states what the actual document represents for the referred resource.

List of articles:
<link rev="index" href="article1.html" />
<link rev="index" href="article2.html" />

target (frame-target)

Specifies the name of the frame where the destination document should be loaded. Refer to the frame-target type definition for further information.

Opens in a new window: <a href="http://www.w3c.org" target="_blank">WWW Consortium</a>
Opens in a frame named "content" (frame must be present in the actual frameset): <a href="http://www.w3c.org" target="content">WWW Consortium</a>

media (media-descriptor)

Specifies the media for which the destination resource has been designed. It can be a single media or a comma-separated list of medias. The default value is "screen".

<link type="text/css" href="printer.css" media="print" />

Events

  • onclick
  • ondblclick
  • onmousedown
  • onmouseup
  • onmouseover
  • onmousemove
  • onmouseout
  • onkeypress
  • onkeydown
  • onkeyup

See a complete list and information about events in HTML

Diseño y desarrollo: Latitud29.com

Links and logos|Contact|Beyond HTML|Tools and resources|Sitemap|Webmaster|Donate