---
title:
slug: Web/HTML/Element/a
tags:
- Conteúdo
- Elemento
- HTML
- Internet
- Rede
- Referencia
- Semántica HTML a nivel de texto
- Web
translation_of: Web/HTML/Element/a
---
O elemento O exemplo de código está armazenado no repositório GitHub. Se deseja contribuir, clone o projeto no https://github.com/mdn/interactive-examples e nos envie uma pull request (subir as atualizações). Os atributos do elemento incluem os atributos globais. A URL para a qual o hiperlink aponta. Links não se restrigem a URLs baseadas no protocolo HTTP — eles podem utilizar qualquer tipo de URL suportado pelos browsers: Note: Quando usando Note: Linking to another page with Note: This attribute is obsolete and should not be used by authors. Use the HTTP {{HTTPHeader("Content-Type")}} header on the linked URL. Note: Use the global attribute {{HTMLAttrxRef("id")}} instead.<a>
em HTML (ou elemento âncora), com o atributo href
cria-se um hiperligação nas páginas web, arquivos, endereços de emails, ligações na mesma página ou endereços na URL. O conteúdo dentro de cada <a>
precisará indicar o destino do link.Atributos
/
e \
são convertidos para underscores (_
).Arquivos de sistema talvez proibam alguns caracteres em nomes de arquivos, então o navegador irá ajustar o nome sugerido caso necessário.
download
somente funciona para URLs de mesma origem , ou os esquemas blob:
e data:
Content-Disposition
tiver um diferente filename
(nome do arquivo) que download
, o cabeçalho tem prioridade. (Se Content-Disposition: inline
, Firefox prioriza o cabeçalho enquanto o Chrome escolhe download
.)
tel:
URLsmailto:
URLsregisterProtocolHandler()
lang
attribute.PING
para as URLs. Typically for tracking.Referrer-Policy
para possíveis valores e seus efeitos.<iframe>
). The following keywords have special meanings for where to load the URL:
_self
: No atual contexto de pesquisa. (Default)_blank
: Normalmente uma nova aba, porém usuários podem configurar seus navegadores para abrir em uma nova janela._parent
: the parent browsing context of the current one. If no parent, behaves as _self
._top
: the topmost browsing context (the "highest" context that’s an ancestor of the current one). If no ancestors, behaves as _self
.target
, adicione rel="noreferrer noopener"
para evitar "exploit" para window.opener
API;target="_blank"
will run the new page in the same process as your page. If the new page executes JavaScript, your page's performance may suffer. This can also be avoided by using rel="noreferrer noopener"
.Obsolete attributes
shape
attribute. A comma-separated list of coordinates.id
and name
could both be used on <a>
, as long as they had identical values.
rel
attribute. Deprecated for being very confusing.Properties
Content categories | Flow content, phrasing content, interactive content, palpable content. |
---|---|
Permitted content | Transparent, containing either flow content (excluding interactive content) or phrasing content. |
Tag omission | {{no_tag_omission}} |
Permitted parents | Any element that accepts phrasing content, or any element that accepts flow content, but not other <a> elements. |
Implicit ARIA role | {{ARIARole("link")}} when href attribute is present, otherwise no corresponding role |
Permitted ARIA roles |
When
When
|
DOM interface | {{DOMxRef("HTMLAnchorElement")}} |
<a href="https://www.mozilla.com"> Mozilla </a>
{{EmbedLiveSample('Linking_to_an_absolute_URL')}}
<a href="//example.com">Scheme-relative URL</a> <a href="/en-US/docs/Web/HTML">Origin-relative URL</a> <a href="./p">Directory-relative URL</a>
a { display: block; margin-bottom: 0.5em }
{{EmbedLiveSample('Linking_to_relative_URLs')}}
<!-- <a> element links to the section below --> <p><a href="#Section_further_down"> Jump to the heading below </a></p> <!-- Heading to link to --> <h2 id="Section_further_down">Section further down</h2>
Note: You can use href="#top"
or the empty fragment (href="#"
) to link to the top of the current page, as defined in the HTML specification.
To create links that open in the user's email program to let them send a new message, use the mailto:
scheme:
<a href="mailto:nowhere@mozilla.org">Send email to nowhere</a>
For details about mailto:
URLs, such as including a subject or body, see Email links or {{RFC(6068)}}.
<a href="tel:+49.157.0156">+49 157 0156</a> <a href="tel:+1(555)5309">(555) 5309</a>
tel:
link behavior varies with device capabilities:
web.skype.com
.See {{RFC(3966)}} for syntax, additional features, and other details about the tel:
URL scheme.
To save a {{HTMLElement("canvas")}} element’s contents as an image, you can create a link with a download
attribute and the canvas data as a data:
URL:
<p>Paint by holding down the mouse button and moving it. <a href="" download="my_painting.png">Download my painting</a> </p> <canvas width="300" height="300"></canvas>
html { font-family: sans-serif; } canvas { background: #fff; border: 1px dashed; } a { display: inline-block; background: #69c; color: #fff; padding: 5px 10px; }
var canvas = document.querySelector('canvas'), c = canvas.getContext('2d'); c.fillStyle = 'hotpink'; function draw(x, y) { if (isDrawing) { c.beginPath(); c.arc(x, y, 10, 0, Math.PI*2); c.closePath(); c.fill(); } } canvas.addEventListener('mousemove', event => draw(event.offsetX, event.offsetY) ); canvas.addEventListener('mousedown', () => isDrawing = true); canvas.addEventListener('mouseup', () => isDrawing = false); document.querySelector('a').addEventListener('click', event => event.target.href = canvas.toDataURL() );
{{EmbedLiveSample('Example_painting_app_with_save_link', '100%', '400')}}
<a>
elements can have consequences for users’ security and privacy. See Referer
header: privacy and security concerns for information.
Using target="_blank"
without rel="noreferrer"
and rel="noopener"
makes the website vulnerable to {{domxref("window.opener")}} API exploitation attacks (vulnerability description).
The content inside a link should indicate where the link goes, even out of context.
A sadly common mistake is to only link the words “click here” or “here”:
<p> Learn more about our products <a href="/products">here</a>. </p>
Luckily, this is an easy fix, and it’s actually shorter than the inaccessible version!
<p> Learn more <a href="/products">about our products</a>. </p>
Assistive software have shortcuts to list all links on a page. However, strong link text benefits all users — the “list all links” shortcut emulates how sighted users quickly scan pages.
Anchor elements are often abused as fake buttons by setting their href
to #
or javascript:void(0)
to prevent the page from refreshing, then listening for their click
events .
These bogus href
values cause unexpected behavior when copying/dragging links, opening links in a new tab/window, bookmarking, or when JavaScript is loading, errors, or is disabled. They also convey incorrect semantics to assistive technologies, like screen readers.
Use a {{HTMLElement("button")}} instead. In general, you should only use a hyperlink for navigation to a real URL.
Links that open in a new tab/window via target="_blank"
, or links that point to a download file should indicate what will happen when the link is followed.
People experiencing low vision conditions, navigating with the aid of screen reading technology, or with cognitive concerns may be confused when a new tab, window, or application opens unexpectedly. Older screen-reading software may not even announce the behavior.
<a target="_blank" href="https://www.wikipedia.org"> Wikipedia (opens in new tab) </a>
<a href="2017-annual-report.ppt"> 2017 Annual Report (PowerPoint) </a>
If an icon is used to signify link behavior, make sure it has {{HTMLAttrxRef("alt", "img", "alt text", "true")}}:
<a target="_blank" href="https://www.wikipedia.org"> Wikipedia <img alt="(opens in new tab)" src="newtab.svg"> </a> <a href="2017-annual-report.ppt"> 2017 Annual Report <img alt="(PowerPoint file)" src="ppt-icon.svg"> </a>
A skip link is a link placed as early as possible in {{HTMLElement("body")}} content that points to the beginning of the page's main content. Usually, CSS hides a skip link offscreen until focused.
<body> <a href="#content">Skip to main content</a> <header> … </header> <main id="content"> <!-- The skip link jumps to here -->
.skip-link { position: absolute; top: -3em; background: #fff; } .skip-link:focus { top: 0; }
Skip links let keyboard users bypass content repeated throughout multiple pages, such as header navigation.
Skip links are especially useful for people who navigate with the aid of assistive technology such as switch control, voice command, or mouth sticks/head wands, where the act of moving through repetitive links can be laborious.
Interactive elements, like links, should provide an area large enough that it is easy to activate them. This helps a variety of people, including those with motor control issues and those using imprecise inputs such as a touchscreen. A minimum size of 44×44 CSS pixels is recommended.
Text-only links in prose content are exempt from this requirement, but it’s still a good idea to make sure enough text is hyperlinked to be easily activated.
Interactive elements, like links, placed in close visual proximity should have space separating them. Spacing helps people with motor control issues, who may otherwise accidentally activate the wrong interactive content.
Spacing may be created using CSS properties like {{CSSxRef("margin")}}.
Specification | Status | Comment |
---|---|---|
{{SpecName("Referrer Policy", "#referrer-policy-delivery-referrer-attribute", "referrer attribute")}} | {{Spec2("Referrer Policy")}} | Added the referrerpolicy attribute. |
{{SpecName("HTML WHATWG", "textlevel-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")}} |
{{Compat("html.elements.a")}}
<a>
, but for metadata hyperlinks that are invisible to users.<a>
elements with valid href
attributes.