HTML <a> Tag

The HTML <a> tag is used for creating an a element (also known as an "anchor" element).

The a element represents a hyperlink. This is usually a link to another document.

You can use the <a> tag to link text or images. You can also link a large block of content (even containing multiple elements) if required - it's not just restricted to hyperlinking single elements. However, there must be no "interactive content" descendant.

Syntax

The <a> tag is written as <a href=""></a> with the linked URL between the double quotes of the href attribute and the anchor text (i.e. the text that the user sees) between the start and end tags.

Like this:

Copy to Clipboard
<a href="http://www.great-workout.com/">Great Workout</a>.

Examples

Basic tag usage

CodeResult

Have a Great Workout.

Open the link in a new window (or tab)

Here we use target="_blank" to open the link in a new window.

CodeResult

Have a Great Workout.

Reload the new window

Here we open multiple links in a new window, but instead of a new window being opened with each link, a new window is opened with the first link, then the following links load their contents into that window.

We do this simply by giving the target attribute a name that doesn't exist (i.e. we make up our own name for the window/tab).

CodeResult

Link 1
Link 2
Link 3

Linked Image

Here we wrap the <a> around an image to create a linked image.

CodeResult

Photo of Koh Phi Phi in Thailand

No-Follow

Here we use rel="nofollow" to create a "nofollow" link. This can be used to tell search engines that you don't endorse the content at the other end of the link. The nofollow attribute value is typically used on paid links and advertising.

Many people refer to this as the "nofollow tag" but it's not actually a tag. It's not even an attribute (the attribute is rel). The nofollow bit is simply a value of the rel attribute.

CodeResult

Top Web Hosting!

Differences Between HTML 4 & HTML5

To see more detail on the two versions see HTML5 <a> Tag and HTML4 <a> Tag. Also check out the links to the official specifications below.

Template

Here's a template for the <a> tag with all available attributes for the tag (based on HTML5). These are grouped into attribute types, each type separated by a space. In many cases, you will probably only need one or two (if any) attributes. Simply remove the attributes you don't need.

For more information on attributes for this tag, see HTML5 <a> Tag and HTML4 <a> Tag.

Copy to Clipboard
<a  
 href=""=""
 target=""=""
 download=""=""
 rel=""=""
 hreflang=""=""
 type=""=""
 
 accesskey=""
 class=""
 contenteditable=""
 contextmenu=""
 dir=""
 draggable=""
 dropzone=""
 hidden=""
 id=""
 itemid=""
 itemprop=""
 itemref=""
 itemscope=""
 itemtype=""
 lang=""
 spellcheck=""
 style=""
 tabindex=""
 title=""
 translate=""

 onabort=""
 onautocomplete=""
 onautocompleteerror=""
 onblur=""
 oncancel=""
 oncanplay=""
 oncanplaythrough=""
 onchange=""
 onclick=""
 onclose=""
 oncontextmenu=""
 oncuechange=""
 ondblclick=""
 ondrag=""
 ondragend=""
 ondragenter=""
 ondragexit=""
 ondragleave=""
 ondragover=""
 ondragstart=""
 ondrop=""
 ondurationchange=""
 onemptied=""
 onended=""
 onerror=""
 onfocus=""
 oninput=""
 oninvalid=""
 onkeydown=""
 onkeypress=""
 onkeyup=""
 onload=""
 onloadeddata=""
 onloadedmetadata=""
 onloadstart=""
 onmousedown=""
 onmouseenter=""
 onmouseleave=""
 onmousemove=""
 onmouseout=""
 onmouseover=""
 onmouseup=""
 onmousewheel=""
 onpause=""
 onplay=""
 onplaying=""
 onprogress=""
 onratechange=""
 onreset=""
 onresize=""
 onscroll=""
 onseeked=""
 onseeking=""
 onselect=""
 onshow=""
 onsort=""
 onstalled=""
 onsubmit=""
 onsuspend=""
 ontimeupdate=""
 ontoggle=""
 onvolumechange=""
 onwaiting=""
	>
</a>

Tag Details

For more details about the <a> tag, see HTML5 <a> Tag and HTML4 <a> Tag.

Specifications

Here are the official specifications for the <a> element.

What's the Difference?

W3C creates "snapshot" specifications that don't change once defined. So the HTML5 specification won't change once it becomes an official recommendation. WHATWG on the other hand, develops a "living standard" that is updated on a regular basis. In general, you will probably find that the HTML living standard will be more closely aligned to the current W3C draft than to the HTML5 specification.

Enjoy this page?

Sponsored Link: Design CODE-FREE Websites

Check a Domain:

ZappyHost Logo
Webydo Banner Ad