--- title: slug: Web/HTML/Element/a translation_of: Web/HTML/Element/a ---

Het HTML <a> element (of anker element) maakt een hyperlink naar andere web pagina's, bestanden, lokaties binnen dezelfde pagina, email-adressen of een andere URL.

Content categorieën Flow content, phrasing content, interactive content, tastbare content.
Toegestane content Transparent, bevat ofwel flow content ( exclusief interactive content) of phrasing content.
Tag verzuim {{no_tag_omission}}
Toegestane ouders Ieder element dat phrasing content accepteert, of ieder element dat  flow content accepteert, maar altijd  <a> elementen uitsluit ( volgens het logische principe van symmetrie dat als een <a> tag, als ouder, geen  interactive content kan bevatten, deze <a> content dus niet deze <a> tag als zijn ouder kan hebben).
Toegestane ARIA roles {{ARIARole("button")}}, {{ARIARole("checkbox")}}, {{ARIARole("menuitem")}}, {{ARIARole("menuitemcheckbox")}}, {{ARIARole("menuitemradio")}}, {{ARIARole("option")}}, {{ARIARole("radio")}}, {{ARIARole("switch")}}, {{ARIARole("tab")}}, {{ARIARole("treeitem")}}
DOM interface {{domxref("HTMLAnchorElement")}}

Attributes

This element's attributes include the global attributes.

{{htmlattrdef("download")}} {{HTMLVersionInline(5)}}
This attribute instructs browsers to download a URL instead of navigating to it, so the user will be prompted to save it as a local file. If the attribute has a value, it is used as the pre-filled file name in the Save prompt (the user can still change the file name if they want). There are no restrictions on allowed values, though / and \ are converted to underscores. Most file systems limit some punctuation in file names, and browsers will adjust the suggested name accordingly.
Notes:
  • This attribute only works for same-origin URLs.
  • This attribute can be used with blob: URLs and data: URLs to download content generated by JavaScript, such as pictures created in an image-editor Web app.
  • If the HTTP header Content-Disposition: gives a different filename than this attribute, the HTTP header takes priority over this attribute.
  • If Content-Disposition: is set to inline, Firefox prioritizes Content-Disposition, like the filename case, while Chrome prioritizes the download attribute.
{{htmlattrdef("href")}}
Contains a URL or a URL fragment that the hyperlink points to.
A URL fragment is a name preceded by a hash mark (#), which specifies an internal target location (an ID of an HTML element) within the current document. URLs are not restricted to Web (HTTP)-based documents, but can use any protocol supported by the browser. For example, file:, ftp:, and mailto: work in most browsers.
This attribute may be omitted (as of HTML5) to create a placeholder link. A placeholder link resembles a traditional hyperlink, but does not lead anywhere.

Note: You can use href="#top" or the empty fragment href="#" to link to the top of the current page. This behavior is specified by HTML5.

{{htmlattrdef("hreflang")}}
This attribute indicates the human language of the linked resource. It is purely advisory, with no built-in functionality. Allowed values are determined by BCP47.
{{htmlattrdef("ping")}}
Contains a space-separated list of URLs to which, when the hyperlink is followed, {{HTTPMethod("POST")}} requests with the body PING will be sent by the browser (in the background). Typically used for tracking.
{{htmlattrdef("referrerpolicy")}} {{experimental_inline}}
Indicates which referrer to send when fetching the URL:
{{htmlattrdef("rel")}}
Specifies the relationship of the target object to the link object. The value is a space-separated list of link types.
{{htmlattrdef("target")}}
Specifies where to display the linked URL. It is a name of, or keyword for, a browsing context: a tab, window, or <iframe>. The following keywords have special meanings:

Note: When using target, consider adding rel="noopener noreferrer" to avoid exploitation of the window.opener API.

{{htmlattrdef("type")}}
Specifies the media type in the form of a {{Glossary("MIME type")}} for the linked URL. It is purely advisory, with no built-in functionality.

Obsolete

{{htmlattrdef("charset")}} {{obsoleteGeneric("inline","HTML5")}}
This attribute defined the character encoding of the linked URL. The value should be a space- and/or comma-delimited list of character sets defined in RFC 2045. The default value is ISO-8859-1.

Usage note: This attribute is obsolete in HTML5 and should not be used by authors. To achieve its effect, use the HTTP Content-Type: header on the linked URL.

{{htmlattrdef("coords")}} {{HTMLVersionInline(4)}} only, {{obsoleteGeneric("inline","HTML5")}}
For use with the below shape attribute, this attribute used a comma-separated list of numbers to define the coordinates of the link on the page.
{{htmlattrdef("name")}} {{HTMLVersionInline(4)}} only, {{obsoleteGeneric("inline","HTML5")}}
This attribute was required for anchors defining a possible target location within a page. In HTML 4.01, id and name could be used simultaneously on a <a> element as long as they have identical values.

Usage note: This attribute is obsolete in HTML5, use the global attribute id instead.

{{htmlattrdef("rev")}} {{HTMLVersionInline(4)}} only, {{obsoleteGeneric("inline","HTML5")}}
This attribute specified a reverse link, the inverse relationship of the rel attribute. It was deprecated for being very confusing.
{{htmlattrdef("shape")}} {{HTMLVersionInline(4)}} only, {{obsoleteGeneric("inline","HTML5")}}
This attribute was used to define a region for hyperlinks to create an image map. The values are circle, default, polygon, and rect. The format of the coords attribute depends on the value of shape. For circle, the value is x,y,r where x and y are the pixel coordinates for the center of the circle and r is the radius value in pixels. For rect, the coords attribute should be x,y,w,h. The x,y values define the upper-left-hand corner of the rectangle, while w and h define the width and height respectively. A value of polygon for shape requires x1,y1,x2,y2,... values for coords. Each of the x,y pairs defines a point in the polygon, with successive points being joined by straight lines and the last point joined to the first. The value default for shape requires that the entire enclosed area, typically an image, be used.
Note: Use the usemap attribute for the {{HTMLElement("img")}} element and the associated {{HTMLElement("map")}} element to define hotspots instead of the shape attribute.

Examples

Linking to an external location

<!-- anchor linking to external file -->
<a href="https://www.mozilla.com/">
External Link
</a>

Result

External Link

Linking to another section on the same page

<!-- links to element on this page with id="attr-href" -->
<a href="#attr-href">
Description of Same-Page Links
</a>

Result

Description of Same Page Links

Creating a clickable image

This example uses an image to link to the MDN home page. The home page will open in a new browsing context, that is, a new page or a new tab.

<a href="https://developer.mozilla.org/en-US/" target="_blank">
  <img src="https://mdn.mozillademos.org/files/6851/mdn_logo.png"
       alt="MDN logo" />
</a>

Result

{{EmbedLiveSample("Creating_a_clickable_image", "320", "64")}}

It's common to create links that open in the user's email program to allow them to send a new message. This is done with a mailto: link. Here's a simple example:

<a href="mailto:nowhere@mozilla.org">Send email to nowhere</a>

Result

Send email to nowhere

For additional details about the mailto URL scheme, such as including the subject, body, or other predetermined content, see Email links or {{RFC(6068)}}.

Offering phone links is helpful for users viewing web documents and laptops connected to phones.

<a href="tel:+491570156">+49 157 0156</a>

For additional details about the tel URL scheme, see {{RFC(3966)}}.

Using the download attribute to save a <canvas> as a PNG

If you want to let users download an HTML {{HTMLElement("canvas")}} element as an image, you can create a link with a download attribute and the canvas data as a file URL:

var link = document.createElement('a');
link.textContent = 'download image';

link.addEventListener('click', function(ev) {
    link.href = canvas.toDataURL();
    link.download = "mypainting.png";
}, false);

document.body.appendChild(link);

You can see this in action at jsfiddle.net/codepo8/V6ufG/2/.

Notes

HTML 3.2 defines only the name, href, rel, rev, and title attributes.

Accessibility recommendations

Anchor tags are often abused with the onclick event to create pseudo-buttons by setting href to "#" or "javascript:void(0)" to prevent the page from refreshing. These values cause unexpected behavior when copying/dragging links, opening links in a new tabs/windows, bookmarking, and when JavaScript is still downloading, errors out, or is disabled. This also conveys incorrect semantics to assistive technologies (e.g., screen readers). In these cases, it is recommended to use a {{HTMLElement("button")}} instead. In general you should only use an anchor for navigation using a proper URL. 

Clicking and focus

Whether clicking on an {{HTMLElement("a")}} causes it to become focused varies by browser and OS.

Does clicking on an {{HTMLElement("a")}} give it focus?
Desktop Browsers Windows 8.1 OS X 10.9
Firefox 30.0 Yes Yes
Chrome ≥39
(Chromium bug 388666)
Yes Yes
Safari 7.0.5 N/A Only when it has a tabindex
Internet Explorer 11 Yes N/A
Presto (Opera 12) Yes Yes
Does tapping on an {{HTMLElement("a")}} give it 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

Specifications

Specification Status Comment
{{SpecName('Referrer Policy', '#referrer-policy-delivery-referrer-attribute', 'referrer attribute')}} {{Spec2('Referrer Policy')}} Added the referrer attribute.
{{SpecName('HTML WHATWG', 'semantics.html#the-a-element', '<a>')}} {{Spec2('HTML WHATWG')}}  
{{SpecName('HTML5 W3C', 'textlevel-semantics.html#the-a-element', '<a>')}} {{Spec2('HTML5 W3C')}}  
{{SpecName('HTML4.01', 'struct/links.html#h-12.2', '<a>')}} {{Spec2('HTML4.01')}}  

Browser compatibility

{{Compat("html.elements.a")}}

See also

{{HTMLRef}}