: 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.

CategoryLinks & Media
Content ModelTransparent, flow content, phrasing content
Allowed ParentsAny element that accepts phrasing content
Content TagYes — requires closing </a> tag
StatusStandard

📝 Syntax

<a href="URL" target="_self|_blank|_parent|_top" rel="relationship">Link text</a>

⚙️ Attributes

This element supports the global attributes plus the following:

AttributeValueDescription
hrefURLThe destination of the link. Can be a full URL, a relative path, a fragment (#section), or special schemes like mailto: and tel:.
targetKeywordWhere to open the linked document.
  • _self — Default. Opens the linked document in the same tab or window.
  • _blank — Opens the linked document in a new tab or window. Use with rel="noopener" for security.
  • _parent — Opens the linked document in the parent frame (when using iframes).
  • _top — Opens the linked document in the full body of the window, ignoring all frames.
downloadFilenamePrompts the user to download the linked resource instead of navigating to it. The optional value sets the downloaded file's name.
relLink typesSpecifies the relationship between the current document and the linked resource. Common values: nofollow, noopener, noreferrer, nofollow.
hreflangLanguage codeHints the language of the linked resource, e.g. en, zh-CN, ja.
typeMIME typeHints 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 ChromeChrome EdgeEdge FirefoxFirefox SafariSafari OperaOpera
<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?
Ahref specifies a hyperlink destination (used in <a>, <link>), while src embeds an external resource (used in <img>, <script>).

📚 Related Tutorials

Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏