HTML5 Reference

HTML <a> tag

Definition

The <a> tag is used to define a link in two ways:

To another part of the current document using the href attribute in conjunction with the id attribute.

This is commonly known as a link.

To another document using the href attribute.

This is commonly known as a hyperlink.

Example


Link:
<p><a href="#beefpie">Beef Pie Link</a></p>
When clicked will move the webpage to the link below:
<p><h3 id="beefpie">Link To Same Page</h3>
Hyperlink:
<p><a href="http://htmldoctor.info/htmlbasics/lotsofpies.html">Hyperlink</a></p>
When clicked will display the webpage:
http://htmldoctor.info/htmlbasics/lotsofpies.html

Attributes

The following attributes can be used with the <a> tag.


url
<a> Specific Attributes
Attribute Value Description Example
downloadresource [value]Specifies that the link is to be used for downloading a resource, which can optionally have a value.

<a href="../images/apple.jpg"
   download>Chicken Pie</a> 
<a href="../images/apple.jpg"
   download="resource.fileExt">Apple</a>
hrefSpecifies the URL to link to.

<a href="../images/apple.jpg">Apple</a>
hreflanglanguage_codeSpecifies the language of target URL to link to.
Should be only be used when the href attribute is present.

<a href="../images/apple.jpg"
   hreflang="en">Apple</a> 
rel



alternate

author

bookmark

help

license


next


nofollow


noreferrer


prefetch

prev


search


tag
Specifies that the link is to be used for downloading a resource, which can optionally have a value.
Should be only be used when the href attribute is present.

Alternative representation of current document.

Link to author of this document.

Gives a permalink for the nearest ancestor.

Link to a help document for current context.

Referenced document provides the copyright license terms for current document.

Indicates that the document is part of a sequence, and that the link to the referenced document is next.

Indicates that the link is not endorsed by the original author or publisher of the page.

Indicates that no referrer information is to be leaked when following the link.

Specifies target document should be cached.

Indicates that the document is part of a sequence, and that the link to the referenced document is previous.

Specifies that referenced document provides an interface specifically for searching the document and its related resources.

Specifies a tag that applies to the current document.

<a href="../images/apple.jpg"
   rel="nofollow">Apple</a> 
target



_blank

_parent

_self (default)

_top

framename
Specifies the relationship between the current document and linked document.
Multiple values can be used using a space as a delimiter.

Opens linked document in new window or tab

Opens linked document in parent frame.

Opens linked document in same frame as it was clicked in.

Opens linked document in window body.

Opens the linked document in a named framename.

<a href="../images/apple.jpg"
   target="_blank">Apple</a> 
typeMIME-typeSpecifies MIME type of the linked resource.
Should only be used when the href attribute is present.

<a href="../images/apple.jpg"
   type="text/html">Apple</a> 
<a> Global Attributes
Attribute Description Example
Common
classSpecifies a classname for the element allowing you to apply the style of the predefined class to the content.

<a href="../images/apple.jpg" class="name">Link text</a> 
idSpecifies a unique id for the element allowing you to apply the style of the predefined id to the content.

<a href="../images/apple.jpg" id="idname">Link text</a>
styleSpecifies an inline style for the element allowing you to apply the style to the contentt.

<a href="../images/apple.jpg" style="color:red;">Link text</a> 
titleSpecifies an inline style for the element allowing you to apply the style to the content.

<a href="../images/apple.jpg" title="Content info.">Link text</a> 
Keyboard
accesskeySpecifies a keyboard shortcut to associate with the element.

<a href="../images/apple.jpg" accesskey="a">Link text</a> 
tabindexSpecifies a tab order for the element.

<a href="../images/apple.jpg" tabindex="1">Link text</a>
Language
dirSpecifies the directional flow of the content.

<!-- The text will flow from left to right -->
<a href="../images/apple.jpg" dir="ltr">Link text</a>
<!-- The text will flow from right to left -->
<a href="../images/apple.jpg" dir="rtl">Link text</a>
langSpecifies a language code for the content of the element.

<a href="../images/apple.jpg" lang="en">Link text</a>
spellcheckSpecifies an inline style for the element allowing you to apply the style to the contentt.

<!-- Valid values true and false. -->
<!-- Default inherited/browser specific. -->
<a href="../images/apple.jpg" spellcheck="true">Link text</a> 
translateSpecifies an inline style for the element allowing you to apply the style to the content.

<!-- Valid values yes and no. -->
<!-- Default yes. -->
<a href="../images/apple.jpg" translate="no">Link text</a>
Miscellaneous
contenteditableSpecifies whether the content of the element is editable.

<!-- Valid values true and false. -->
<!-- Default inherited. -->
<a href="../images/apple.jpg" contenteditable="false">Link text</a> 
draggableSpecifies whether the element is draggable.

<!-- Valid values true and false. -->
<!-- Default browser specific. -->
<a href="../images/apple.jpg" draggable="true">Link text</a> 
hiddenSpecifies whether the element is not yet, or no longer, relevant.

<!-- Valid values an empty string or hidden -->
<a href="../images/apple.jpg" hidden>Link text</a> 
<a href="../images/apple.jpg" hidden="hidden">Link text</a> 
<a> Event Attributes
Attribute Description Example
Document Element
oncopyThe script to be run when the user copies the content of an element.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" oncopy="go()">Link text</a> 
oncutThe script to be run when the user cuts the content of an element.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" oncut="go()">Link text</a>
onpasteThe script to be run when the user pastes some content into an element.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onpaste="go()">Link text</a>
Drag and Drop
ondragThe script to be run when an element is dragged.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" ondrag="go()">Link text</a>
ondragendThe script to be run when an element has stopped being dragged.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" ondragend="go()">Link text</a>
ondragenterThe script to be run when an element has been dragged to a valid drop target.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" ondragenter="go()">Link text</a>
ondragleaveThe script to be run when an element leaves a valid drop target.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" ondragleave="go()">Link text</a>
ondragoverThe script to be run when an element is being dragged over a valid drop target.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" ondragover="go()">Link text</a>
ondragstartThe script to be run at the start of a drag operation.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" ondragstart="go()">Link text</a>
ondropThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" ondrop="go()">Link text</a>
Form
onblurThe script to be run when the element loses focus.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onblur="go()">Link text</a>
onchangeThe script to be run when object changed and attempt to leave field.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onchange="go()">Link text</a>
oncontextmenuThe script to be run when a context menu is triggered.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" oncontextmenu="go()">Link text</a>
onfocusThe script to be run when the element gets focus.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onfocus="go()">Link text</a>
oninputThe script to be run when an element gets user input.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" oninput="go()">Link text</a>
oninvalidThe script to be run when an element is invalid.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" oninvalid="go()">Link text</a>
onresetThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onreset="go()">Link text</a>
onselectThe script to be run when some or all of the contents of an object are selected.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onselect="go()">Link text</a>
onsubmitThe script to be run when a form is submitted.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onsubmit="go()">Link text</a>
Keyboard
onkeydownThe script to be run when an element is in focus and keyboard key is pressed down.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onkeydown="go()">Link text</a>
onkeypressThe script to be run when an element is in focus and keyboard key is pressed down and released.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onkeypress="go()">Link text</a>
onkeyupThe script to be run when an element is in focus and keyboard key is released.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onkeyup="go()">Link text</a>
Media
onabortThe script code to be run on abort.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onabort="go()">Link text</a>
oncanplayThe script to be run when a file has buffered enough so it is ready to start playing.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" oncanplay="go()">Link text</a>
oncanplaythroughThe script to be run when a file can be played all the way to the end without further need of buffering.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" oncanplaythrough="go()">Link text</a>
oncuechangeThe script to be run when the cue changes when using the track element.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" oncuechange="go()">Link text</a>
ondurationchangeThe script to be run when the length of the media is changed.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" ondurationchange="go()">Link text</a>
onemptiedThe script to be run when a media resource element suddenly becomes empty, usually due to an error.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onemptied="go()">Link text</a>
onendedThe script to be run when the media has reach the end.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onended="go()">Link text</a>
onloadeddataThe script to be run when media data is loaded and playback can start.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onloadeddata="go()">Link text</a>
onloadedmetadataThe script to be run when metadata has been loaded.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onloadedmetadata="go()">Link text</a>
onloadstartThe script to be run when the media resource has started loading.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onloadstart="go()">Link text</a>
onpauseThe script to be run when the media resource has been paused.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onpause="go()">Link text</a>
onplayThe script to be run when the media resource starts playback.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onplay="go()">Link text</a>
onplayingThe script to be run when playback has already begun.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onplaying="go()">Link text</a>
onprogressThe script to be run when the browser is fetching the media data.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onprogress="go()">Link text</a>
onratechangeThe script to be run when the playback rate changes.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onratechange="go()">Link text</a>
onseekedThe script to be run when the seeking attribute is set to false indicating that seeking has finished.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onseeked="go()">Link text</a>
onseekingThe script to be run when the seeking attribute is set to true indicating that seeking is currently active.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onseeking="go()">Link text</a>
onstalledThe script to be run when the browser is unable to continue fetching media data.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onstalled="go()">Link text</a>
onsuspendThe script to be run when media data has stopped before being completely loaded.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onsuspend="go()">Link text</a>
ontimeupdateThe script to be run when the media resources current playback position has changed.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" ontimeupdate="go()">Link text</a>
onvolumechangeThe script to be run when the volume has changed or been muted.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onvolumechange="go()">Link text</a>
onwaitingThe script to be run when the media resource has paused but is expected to resume.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onwaiting="go()">Link text</a>
Mouse
onclickThe script to be run when when a mouse is clicked on an element.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onclick="go()">Link text</a>
ondblclickThe script to be run when a mouse is double clicked on an element.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" ondblclick="go()">Link text</a>
onmousedownThe script to be run when he mouse button is pressed down while the cursor is over an element.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onmousedown="go()">Link text</a>
onmousemoveThe script to be run when the mouse button is moved.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onmousemove="go()">Link text</a>
onmouseoutThe script to be run when the mouse cursor moves off an element.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onmouseout="go()">Link text</a>
onmouseoverThe script to be run when the mouse cursor moves over an element.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onmouseover="go()">Link text</a>
onmouseupThe script to be run when the mouse button is released while the cursor is over the element.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onmouseup="go()">Link text</a>
onwheelThe script to be run when the mouse wheel rolls up or down over an element.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onwheel="go()">Link text</a>
Scroll
onscrollThe script code to be run when the scrollbar of an element is being scrolled.

 <!-- Executes go() function -->
<a href="../images/apple.jpg" onscroll="go()">Link text</a> 
Scroll
Window - NONE

Link To Same Page

We linked to a different part of the page!

Beef Pie

Go back



Relevant HTML Tutorial

HTML Lessons - Links