---
title: "How do I open a link in a new tab safely?"
description: "Use target=\"_blank\" to open a link in a new tab. Learn what rel=\"noopener noreferrer\" does, what browsers now do for you, and when you should not open new tabs at all."
url: https://www.danny.engineering/answer/html/how-do-i-open-a-link-in-a-new-tab-safely
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T18:57:00.000Z
tags: ["HTML"]
---

# How do I open a link in a new tab safely?

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


```html
<a href="https://example.com/report.pdf" target="_blank" rel="noopener noreferrer">
  Annual report (PDF, opens in a new tab)
</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


### Plain HTML links


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.


```html
<!-- Destination still sees your origin as the referrer -->
<a href="https://partner.example" target="_blank" rel="noopener">Partner site</a>

<!-- No referrer is sent at all -->
<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.


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


### Tell people the link opens a new tab


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.


```html
<a href="https://example.com/terms" target="_blank" rel="noopener">
  Terms of service
  <span class="visually-hidden">(opens in a new tab)</span>
</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.

## Related reading

- [MDN: rel=noopener](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/noopener)
- [MDN: the anchor element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a)
- [MDN: Window.open()](https://developer.mozilla.org/en-US/docs/Web/API/Window/open)
