HTML a tag
Note: If you don't know what a 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.
Description
The
HTML a tag defines an anchor and may be used to establish a link to other document, as a bookmark on a page, or as both of them.
When used to set a bookmark you must define an id or name (use "id" for Strict
XHTML or both "id" and "name" with the same value for compatibility) to be able to point to it in other instances. The id must be unique and follow the rules described for the "name" attribute. If no "href" attribute is defined, the visual aspect of text is not changed.
Example:
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.
Example:
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.
Attributes
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.
Example:
Code begin
<p id="paragraph1">This is the first paragraph named as paragraph1. To dynamically change its properties use this identifier.</p>Code end
The "class" attribute assigns a class name (or a list of class names separated by spaces) to the container element. It's used with style sheets and tells the browser the class to which the element is associated with. A class gives visual attributes to elements.
Example:
Code begin
<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>Code end
Defines a visual style of this element. Is a better practice to define styles attributes in external style sheets grouping them in classes. Attributes in the "style" parameter must preserve this order "name : value" and be separated by a semi-colon.
If you're writing
XHTML code it's recommended not to use this attribute and try style sheet classes (with the "class" attribute).
Example:
Code begin
<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>Code end
Indicates a title for the element. Used to give a short description about the element that is usually shown as a "tool tip" when the user put the mouse pointer over the element.
Example:
Code |
View |
<a title="HTMLQuick.com" href="http://www.htmlquick.com">HTML code</a> |
HTML code |
Specifies the character encoding of the target
URL. Refer to the type definition and the reference for
character encoding for more information.
Example:
Code begin
<a charset="utf-8" href="http://www.htmlquick.com">HTML code</a>Code end
href (uri)
Specifies the destination resource for the element. Commonly used to refer to pages in the same domain name or external pages.
Example:
Code |
View |
Link to page on this site: <a href="http://www.htmlquick.com/tutorials/links.html">Links in HTML tutorial</a><br /> Link to external site: <a href="http://www.w3.org">World Wide Web Consortium</a> |
Link to page on this site: Links in HTML tutorial
Link to external site: World Wide Web Consortium |
Defines the destination resources' language. This attribute may only be used when the "href" attribute is present.
Example:
Code begin
<a hreflang="en" href="english-version.html">English version</a>Code end
Tells the browser the content type of the resource named in "href" attribute.
Example:
Code begin
<a href="logo.gif" type="image/gif">Check out our logo</a><br />
<a href="article.html" type="text/html">Read the article</a>Code end
Describes de relationship from the current document to the destination resource. In other words defines the meaning of the referred resource for the actual document.
Example:
Code begin
<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>Code end
Stablish a relationship from the resource pointed by the "href" attribute to the current document. In other words, establishes what represents the actual document for the referred resource.
Example:
Code begin
List of articles:
<a rev="index" href="article1.html">Article 1</a>
<a rev="index" href="article2.html">Article 2</a>
...Code end
shape
Specifies the form of a shape used to define an area. Values are case-insensitive and may be one of these:
- default: Specifies the entire region.
- rect: Define a rectangular region.
- circle: Define a circular region.
- poly: Define a polygonal region.
coords
Defines the coordinates and position of a shape. It's used together with the "shape" attribute, and the coordinates depend of the "shape" value:
- rect: left-x, top-y, right-x, bottom-y.
- circle: center-x, center-y, radius. If the radius is measured in percentage, its calculated as that percentage of the smaller size of the associated object.
- poly: x1, y1, x2, y2, ..., xN, yN. 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. Each coordinate is of
length type and are separated by commas.
Specifies the name of the frame where the destination document should be loaded. Refer to the
frame-target type definition for further information.
Code begin
Open in a new window: <a href="http://www.w3c.org" target="_blank">WWW Consortium</a>
Open in a frame named "content" (frame must be present in the actual frameset): <a href="http://www.w3c.org" target="content">WWW Consortium</a>Code end
Specifies the position of this element in the tabbing order. The tabbing order defines the sequence with all the elements than can receive the focus. Users can navigate this sequence via keyboard (usually with the "tab" key).
Stablish a relationship between this element and a character key, allowing the user to activate it with that key (usually when used together with the "alt" key). The activation result depends on the actual element's nature. For links, this action automatically follows the link, and other elements simply get the focus.
Defines a unique name for the element so it can be located later. It's used to set bookmarks on a page. It's recommended to use the "id" attribute instead because of its compatibility with
XHTML code.
Events
- onfocus
- onblur
- onclick
- ondblclick
- onmousedown
- onmouseup
- onmouseover
- onmousemove
- onmouseout
- onkeypress
- onkeydown
- onkeyup
See complete list and information about
events in HTML
Examples
In the description, an a tag was defined as a bookmark with the id "bookmark":
Code |
View |
To go to that bookmark at the first example for this tag, click here: <a href="#bookmark">HTML a tag example</a> |
To go to that bookmark at the first example for this tag, click here: HTML a tag example |