The short answer

#

Add target="_blank" to the link. Current browsers already treat that as rel="noopener", but writing rel="noopener noreferrer" yourself is still a good habit: it makes the intent clear to the next developer and noreferrer also stops the referrer being sent. Then tell people the link opens in a new tab.


_10
<a href="https://example.com/report.pdf" target="_blank" rel="noopener noreferrer">
_10
Annual report (PDF, opens in a new tab)
_10
</a>

Why it happens

#

When a link opens a new browsing context with target="_blank", the new page used to get a reference back to your page through window.opener. A hostile or compromised page could then run something like window.opener.location = "https://fake-login.example" and quietly replace your original tab with a phishing page. Users would switch back, see a familiar looking login form and type their password. This is known as reverse tabnabbing.

The noopener keyword cuts that link: in the new page, window.opener is null. The HTML standard was later changed so that target="_blank" on links implies noopener by default, and all current major browsers follow it. That is why the old warning is less urgent than it was, but it does not cover everything (see the pitfalls below).

The noreferrer keyword goes further. It stops the browser sending the Referer header to the destination, and it implies noopener too. The trade-off is that the destination site can no longer see where its visitors came from, which matters if you rely on referral traffic showing up in someone else's analytics.

How to fix it

#

Use target="_blank" with an explicit rel. Pick noopener if you want the destination to see your site as the referrer, or noopener noreferrer if you do not.


_10
<!-- Destination still sees your origin as the referrer -->
_10
<a href="https://partner.example" target="_blank" rel="noopener">Partner site</a>
_10
_10
<!-- No referrer is sent at all -->
_10
<a href="https://other.example" target="_blank" rel="noopener noreferrer">Other site</a>

Opening a tab from JavaScript

The implicit noopener rule applies to links, not to window.open. Pass the feature yourself. With noopener, window.open returns null, so you cannot script the new window afterwards.


_10
window.open("https://example.com", "_blank", "noopener,noreferrer");

A new tab breaks the back button for that page, which surprises keyboard and screen reader users in particular. Say so in the link text, or add visually hidden text next to an icon.


_10
<a href="https://example.com/terms" target="_blank" rel="noopener">
_10
Terms of service
_10
<span class="visually-hidden">(opens in a new tab)</span>
_10
</a>

When not to open a new tab

#

Most of the time, leave links alone. People can already open any link in a new tab with a middle click, Ctrl or Cmd click, or a long press on mobile. Forcing it takes that choice away.

A new tab does make sense when leaving the page would lose work, such as a help link in the middle of a long form or checkout. It can also suit links inside an app shell, an editor preview or a chat window. It is rarely worth it just because a link points to another site.

Common pitfalls

#
  • Writing target="blank" without the underscore. That creates a window named "blank", and every link with the same target reuses that one tab instead of opening a new one.
  • Assuming window.open is protected by the implicit noopener rule. It is not, so add the feature string.
  • Adding noreferrer everywhere by reflex, then wondering why partners cannot see your referral traffic.
  • Opening every external link in a new tab. It clutters tabs, breaks the back button and is a common accessibility complaint.
  • Using a JavaScript click handler instead of a real link. You lose middle click, copy link and the browser's own security defaults.
#
file under:
HTML

quick question

Was this resource helpful?