Why This Matters
Opening links in new browser windows or tabs is a common feature in modern web development, but it's surrounded by accessibility concerns, security considerations, and user experience debates. This guide covers the HTML implementation, security best practices, and accessibility requirements you need to know.
According to the W3C's Web Content Accessibility Guidelines (WCAG), opening new windows can disorient users, particularly those using screen readers or zoom features. Modern browsers support the anchor element across all platforms, making it a baseline feature for web developers.
However, the feature must be implemented thoughtfully. When done incorrectly, it creates security vulnerabilities and accessibility barriers. When done correctly, it can enhance user experience in specific scenarios. Our web development services emphasize these foundational HTML practices to ensure every website we build follows security and accessibility best practices from the ground up.
The Basic HTML Implementation
The HTML anchor element provides the target attribute to control link behavior. Understanding this attribute is fundamental to proper implementation.
How target="_blank" Works
The target="_blank" attribute on an anchor element instructs the browser to open the linked URL in a new tab or window. Modern browsers universally open new tabs rather than new windows by default, as this better aligns with user preferences and tabbed browsing workflows.
<!-- Opens the link in a new tab -->
<a href="https://example.com" target="_blank">Visit Example</a>
This simple addition changes the default behavior. Instead of navigating the current page away, the browser creates a new tab and loads the destination there.
Default Behavior Without target="_blank"
Without the target attribute, links navigate within the current tab. This is the default behavior and often the preferred approach for most links on a website. Users maintain their browsing context, can use the back button naturally, and control their own experience through browser controls. Following consistent CSS naming conventions helps maintain readable and maintainable HTML structures across your codebase.
1<!-- Basic new tab link (NOT secure) -->2<a href="https://example.com" target="_blank">3 Visit Example4</a>5 6<!-- SECURE version with rel attributes -->7<a href="https://example.com" target="_blank" rel="noopener noreferrer">8 Visit Example9</a>Security Considerations
Opening links in new tabs introduces security considerations that developers must address. The rel attribute provides the necessary protections.
The Opener Tab Vulnerability
When you use target="_blank" without additional attributes, the newly opened page can access the window.opener object of the original page. This creates a security vulnerability known as "tabnabbing" or "reverse tabnabbing". The new page can:
- Redirect the original tab to a malicious site
- Access the original page's DOM through window.opener
- Modify the appearance of the original page
- Intercept sensitive information
The Solution: rel="noopener noreferrer"
The recommended fix is to add rel="noopener noreferrer" to any link using target="_blank". This attribute combination provides two important protections:
-
noopener: Prevents the new page from accessing the
window.openerobject, breaking the connection between the two pages. -
noreferrer: Prevents the browser from sending the referring URL to the new page, adding privacy protection.
At Digital Thrive, we build all external links with these security attributes as a standard practice. Our development process includes code review checklists that verify every external link meets these security requirements before deployment. Implementing robust error handling patterns alongside security best practices ensures your website remains safe and functional.
1<!-- Secure external link pattern -->2<a href="https://example.com" target="_blank" rel="noopener noreferrer">3 External Resource4</a>5 6<!-- Minimum secure version -->7<a href="https://example.com" target="_blank" rel="noopener">8 External Resource9</a>Accessibility Requirements
Making links that open in new tabs accessible requires both visual and non-visual considerations. WCAG guidelines emphasize that users must be informed when a link will open a new window.
Visual Indicators
Visual users need clear indication that a link opens in a new tab. This allows them to make informed decisions before clicking. Adding "(opens in new tab)" text after such links provides clear communication.
Screen Reader Accessibility
For non-visual users, screen readers must announce that links open in new tabs. This requires using visually hidden text that screen readers can detect. When implementing accessible links, also ensure your Make img alt visible strategies are in place for consistent accessibility across all interactive elements.
Focus Management with hasfocus
Implementing proper focus management is crucial when links open new tabs. The hasfocus selector helps ensure keyboard users maintain their place in the navigation flow, creating a seamless experience for users who rely on keyboard navigation. Combining hasfocus patterns with new tab accessibility creates an inclusive experience for all users.
CSS for Visually Hidden Text
.visually-hidden {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
We incorporate these accessibility patterns as part of our comprehensive accessibility audit services, ensuring websites meet WCAG compliance while maintaining excellent user experience.
1<!-- Accessible external link with icon and screen reader text -->2<a href="https://example.com" target="_blank" rel="noopener noreferrer" class="external-link">3 Visit Example4 <span class="visually-hidden">(opens in new tab)</span>5 <svg aria-hidden="true" class="external-icon" width="16" height="16">6 <use href="/icons.svg#external-link"></use>7 </svg>8</a>User Experience Guidelines
Research from the Nielsen Norman Group provides valuable insights into when users prefer links to open in new tabs versus the same tab.
When New Tabs Work Well
Certain scenarios benefit from opening links in new tabs:
-
Comparing content: When users need to view multiple items side by side, such as product comparisons.
-
Keeping track of items: In shopping scenarios, users often open product details in new tabs to compare options.
-
Using original tab as a launching point: When the original page serves as a reference and users will return to it.
-
Multi-step workflows: When a link provides supplementary information that doesn't replace the current task.
-
Forms and applications: To prevent losing form data when users need to reference external documentation.
When to Avoid New Tabs
- Quick information lookup when users expect a brief diversion
- Linear workflows where the link is part of a sequential process
- Mobile devices where back button and tab switching are more difficult
- Content-heavy reading where users prefer reading in the same tab
- When users already have many open tabs
The Default Recommendation
For the most part, always open links in the same browser tab or window. Users can always right-click and choose "Open in new tab" when they prefer that behavior. Taking away this choice can frustrate users and disrupt their workflow. When designing responsive layouts, consider how aspect ratios for grid items and other responsive techniques affect the user experience across different devices.
Mobile Considerations
Mobile browsers handle new tabs differently than desktop browsers, requiring special consideration for mobile users.
Mobile Browser Behavior
On mobile devices, opening a new tab doesn't create the same user experience as on desktop. The back button is harder to access, tab switching requires multiple gestures, and screen space is limited. Users often cannot see their original tab when a new one opens.
Responsive Link Strategy
Consider implementing different behaviors based on device type, or avoid using target="_blank" for mobile users entirely, allowing them to make the choice through long-press gestures. Creating smooth animations and no-jank CSS stripes for loading indicators helps maintain a polished experience when users do navigate between content.
Touch Interaction Patterns
Mobile users expect certain touch interactions:
- Tap to follow link in same tab
- Long-press to open in new tab
- Swipe to switch tabs (on supported browsers)
By not forcing new tabs, you respect these native interaction patterns and user expectations. Our mobile development services ensure websites adapt link behavior appropriately for each device type, providing a seamless experience across desktop and mobile.
Best Practices Summary
Implementing links that open in new tabs correctly requires attention to multiple concerns:
-
Always use
rel="noopener noreferrer"withtarget="_blank"to prevent security vulnerabilities. -
Add accessibility indicators through visual icons and screen reader text.
-
Reserve new tabs for specific scenarios rather than applying them universally.
-
Consider mobile users who have different navigation expectations.
-
Let users control their experience by making deliberate choices about when to use new tabs.
-
Test across devices and browsers to ensure consistent behavior.
-
Document your link strategy for content creators to maintain consistency.
Following these best practices ensures your website provides a secure, accessible, and user-friendly experience while maintaining the flexibility to open links in new tabs when it truly benefits the user.
Common Implementation Patterns
React Component Pattern
function ExternalLink({ href, children }) {
return (
<a
href={href}
target="_blank"
rel="noopener noreferrer"
className="external-link"
>
{children}
<span className="visually-hidden">(opens in new tab)</span>
</a>
);
}
CMS Integration
When building a CMS, consider adding a "open in new tab" checkbox that automatically applies the correct attributes and accessibility features. Our custom web development services include building CMS integrations that handle these patterns automatically, reducing the burden on content editors while maintaining best practices.
Automated Link Enhancement
For existing sites, you can use JavaScript to automatically add security attributes to external links:
document.querySelectorAll('a[target="_blank"]').forEach(link => {
if (!link.getAttribute('rel')?.includes('noopener')) {
link.rel = (link.rel || '') + ' noopener noreferrer';
}
});
When integrating JavaScript link enhancement with your CSS, following established CSS and JavaScript patterns ensures maintainable and performant code. Combined with proper CSS ruleset terminology, your stylesheets remain organized and scalable.
Conclusion
Opening links in new tabs is a powerful feature when implemented thoughtfully. The HTML is simple--target="_blank" with rel="noopener noreferrer"--but the surrounding considerations of accessibility, security, and user experience require careful attention.
Follow the core principles: protect against tabnabbing attacks, inform users visually and non-visually when new tabs will open, and reserve new tabs for scenarios where they genuinely benefit the user. By doing so, you'll create links that are secure, accessible, and user-friendly across all devices and contexts.
Need help ensuring your website follows these best practices? Our web development team can review your site's link implementations and make recommendations tailored to your specific needs.
Frequently Asked Questions
Sources
-
W3C WCAG Techniques G200 - Official accessibility guidance on opening new windows.
-
MDN Web Docs: The Anchor Element - HTML specification for target and rel attributes.
-
Pope Tech Blog: How to make external links accessible - Code examples for accessible external links.
-
Nielsen Norman Group: Opening Links in New Browser Windows and Tabs - UX research-based analysis of user preferences.