A Comprehensive Guide to the HTML <a> Tag's rel Attribute: Safety, Privacy, and SEO Best Practices
Hi, I’m HenryZ.
This article discusses a pitfall that every front-end developer has encountered but often glosses over: the rel attribute of the <a> tag.
After reading this, you’ll be able to tell yourself: “From now on, whenever I use target="_blank", I’ll first write noopener and then add others as needed.”
1. Understand Two Things First
| Question | One-sentence Answer |
|---|---|
What is rel for? | It tells the browser “what my relationship with that link is” and decides whether to hand over information from the previous page. |
Why is it always used with target="_blank"? | A new tab will get the window.opener pointer, which can tamper with the source page in reverse—this is called reverse tabnabbing. |
2. The Safety Duo: noopener / noreferrer
| Attribute | What It Does | Additional Effect | Recommended Scenario |
|---|---|---|---|
noopener | Cuts off window.opener | None | Add to all target="_blank" links to ensure safety first |
noreferrer | Does not send the Referer request header | Modern browsers also cut off window.opener | Use when you don’t want the target site to know where you’re coming from |
What does “cutting off
window.opener” mean?
By default, thewindow.openerin a new tab points to the page that opened it.
With this “key to go back,” the new page can: