The <a> (anchor) 元素创建超链接。它的 href 是目标地址,可以是 URL、路径、页内锚点或特殊协议。
html
External site
Internal page (relative)
Jump to an element with id="section2"
Send email
Call us
<a href="https://other.com" target="_blank" rel="noopener noreferrer">
Opens in a new tab
</a>
target="_blank" 会打开新标签页,但你应该添加 rel="noopener":没有它,新页面可以访问 window.opener 并可能重定向你的页面(一种"标签页劫持"攻击)。noreferrer 也会删除引用页面头。现代浏览器对 _blank 暗示 noopener,但明确添加它是最佳实践。
<a href="..." rel="nofollow">Don't pass SEO ranking (untrusted/user links)</a>
<a href="..." rel="noopener">Security: no window.opener access</a>
<a href="..." rel="sponsored">Paid/affiliate link</a>
<a href="#top">Back to top</a>
...
<div id="top">...</div> <!-- the link scrolls here -->
点击会滚动到 id 与 fragment 匹配的元素。
锚点是网络导航的骨干。
了解 href 协议(相对、绝对、fragment、mailto/tel)、target="_blank" + rel="noopener" 安全配对以及与 SEO 相关的 rel 值对于正确、安全的链接至关重要。