What if your visitors never had to lose their place on your site when clicking links?
Why Opening links in new tab in HTML? - Purpose & Use Cases
Imagine you have a webpage with many links. You want users to open some links without leaving your page, so they can easily come back.
If you just add links normally, clicking them replaces your page. Users lose their place and have to hit back, which can be frustrating and slow.
Using a simple attribute in your link tag, you can tell the browser to open the link in a new tab automatically. This keeps your page open and improves user experience.
<a href="https://example.com">Visit Example</a><a href="https://example.com" target="_blank" rel="noopener noreferrer">Visit Example</a>
This lets users explore other pages without losing your site, making navigation smoother and more user-friendly.
On a blog, you link to sources or references. Opening them in new tabs lets readers check details without losing their spot in your article.
Opening links in new tabs keeps your page open for users.
It prevents frustration from losing place when clicking links.
Adding target="_blank" and rel="noopener noreferrer" is a simple, safe way to do this.
Practice
<a> tag makes the link open in a new browser tab?Solution
Step 1: Understand the purpose of the
Thetargetattributetargetattribute in an<a>tag controls where the linked document opens.Step 2: Identify the correct value for opening in a new tab
Usingtarget="_blank"tells the browser to open the link in a new tab or window.Final Answer:
<a href="url" target="_blank"> -> Option DQuick Check:
Open link in new tab = target="_blank" [OK]
- Using href="_blank" instead of target
- Using rel attribute to open new tab
- Using open="new" which is invalid
Solution
Step 1: Use
This attribute opens the link in a new tab or window.target="_blank"to open link in new tabStep 2: Add
This prevents the new page from accessing the original page via JavaScript, protecting against security risks.rel="noopener noreferrer"for securityFinal Answer:
<a href="https://example.com" target="_blank" rel="noopener noreferrer">Link</a> -> Option AQuick Check:
New tab + security = target="_blank" + rel="noopener noreferrer" [OK]
- Omitting rel attribute causing security risk
- Using target="new" instead of _blank
- Using rel without target="_blank"
<a href="https://openai.com" target="_blank">Visit OpenAI</a>
Solution
Step 1: Check the
The attributetargetattribute valuetarget="_blank"instructs the browser to open the link in a new tab or window.Step 2: Understand browser behavior
Most modern browsers open links withtarget="_blank"in a new tab by default.Final Answer:
The link opens in a new tab. -> Option AQuick Check:
target="_blank" means new tab [OK]
- Thinking it opens in the same tab
- Confusing new window with new tab
- Assuming no action happens without rel attribute
<a href="https://example.com" target="blank">Example</a>
Solution
Step 1: Check the
The value is "blank" but it must be "_blank" with an underscore to open in a new tab.targetattribute valueStep 2: Confirm other attributes
While addingrel="noopener noreferrer"is recommended for security, the main error preventing new tab opening is the wrong target value.Final Answer:
Incorrect target value; should be "_blank" with underscore. -> Option CQuick Check:
target must be "_blank" with underscore [OK]
- Using target="blank" without underscore
- Forgetting rel attribute for security
- Assuming missing protocol breaks new tab
Solution
Step 1: Identify internal vs external link behavior
Internal links (like "/about") should open in the same tab, so notargetattribute is needed.Step 2: Apply new tab and security attributes to external links
External links should usetarget="_blank"andrel="noopener noreferrer"for security and to open in new tabs.Final Answer:
<a href="/about">About</a> <a href="https://external.com" target="_blank" rel="noopener noreferrer">External</a> -> Option BQuick Check:
Internal same tab, external new tab + security [OK]
- Adding target="_blank" to internal links unnecessarily
- Using target="blank" without underscore
- Omitting rel attribute on external links
Ready to prove it?
Pass the test and this pattern moves unknown
