This page is In Progress

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

a

Summary

Defines a hyperlink, a destination of hyperlink, or both.


Overview Table

DOM Interface
HTMLAnchorElement

Description

The a element defines a hyperlink to any content, which could be an external site, another page on the same site, a section within the same page, an image, or a local file.

Syntax

<a href="[URI]">[Anchor text or image tag]</a>
<a id="#[identifier]">[Anchor text or image tag]</a>
<a>[Anchor text or image tag]</a>

Enclosed HTML

HTML enclosed by the <a></a> tags is typically text or an image. It is displayed in the page and (if the href attribute is present) is rendered as a link.

Common Attributes

Name Value Purpose Example Validity
download text File name to show in Save dialog
download="filename.pdf"
HTML5
href URI Target of link
href="http://example.com"
href="#TableOfContents"
id identifier text Creates an anchor in the page that can be referred to by href
id="TableOfContents"
hreflang Language tag for HTML5 or for HTML4 Hint for language of target. May be used with rel="alternate" as a hint to the server for which language to provide.
hreflang="ja"
rel comma-separated list of keywords Indicates the relationship of the link target to the current page
rel="help"
target Browsing context Tells where to open the link when it is followed
target="_blank"

Examples

<!-- Link to an external website. -->
<a href="http://www.example.com">Example website</a>

<!-- Link to an internal website in same directory. -->
<a href="home.html">Home</a>

<!-- Download link (HTML5 only). Value of download attribute is used as pre-filled file name in Save dialog.
If no value is specified for the download, the name of the resource will be used.–>
<a href="filename_on_server.pdf" download="meaningful_filename.pdf">Download your pdf</a>

<!-- Open a link in the window specified by the attribute TARGET. -->
<a href="http://www.example.com" target="_blank">Open example website in new window</a>

<!-- Include an IMG element as a part of the link. -->
<a href="http://www.example.com"><img src="images/bullet.png">A link with an image</a>

<!-- Link to an anchor on the same page. -->
<a href="#top">Go to top</a>

<!-- Define an anchor. -->
<a id="top"></a>

<!-- Invoke a JavaScript function (Not recommended) -->
<a href="javascript:alert(‘Link clicked’)">Click this link</a>

<!-- Links to a document and uses the ‘’rel’’ attribute to specify the relationship to the linked document. -->
<a href="http://www.example.com/help" rel="help">Link to help</a>

View live example

Notes

Remarks

For creating an anchor in the page, the name attribute is obsolete and should be replaced by id attribute.

Both text and images can be included within an anchor. An image that is an anchor has a border whose color indicates whether the link has been visited. To prevent this border from appearing, you can set the img element's border attribute to 0 or omit the border attribute. You can also use CSS attributes to override the default appearance of a and img elements.

The URI may refer to any protocol, e.g. http, mailto, file. A fragment (# followed by text) refers to a location in the current page. href may be omitted to indicate a placeholder link, such as a reference to the current page in a menu.

Optionally the rel element may be specified to provide semantic meaning to the link target.

Internationalization topics related to the a element:

Clicking and focus

Whether clicking on an anchor causes it to (by default) become focused varies by browser and OS.

Does clicking on an anchor give it the focus?

Desktop Browsers Windows 8.1 OS X 10.9
Firefox 30.0 Yes Yes
Chrome >=39 Yes Yes
Safari 7.0.5 N/A Only when it has a tabindex
Internet Explorer 11 Yes N/A
Presto (Opera 12) Yes ???

Does tapping on an anchor give it the focus?

Mobile Browsers iOS 7.1.2 Android 4.4.4
Safari Mobile Only when it has a tabindex N/A
Chrome 35 ??? Only when it has a tabindex

Related specifications

HTML 5.1
W3C Working Draft
HTML 5
W3C Recommendation
HTML 4.01
W3C Recommendation

Attributions