How to Open Links in a New Tab using target="_blank" in HTML
When you add a hyperlink in HTML using the <a>
tag, by default, the link opens in the same browser tab.
But sometimes you may want the link to open in a new tab or window—for example, when linking to an external website.
This is done using the target="_blank"
attribute.
Syntax
<a href="https://www.example.com" target="_blank">Visit Example</a>
href
→ URL of the page you want to open.target="_blank"
→ tells the browser to open the link in a new tab (or new window, depending on browser settings).Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Target _blank Example</title>
</head>
<body>
<p>Click below to visit Google:</p>
<a href="https://www.google.com" target="_blank">Open Google in New Tab</a>
</body>
</html>
When you click the link, Google will open in a new tab, and your current page stays open.
Why Use target="_blank"?
- To keep users on your website while letting them explore other resources.
- Useful for external links (so users don’t lose your site).
- Helpful in blogs, documentation, and reference links.
Important Note: Security Best Practice
When using target="_blank"
, always add rel="noopener noreferrer"
to prevent potential security risks (like tabnabbing attacks).
Example with Security:
<a href="https://www.example.com" target="_blank" rel="noopener noreferrer">
Visit Example Securely </a>
Difference Between Common Target Values
Value | Behavior |
---|---|
_self (default) | Opens link in the same tab |
_blank | Opens link in a new tab/window |
_parent | Opens link in parent frame (if using frames) |
_top | Opens link in full body of the window |
FAQs
Q1. Does target="_blank"
always open a new tab?
Not always. Some browsers or user settings may open it in a new window instead.
Q2. Should I use _blank
for all links?
No. Use it only for external links or when you want to keep users on your site.
Q3. Why add rel="noopener noreferrer"
?
It prevents the newly opened tab from accessing your page, which improves security and performance.
Q4. Is _blank
good for SEO?
It does not affect SEO directly. But keeping users on your page longer can reduce bounce rates, which is good for user experience.