HTML a element

Reference for the HTML a element: content model, href, target, rel, same-origin download, and the current standard rule for noopener.

The a element creates a hyperlink when it has an href attribute. Without href, it is a placeholder for a link and is not a navigable control. This page deepens the catalog card for <a>. It does not replace the tag catalog or the HTML tutorial.

Permitted content is transparent, except that an a element must not contain another a element, other interactive content, or a descendant with a tabindex attribute. Both the start and end tags are required. The implicit ARIA role is link when href is present, and generic when it is not.

Examples are complete, minimal HTML fragments. They were checked with Python 3.13's html.parser as a structural tree, and with the site build. This is not a browser test: navigation, downloads, focus, and accessibility were not executed in a user agent.

Official sources: MDN <a> element and the WHATWG HTML Living Standard. Fragments were checked with Python 3.13 html.parser. That parser builds an element tree; it is not a WHATWG conformance checker, and this is not a browser or accessibility test.

HTML tag catalog → · HTML tutorial overview →

Purpose and content model

Use a for navigation to a URL, a same-document fragment, or a scheme such as mailto. Do not use a as a stand-in for a button that performs an in-page action. Do not nest a button, input, or another link inside an a element.

Visible text (or an equivalent accessible name) should describe the destination. The first example shows a fragment link, an ordinary URL, and a placeholder a without href.

href, fragment links, and a placeholder without href

<a href>
<a href="#fragment">
<a>placeholder</a>

A link needs href to be a hyperlink. A missing href does not create a hyperlink.

AttributeDescription
hrefA valid URL potentially surrounded by spaces. Omit it when the element is only a placeholder for a future link.
hreflangOptional hint for the language of the destination document.
typeOptional hint for the destination MIME type. It does not change how the browser follows the link.
  • This fragment is markup only. The example.com URL is a documentation example and is not fetched here.
html
<nav>
  <a href="#features">Features</a>
  <a href="https://example.com/docs">Example docs</a>
  <a>Coming soon</a>
</nav>

What this markup means

The first anchor jumps to an id in the same document. The second points at a documentation URL. The third has no href, so it is not a hyperlink and should not be expected to activate like a link.

Related: Tag catalog: <a>, <button>

MDN documentation → · WHATWG HTML Standard →

target, rel, and noopener

The default target is _self, which means the current browsing context. target="_blank" asks for a new browsing context, usually a new tab.

The HTML Living Standard treats target="_blank" on a and area as implying rel="noopener", unless rel includes opener. MDN notes the same protection in newer browsers, and still records that older browsers could expose window.opener without an explicit rel. This page does not treat "always add noopener or the page is compromised" as the current default rule, and it does not claim every historical user agent was tested here.

Writing rel="noopener" explicitly remains valid and makes the intent obvious. rel="noreferrer" also omits the referrer and implies noopener. The catalog example that uses rel="noopener noreferrer" with target="_blank" is still a reasonable, explicit pattern.

The download attribute

The download attribute asks the browser to treat the URL as a download, optionally with a suggested filename. It is a hint, not a guarantee.

Same-origin URLs (and typically blob: or data: URLs) can honor download. Cross-origin URLs generally ignore the attribute and may navigate to the resource instead. Do not claim that download works for every href.

target, rel, and a same-origin download

<a href target="_blank" rel="noopener">
<a href download>

Open a new tab with an explicit rel, and suggest a same-origin download filename.

AttributeDescription
targetBrowsing context name. _self is the default. _blank requests a new tab or window.
relSpace-separated link types. noopener is implied by target=_blank in the current HTML Standard unless rel includes opener. noreferrer also implies noopener and omits the referrer.
downloadSuggests a download, with an optional filename. Meaningful mainly for same-origin, blob, or data URLs. Cross-origin hrefs usually ignore it.
  • The notes.txt path is a same-document style path in the example. No file is read or uploaded, and no network request is made from this page.
html
<p>
  <a href="https://example.com/notes" target="_blank" rel="noopener">Open notes</a>
  <a href="/files/notes.txt" download="notes.txt">Download notes</a>
</p>

What this markup means

The first link requests a new tab and states rel="noopener" explicitly. The second uses download with a same-origin path and a suggested filename. A cross-origin href would not be a reliable download just because download is present.

Related: Tag catalog: <a>

MDN documentation → · WHATWG HTML Standard →

Accessibility and security boundaries

Link text should make sense out of context. Avoid using a only around "click here". A placeholder a without href is not a keyboard-activated link.

Do not put javascript: in href. That scheme is a vector for unexpected script, not a navigation style. Do not use a to wrap a button or other interactive content. Referrer policy and rel="noreferrer" affect what the destination learns about the source page; they are not a substitute for HTTPS on either origin.