HTML Reference Β· Inline Text
The <a> element
Reference for the HTML <a> element: href, target, rel, download, hreflang, type, referrerpolicy and ping, plus link-text and accessibility guidance.
The <a> element (the anchor) creates a hyperlink. With an href attribute it points somewhere: another page, a file, a section of the current page, an email address or a phone number. Activating it with a click, a tap or the Enter key follows the link.
Without href, an <a> is only a placeholder for where a link would go, for example the current page in a navigation menu. A placeholder is not focusable and is not announced as a link.
<a href="/pricing">See our pricing</a>
Try it
The #menu link scrolls to the element whose id is menu. The email and phone links hand off to whichever app the device uses for those schemes.
The script builds a file in memory and gives the link a blob: URL. The download attribute tells the browser to save it as shopping-list.txt instead of opening it.
Attributes
| Attribute | Values | Description |
|---|---|---|
href |
A URL | The destination. Can be absolute (https://β¦), relative (../about.html), root-relative (/about), a fragment (#faq) or use another scheme such as mailto:, tel: or sms:. |
target |
_self, _blank, _parent, _top, or a name |
Where to open the destination (a navigable: tab, window or iframe). |
rel |
Space-separated keywords | How the current page relates to the destination, and some security and privacy switches. |
download |
Empty, or a file name | Save the destination as a file instead of navigating to it. A value suggests the file name. |
hreflang |
A language tag, e.g. de, pt-BR |
The language of the destination. Advisory only. |
type |
A MIME type, e.g. application/pdf |
The expected type of the destination. Advisory only. |
referrerpolicy |
A referrer policy keyword | How much of the current URL is sent as the Referer header when the link is followed. |
ping |
Space-separated URLs | URLs the browser notifies, with a small POST request, when the link is followed. |
The obsolete attributes name, charset, coords, shape and rev should not be used. Instead of <a name="top">, put an id on the element you want to link to.
The element also accepts the global attributes.
href
href is what turns an <a> into a real link. Relative URLs are resolved against the page address (or a <base> element, if there is one). Common forms:
| Form | Example | Goes to |
|---|---|---|
| Absolute | https://example.com/shop |
An exact address, often on another site |
| Root-relative | /shop/cart |
A path on the same site, from its root |
| Relative | photos/beach.html |
A path relative to the current page's folder |
| Fragment | #returns |
The element with id="returns" on this page |
mailto:[email protected] |
A new message in the user's mail app | |
| Phone | tel:+15555550147 |
A call on devices that can dial |
href="#" or href="#top" scrolls to the top of the page. Avoid href="javascript:β¦": if something should do an action rather than go somewhere, use a <button>.
target
| Value | Opens the destination in |
|---|---|
_self |
The same navigable as the link (the default) |
_blank |
A new, unnamed tab or window |
_parent |
The parent of the current iframe, or the same navigable if there is no parent |
_top |
The topmost navigable, escaping all nested iframes |
| any other name | The tab, window or iframe with that name; a new one is created if none exists |
Modern browsers treat target="_blank" as if rel="noopener" were set, so the new page cannot reach back to yours through window.opener. Opening new tabs takes control away from the user, so do it only when there is a clear reason (for example, a help page next to a half-filled form) and say so in the link text.
rel
rel holds one or more keywords, separated by spaces. The ones that apply to <a>:
| Keyword | Meaning |
|---|---|
alternate |
Another version of the current document: a translation, a print version, a feed |
author |
Information about the author of the current page or article |
bookmark |
The permanent link for the nearest enclosing article or section |
external |
The destination is on a different site |
help |
Help for the current context |
license |
The license that covers the main content of the page |
next / prev |
The next or previous document in a series, such as paged results |
nofollow |
The author does not endorse the destination; search engines may not pass ranking to it |
noopener |
The new page gets no window.opener reference to this one |
noreferrer |
No Referer header is sent; also implies noopener |
opener |
Keep window.opener even for target="_blank" (rarely needed) |
privacy-policy |
The site's privacy policy |
search |
A resource for searching this document or site |
tag |
A tag or category that applies to the current document |
terms-of-service |
The site's terms of service |
Search engines also recognize sponsored (paid or affiliate links) and ugc (links inside user-generated content). These are not part of the HTML standard but are widely used alongside nofollow.
<a href="https://partner.example/" rel="sponsored noopener" target="_blank"> Partner offer (opens in a new tab) </a>
download
download asks the browser to save the destination as a file. With a value, it suggests a file name; browsers may change characters that are not allowed in file names.
<a href="/files/menu-2026.pdf" download="Spring menu.pdf">Download the menu (PDF, 220 KB)</a>
It only works for same-origin URLs and for blob: and data: URLs. For a file on another origin, the browser ignores download and navigates normally. A Content-Disposition header sent by the server takes priority over the attribute.
hreflang and type
Both are hints about the destination. The browser does not check them, and they do not change what is downloaded. They are useful for styling (for example, adding a PDF icon with a[type="application/pdf"]) and as extra information for tools.
<a href="/fr/" hreflang="fr" lang="fr">Version franΓ§aise</a> <a href="/report.pdf" type="application/pdf">Annual report (PDF)</a>
Put lang on the link too when the link text itself is in another language, so screen readers pronounce it correctly.
referrerpolicy
When a link is followed, the browser normally tells the destination which page the user came from, in the Referer request header. referrerpolicy controls how much is shared:
| Value | What is sent |
|---|---|
no-referrer |
Nothing |
no-referrer-when-downgrade |
The full URL, except when going from HTTPS to HTTP |
origin |
Only the origin, e.g. https://example.com/ |
origin-when-cross-origin |
The full URL within the same origin, only the origin elsewhere |
same-origin |
The full URL within the same origin, nothing elsewhere |
strict-origin |
Only the origin, and nothing from HTTPS to HTTP |
strict-origin-when-cross-origin |
Full URL same-origin, origin cross-origin, nothing from HTTPS to HTTP (the browser default) |
unsafe-url |
Always the full URL, including path and query (avoid) |
Use no-referrer or rel="noreferrer" on links where the current URL could contain private information, such as a reset token or a search query.
ping
ping lists URLs that should be notified when the user follows the link. The browser sends each one a small POST request (with the body PING) and then navigates as usual, without waiting for the replies.
<a href="/guide" ping="/stats/click?id=guide">Read the guide</a>
It is meant as a lighter, more transparent alternative to redirect-based click tracking. Some browsers disable it by default or let users turn it off, so treat it as best effort.
Usage notes
- Write link text that makes sense on its own. Screen reader users often pull up a list of all links on the page. "Click here", "read more" and "this" mean nothing in that list; "Download the 2026 timetable" does.
- Every link needs an accessible name. For an image link, the image's
altis the name. For an icon-only link, add visually hidden text oraria-label. - Links go places, buttons do things. Use
<a href>for navigation and<button>for actions such as opening a menu, submitting or deleting. An<a>withouthrefis not keyboard-focusable, so it is a poor substitute for a button. - Warn about surprises. Mention it in the text when a link opens a new tab, downloads a file or leads to a large file type: "Price list (PDF, 1.2 MB)".
- Links can wrap blocks. Because the content model is transparent, an
<a>can wrap a heading, image and paragraph to make a whole card clickable, as long as its parent allows flow content. Keep the text inside short, since all of it becomes the link's name. - No nesting. Don't put a link, button, form control or any element with
tabindexinside an<a>. - Keep the focus outline. Don't remove the browser's focus ring with
outline: noneunless you replace it with an equally visible style. - Links should look like links. Underlines are the clearest cue. If you remove them in running text, make sure color is not the only difference.
Technical summary
| Content categories | Flow content, phrasing content, palpable content; interactive content when href is present |
| Permitted content | Transparent, but with no interactive content, no <a> descendant and no descendant with a tabindex attribute |
| Tag omission | None; both the start and end tags are required |
| Permitted parents | Any element that accepts phrasing content, or flow content (the content model is transparent) |
| Implicit ARIA role | link when href is present; generic otherwise |
| DOM interface | HTMLAnchorElement |
| Default display | inline |
Browser support
The element and href, target, rel, hreflang and type work in every browser. download and referrerpolicy are supported in all current browsers; ping is available in most but can be disabled by the browser or the user.
Related
<link>β relationships to other resources, declared in the head<area>β links on regions of an image map<base>β the base URL and default target for all links<button>β for actions rather than navigation<nav>β a group of major navigation links- Lessons: Links in Depth, Link Targets and Page Jumps, Email, Phone and Download Links, File Paths and URLs, URL Encoding, Building Navigation Menus, Accessibility Basics