: The Anchor Element
Last updated: 2026-09-12
<a>The Anchor Element
The <a> (anchor) element defines a hyperlink. It is the fundamental building block of the World Wide Web, used to link from one page to another, to files, to email addresses, and to locations within the same page.
| Category | Links & Media |
|---|---|
| Content Model | Transparent, flow content, phrasing content |
| Allowed Parents | Any element that accepts phrasing content |
| Content Tag | Yes — requires closing </a> tag |
| Status | Standard |
📝 Syntax
<a href="URL" target="_self|_blank|_parent|_top" rel="relationship">Link text</a>
⚙️ Attributes
This element supports the global attributes plus the following:
| Attribute | Value | Description |
|---|---|---|
href | URL | The destination of the link. Can be a full URL, a relative path, a fragment (#section), or special schemes like mailto: and tel:. |
target | Keyword | Where to open the linked document.
|
download | Filename | Prompts the user to download the linked resource instead of navigating to it. The optional value sets the downloaded file's name. |
rel | Link types | Specifies the relationship between the current document and the linked resource. Common values: nofollow, noopener, noreferrer, nofollow. |
hreflang | Language code | Hints the language of the linked resource, e.g. en, zh-CN, ja. |
type | MIME type | Hints the MIME type of the linked resource, e.g. text/html, image/png. |
▶ Example
Edit the code below and see the live result in the playground:
🌐 Browser Support
| Browser | |||||
|---|---|---|---|---|---|
| <a> | ✓ v1 | ✓ v12 | ✓ v1 | ✓ v1 | ✓ v1 |
| Supported in all major browsers | |||||
Tip: Always use
rel="noopener" (or noreferrer) when opening links in a new tab to avoid tab-nabbing security risks.Warning: Do not wrap block-level interactive elements (like buttons) inside an
<a> tag — it creates invalid nesting and confusing keyboard navigation.❓ FAQ
QHow to open a link in a new tab?
AUse
target="_blank" and add rel="noopener" for security: <a href="url" target="_blank" rel="noopener">QWhat is the difference between href and src?
A
href specifies a hyperlink destination (used in <a>, <link>), while src embeds an external resource (used in <img>, <script>).QCan I put a button inside an tag?
ANo, it's invalid HTML. Interactive elements cannot be nested. Instead, style the
<a> to look like a button using CSS.