a

< html‎ | elements
Jump to: navigation, search

a

This article is In Progress.


W3C Recommendation

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"
 


Compatibility

Do you think this data can be improved? You can ask to add by opening an issue or make a pull request.

Desktop

FeaturesChromeFirefoxInternet ExplorerOperaSafari
Basic support
?
Yes
1.0
Yes
?
Yes
?
Yes
?
Yes
href="#top"
?
Yes
?
Unknown
?
Yes
?
Yes
?
Yes
download
14
Yes
?
Unknown
?
none
?
none
?
Unknown

Mobile

FeaturesAndroidFirefox MobileIE MobileOpera MobileSafari Mobile
Basic support
?
Yes
1.0
Yes
?
Yes
?
Yes
?
Yes
href="#top"
?
Yes
10.0
Yes
?
Yes
?
Yes
?
Yes
download
?
Yes
20.0
Yes
?
none
?
Unknown
?
Unknown

Examples

View live example

HTML

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

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:

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

Attribution

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]