Opening links in a new tab is one of those small frontend decisions that carries more weight than it appears to. Get it right and users keep their place in your app while exploring references, documentation, or external resources. In practice, get it wrong and you introduce a security hole, break accessibility expectations, or ship a button that silently fails because a popup blocker ate it. In React, the behavior is straightforward once you understand the underlying browser mechanics, but the details around rel, routing, and accessibility are where most developers stumble.
This guide covers how to open a link in a new tab in React properly — from the plain anchor tag to reusable components, React Router, Next.js, and programmatic window.open() calls — along with the security and accessibility rules that should always come along for the ride Turns out it matters..
The Foundation: target="_blank" in JSX
React renders standard HTML attributes, so the simplest way to open a link in a new tab is the same as in plain HTML:
function ExternalLink({ href, children }) {
return (
{children}
);
}
Two attributes matter here:
target="_blank"tells the browser to open the resource in a new browsing context (a tab or window, depending on user settings).rel="noopener noreferrer"is the security layer. Without it, the newly opened page receives a reference to your page throughwindow.opener.
In JSX, remember that class becomes className, and attributes with hyphens like rel and target stay exactly as they are. Self-closing tags and camelCase event handlers are the other syntax differences you will hit while converting HTML snippets Which is the point..
Why rel="noopener noreferrer" Is Not Optional
The vulnerability that noopener prevents is called reverse tabnabbing. When you open a page with target="_blank" and no noopener, the new page can run JavaScript like this:
// Runs on the *linked* page, not yours
window.opener.location = "https://evil-example.com/phishing";
Because the linked page holds a reference to your window, it can silently redirect your original tab to a convincing fake login screen. The user sees a familiar-looking page in the tab they trusted, and enters credentials. This attack works even if you fully trust the destination today — third-party sites change ownership, get compromised, or serve injected ads.
Easier said than done, but still worth knowing It's one of those things that adds up..
Modern browsers (Chrome 88+, Firefox 79+, Safari 12.1+) now treat target="_blank" as implicitly noopener, so the practical risk has shrunk considerably. Still, writing rel="noopener noreferrer" explicitly is a cheap habit that protects older browsers and signals intent to anyone reading your code.
Understand the tradeoff between the two tokens:
noopener— severs thewindow.openerreference. Does not affect theRefererHTTP header.noreferrer— severswindow.openerand suppresses theRefererheader.noreferrerimpliesnoopener, so writing both is redundant but harmless and very common in real codebases.
The catch: if you rely on referral traffic in your analytics, noreferrer will strip that data, showing the visit as direct traffic. For internal links where you want the referrer preserved, use rel="noopener" alone.
Opening Links Programmatically with window.open()
Sometimes the destination is not known at render time — it comes from an API response, a user action, or a computed value. In those cases you call window.open() inside an event handler:
import { useCallback } from "react";
function OpenReportButton({ reportUrl }) {
const handleClick = useCallback(() => {
if (!reportUrl) return;
const newTab = window.open(reportUrl, "_blank", "noopener,noreferrer");
if (newTab) newTab.opener = null;
}, [reportUrl]);
return (
);
}
A few practical notes on this pattern:
noopenerin thefeaturesstring causes some browsers to returnnullfromwindow.open(). That is expected behavior, not a bug — so guard your code instead of assuming you will get a window reference.- Popup blockers only allow
window.open()during a genuine user gesture. If you wrap it insetTimeout,awaita fetch, or trigger it from auseEffect, the browser will likely block it. Open the tab synchronously, then handle it, or restructure the flow so the call happens directly in the click handler. - Prefer an anchor when you can. A real
<a href>is keyboard-focusable, supports middle-click and "Copy link address," and works when JavaScript fails. Reach forwindow.open()only when the URL genuinely cannot be rendered as markup.
React Router: Link and NavLink with target="_blank"
React Router's Link component renders an anchor under the hood and forwards standard anchor props, so opening a route in a new tab is a one-liner:
import { Link } from "react-router-dom";
function Nav() {
return (
);
}
This works because Link passes unrecognized props through to the DOM element. NavLink behaves identically, and also accepts end, className as a function, and aria-current handling for active states.
One subtlety worth knowing: if you need the current route opened in a new tab, use a plain anchor with href or build the URL with useLocation() and createPath(). Mixing relative to values with target="_blank" can produce surprising results depending on your router version and basename configuration.
The official docs gloss over this. That's a mistake The details matter here..
Next.js: next/link and External URLs
In the Next.js App Router, next/link supports target and rel directly:
import Link from "next/link";
export function Docs() {
return (
<>
Open post in a new tab
External reference
>
);
}
For fully external URLs, next/link renders a standard anchor and skips client-side prefetching, so there is no routing penalty. If you are using next/image with remote sources, remember that domains must be allowlisted in next.Also, config. js under images.remotePatterns — a separate concern from link behavior, but a frequent source of confusion.