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 a tag

Bypass main content

HTML a tag

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

Bypass main content


The HTML a tag defines an anchor and may be used to establish a link to another document, as a bookmark on a page, or as both.

When used to set a bookmark you must define an id or name to it, so you are able to point to it in other instances. The id must be unique and follow the rules described for the "name" attribute.

Note that in XHTML 1.0, the "name" attribute for this element has been deprecated in favor of the "id" attribute. And in XHTML 1.1 it's been completely removed. Its use, in XHTML 1.0, is only recommended for backward compatibily.

<a id="bookmark1" name="bookmark1">This text is part of a bookmark named "bookmark1". We'll refer to it in other examples.</a>

When the HTML a tag is used to link to other page the "href" attribute is defined and describes the location of the referred resource. The links are usually rendered in a special way by browsers using text decorations, as color and/or underline.

<a href="http://www.w3.org/">World Wide Web Consortium</a><br />
<a href="img.html">The HTML img tag</a>

And finally, the HTML a tag may be used for both purposes. While referring to another document, this anchor will set a bookmark on this page.

<a id="doctypelink" name="doctypelink" href="http://www.htmlquick.com/reference/tags/doctype.html">The HTML !DOCTYPE tag</a>


In the description, a bookmark named "bookmark1" was defined. In the following example we'll make a link referring to that bookmark:

To go to that bookmark at the first example for this tag, follow this link: <a href="#bookmark1">HTML a tag example</a>
To go to that bookmark at the first example for this tag, follow this link: HTML a tag example


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 is used together with style sheets and tells the browser the class (or classes) to which the element is associated.

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 should be a short and accurate description of the element. Browsers usually render it as a "tool tip" when the user puts the mouse pointer over the element for a short period of time.

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

lang (langcode)

Specifies the language of an element's content. The default value is "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, as 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>


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">...a 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.

<a charset="utf-8" href="http://www.htmlquick.com">HTML code</a>

href (uri)

The "href" attribute specifies the destination resource to which the element is linked. 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.

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

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), it states the meaning of the referred resource for the actual document.

<a rel="prev" href="article1.html">Read previous article</a>
<a rel="next" href="article3.html">Read next article</a>
<a rel="copyright" href="copyright.html">Article copyrights</a>
<a rel="alternate" href="english-version.html" hreflang="en">English version</a>

rev (link-types)

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

List of articles:
<a rev="index" href="article1.html">Article 1</a>
<a rev="index" href="article2.html">Article 2</a>


Specifies the form of a shape used to define an area in an image map. Values are case-insensitive and must correspond to the ones in this list:

  • default: Selects the entire region.
  • rect: Defines a rectangular region.
  • circle: Defines a circular region.
  • poly: Defines a polygonal region.


Specifies the coordinates and position of the shape defined in the "shape" attribute. The coordinates depend on the shape used:

  • rect: left-x, top-y, right-x, bottom-y (e.g., "0, 0, 10, 10" defines a square with 10 pixels sides that touches the top and left borders of the image).
  • circle: center-x, center-y, radius (e.g., "20, 20, 20" defines a circle with a radius of 20 pixels that touches the top and peft borders of the image). If the radius is measured in percentage, it is calculated as a percentage of the smallest size of the associated object.
  • poly: x1, y1, x2, y2, ..., xN, yN (e.g., "0, 20, 20, 20, 10, 0, 0, 20" defines a triangle with a base and height of 20 pixels that touches the top and left borders of the image). This defines a closed polygon. If you define an open polygon, the browser should close it by adding a segment from the first point to the last one.

Coordinates are relative to the top-left corner of the associated object. Coordinates have a length type and are separated by commas.

<map name="red-button" id="red-button">
<area href="document.html" shape="circle" coords="25, 25, 20" alt="Access the document by pressing this red button!" />
<img src="redbtn.png" usemap="#red-button" width="50" height="50" alt="Red button">

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>

tabindex (number)

Specifies the position of this element in the tabbing order. The tabbing order defines a sequence with all the elements than can receive the focus. Users can navigate this sequence via keyboard (usually with the "tab" key).

<a href="doc1.html" tabindex="1">First document in the list</a>
<a href="doc2.html" tabindex="2">Second document in the list</a>
<a href="doc3.html" tabindex="3">Third document in the list</a>

accesskey (character)

Relates the element to a character key. Most browsers allow users to access the element by pressing that key while holding down the "alt" key. The activation result depends on the element's nature. For links, this action automatically follows the link, while other elements simply get the focus.

<a href="http://www.htmlquick.com/" accesskey="H">Homepage (H)</a>

name (name)

Defines a unique name for the element used to set bookmarks on a page.

In XHTML 1.0 the "name" attribute for this element has been deprecated in favor of the "id" attribute and in XHTML 1.1 it's simply invalid. Still, bookmarks without the "name" attribute may not be backward compatible, so unless you're writing XHTML 1.1, the best practice is to use both attributes with the same value.

<a name="first-bookmark" id="first-bookmark">Here we've placed the first bookmark on the page</a>


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

See a complete list and information about events in HTML

descar anti virus gratis

Diseño y desarrollo: Latitud29.com

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