< html‎ | elements
Jump to: navigation, search


This article is In Progress.

W3C Recommendation


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

Overview Table

DOM Interface HTMLAnchorElement


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.


<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
href URI Target of link
id identifier text Creates an anchor in the page that can be referred to by href
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.
rel comma-separated list of keywords Indicates the relationship of the link target to the current page
target Browsing context Tells where to open the link when it is followed


View live example


<!-- 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>



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:

HTML information

Closing Tag required
CSS Display inline


Related specifications

Specification Status Related Changes
HTML 5 W3C Candidate Recommendation
HTML 4.01 W3C Recommendation
WHATWG Living Standard



Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic Support 22.0


Feature Android BlackBerry Chrome for mobile Firefox Mobile (Gecko) IE Mobile Opera Mobile Opera Mini Safari Mobile
Basic Support Supported (when?)
Supported (when?)
Supported (when?)
Supported (when?)
Supported (when?)
Supported (when?)
Supported (when?)
Supported (when?)

Compatibility notes

Browser Version Note
Internet Explorer 8 and later A table object does not function properly when contained within an a tag. The value of the href attribute depends on the current document compatibility mode. Internet Explorer 8 and later. When Protected Mode is enabled and a Web page contains an anchor link with a named target, Windows Internet Explorer opens the target of the link in a new window when the target has a different integrity level than the Web page containing the link. For more information, see Understanding and Working in Protected Mode Internet Explorer.
Safari / Google Chrome any A elements with href don't get focus by mouse press by default.


This article contains content originally from external sources.

Portions of this content come from the Mozilla Developer Network cc-by-sa-small-wpd.svg: Article

Portions of this content come from the Microsoft Developer Network: [Windows Internet Explorer API reference Article]