What is noopener noreferrer in HTML and Why Use It
noopener and noreferrer are values for the rel attribute on links that open in a new tab. noopener stops the new page from controlling the original page, improving security, while noreferrer prevents the browser from sending the original page's address to the new page, protecting privacy.How It Works
When you click a link that opens in a new tab using target="_blank", the new page can access the original page through a special connection called window.opener. This is like giving the new page a remote control to the original page, which can be risky if the new page is untrusted.
Adding rel="noopener" cuts this connection, so the new page cannot control or change the original page. Think of it as closing the remote control so the new page can’t press any buttons on your original page.
rel="noreferrer" goes a step further by also stopping the browser from sending the original page’s address (the "referrer") to the new page. This helps keep your browsing history private, like not telling the new page where you came from.
Example
noopener and noreferrer. The new page cannot access or control the original page, and it won’t know where the visitor came from.<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Noopener Noreferrer Example</title> </head> <body> <a href="https://example.com" target="_blank" rel="noopener noreferrer">Visit Example.com safely</a> </body> </html>
When to Use
Use rel="noopener noreferrer" whenever you create links that open in a new tab with target="_blank". This is important for security and privacy, especially when linking to websites you don’t control.
For example, if you link to an external site, adding these attributes prevents that site from potentially manipulating your page or seeing your URL. It’s a simple way to protect your users and your website from common web risks.
Key Points
- noopener stops the new tab from controlling the original page.
- noreferrer hides the original page’s address from the new tab.
- Both improve security and privacy when opening links in new tabs.
- Always add
rel="noopener noreferrer"withtarget="_blank"links.