Table of Content
This article shows you how to open a link in a new tab. Read the code and follow the examples to apply it to pages.
Understand the Target Attribute and its Values
The target attribute tells the browser where to open the link. Here is how you can write it:
<a href="{url}" target="_blank">Visit site</a>Most users prefer a new tab for external links and long reads. The browser opens a new window or tab for the link target.
That happens so the old page stays in the browser and the reader can go back to it.
Examples of Links that Open in a New Tab
Basic external link:
<a href="https://example.com" target="_blank" rel="noopener">Visit example</a>This example opens an external site in a new tab and sets rel noopener. The rel attribute stops the new tab from accessing the opener page and keeps the session safe.
Load into a named frame (same site):
<a href="page.html" target="sidebar">Open panel</a>
<iframe name="sidebar"></iframe>This example open a link into a named iframe on the same page to load content. Use this to keep user on the main page and to show details inline and avoid full page reloads.
Non-HTTP link (mailto):
<a href="mailto:you@example.com" target="_blank">Email us</a>This example open a mailto link in a new tab to start an email draft outside the site. Use this to keep the main page state and to let the mail app handle the send action.
Wrapping Up
You learned how to open links in a new tab and how the target behaves.
Here is a quick recap:
- Use target
_blankto open a new tab and use relnoopenerto limit access. - Test your links across main browsers to confirm the behavior.
FAQs
How do I open a link in a new tab in HTML?
<a href="https://example.com" target="_blank">Visit Site</a>
Tip: Add rel="noopener noreferrer" for better security.What does target="_blank" mean in HTML?
<a href="https://google.com" target="_blank">Google</a>
It improves navigation but you should use it with care.
Should I use rel="noopener noreferrer" with target blank?
<a href="https://example.com" target="_blank" rel="noopener noreferrer">Safe Link</a>
- Prevents security risks
- Stops performance issues
How do I make all links open in a new tab?
<script>
document.querySelectorAll("a").forEach(link => {
link.setAttribute("target", "_blank");
});
</script>
- This updates every link on the page
- Works dynamically
Similar Reads
The HTML del tag shows text that a user or author removed from a page. A browser shows this text…
The style tag in HTML defines CSS inside a web page. Click to see how it works with syntax and…
You use the HTML <table> tag to display structured data in rows and columns, using table elements such as <tr>…
HTML form validation attributes help you check the form data before it reaches the server. What Are HTML Form Validation…
HTML tags that no longer work stay in the deprecated list. This article explains them and shows the modern replacements.…
The header tag defines the top part of a page or a section in HTML. It usually holds a heading…
HTML syntax shows how tags and attributes go together. It gives browsers the rules to read and display a page.…
The HTML sup tag puts text above the normal line. Writers use it for math power and marks. So, readers…
HTML builds web pages. It does this with elements and tags. Many new learners confuse them, so you need to…
data-* attributes store extra values on elements without an extra DOM nodes or backend requests. What are data-* attributes in…