How to Open a Link in a New Tab in HTML
What you’ll build or solve
You’ll open a link in a new browser tab using a single HTML attribute.
When this approach works best
Opening a link in a new tab works best when you:
Learn HTML on Mimo
- Send users to an external website.
- Link to documentation or references.
- Share third-party resources without interrupting your page.
- Let users view a file while keeping your page open.
This approach is a bad idea for normal internal navigation. Most internal links should open in the same tab.
Prerequisites
- A code editor
- A browser
- Basic understanding of the
<a>tag
No additional setup is required.
Step-by-step instructions
Step 1: Add target="_blank" to your link
To open a link in a new tab, add the target="_blank" attribute to your anchor tag.
<ahref="https://example.com"target="_blank">
Visit Example
</a>
hrefdefines the destination.target="_blank"tells the browser to open it in a new tab.
This works with any valid link, including external websites, internal pages, and files.
What to look for:
- The value must be
_blankwith an underscore. - If the link opens in the same tab, confirm the
targetattribute is present and spelled correctly.
Step 2: Add rel="noopener noreferrer" for external links
When linking to third-party websites, include a rel attribute for security.
<ahref="https://example.com"
target="_blank"
rel="noopener noreferrer">
Open Securely
</a>
noopenerprevents the new page from accessing your page throughwindow.opener.noreferrerprevents the browser from sending referral information.
Use this for external links. Internal links usually do not need it.
What to look for:
- The same
target="_blank"technique works for external sites, internal pages, and files. - For file downloads, use the
downloadattribute instead of relying on a new tab:
<ahref="resume.pdf"download>Download Resume</a>
- Internal navigation often works better in the same tab.
- Confirm the URL in
hrefis correct and not empty.
Examples you can copy
Example 1: External documentation link
<p>
Read more on
<ahref="https://developer.mozilla.org"
target="_blank"
rel="noopener noreferrer">
MDN Web Docs
</a>.
</p>
Example 2: External partner link in navigation
<nav>
<ahref="index.html">Home</a>
<ahref="pricing.html">Pricing</a>
<ahref="https://partner-site.com"
target="_blank"
rel="noopener noreferrer">
Partner Site
</a>
</nav>
Example 3: Open a PDF in a new tab
<ahref="guide.pdf"target="_blank">
View Guide
</a>
Users can read the file while your page stays open.
Common mistakes and how to fix them
Mistake 1: Forgetting the target attribute
What you might do
<ahref="https://example.com">
Visit Example
</a>
Why it breaks
Links open in the same tab by default.
Fix
<ahref="https://example.com"target="_blank">
Visit Example
</a>
Mistake 2: Missing rel on external links
What you might do
<ahref="https://example.com"target="_blank">
External Site
</a>
Why it causes issues
Without rel="noopener noreferrer", the new page can access your original page through window.opener.
Fix
<ahref="https://example.com"
target="_blank"
rel="noopener noreferrer">
External Site
</a>
Mistake 3: Typing the target value incorrectly
What you might do
<ahref="https://example.com"target="blank">
Visit
</a>
Why it breaks
The value must be _blank, not blank.
Fix
<ahref="https://example.com"target="_blank">
Visit
</a>
Troubleshooting
If the link opens in the same tab, check that target="_blank" is present.
If security scanners warn about external links, confirm rel="noopener noreferrer" is added.
If nothing happens on click, verify the href value is valid.
If a file does not open, confirm the file path is correct.
If pop-up blockers interfere, test in a different browser.
Quick recap
- Add
target="_blank"to open a link in a new tab. - Use
rel="noopener noreferrer"for external links. - The same technique works for pages, websites, and files.
- Use
downloadif you want to suggest downloading instead. - Double-check that
_blankincludes the underscore.
Join 35M+ people learning for free on Mimo
4.8 out of 5 across 1M+ reviews
Check us out on Apple AppStore, Google Play Store, and Trustpilot