Skip to main content

The Last Word (Maybe) on Opening New Windows

From time to time, the question surrounding the opening of new windows (tabs) to external sites...pops up. (Sorry.) I thought I would share a few thoughts as to why we may want to think real hard before implementing this functionality. It is a touchy matter for some and has been discussed, ad nauseam, for years, so I might be beating a dead horse, but this is certainly how I have come to see and respond to the request over the last decade. Also, why repeat myself to friends and colleagues when I can just share this article when fresh controversy over this subject erupts again? I think it is a smart idea to be efficient with our time, since we have so little of it.

History Lesson

Let me tell you a little story. Back in the early days of the web, around the mid to late 90’s, we did a lot of unusual things in an effort to keep users on our sites. If websites were ever narcissistic and creepy, this was their heyday. Hi, where ya going? Stick around and we’ll have some fun. Check out my Flash! Click on me. Don’t leave...please. I think this sums up the experience back then pretty well, don't you? Overall, there was this rampant and irrational fear that if a user left your site, that they would never return. Let's be honest here. With a website going to such great lengths to keep us from leaving—who'd want to stay?

Meme of Elrond from Lord of the Rings, saying 'I Was There 3000 Years Ago'
Spell was there, when new windows ran rampant, 3000 years ago.

In later years, this effort was also combined with a misguided attempt to improve one’s SEO (Search Engine Optimization), so it was very commonplace to have every link that left your site, open in a new window. SEO specialists didn't like the idea of a user leaving a site because it supposedly hurt the "time on page" and bounce rate statistics. However, if a user is not on your site, then they are not on your site. Keeping the window open in the background is not an accurate (or honest) portrayal of usage. Now, combine all of this with hostile attempts to push ads into our faces by hijacking the user experience with popup windows and you have a recipe for a UX disaster, which it was. Suffice to say, this incident has left a long standing bad taste in our collective mouths.

Unfortunately, old habits die hard and many of these outdated notions still prevail, but we know better than to employ such seedy techniques today. (I hope.) On the SEO front, good quality content, proper keyword placement and link building strategies rule the day. We also trust that users will return to our sites without having to hold them hostage. Say what? Yes! Because we trust our users and have done our jobs to craft an experience that they will want or need to return to, no hacks or anti-patterns are required! It is often a smart idea to not make assumptions about certain behaviors and let the user decide if opening a new window is the best course of action. Your users are intelligent! Treat them as such. 'Nuff said.

Personally, I always ask myself a simple question: Do I need a new window? 99% of the time the answer is no, but some functionality may demand it. I never open a new window because I don't want users to leave my site. That's just silly!

If you would like to read another opinion on the subject, by a more reputable and well-known web design heavy-weight, then please check out When to use target="_blank" by Chris Coyier. I am even linking to this article without opening it in a new window. Meta!

So what else might we want to consider before opening up new windows?

Accessibility

Opening up new windows can often be a poor experience for those among us who are disabled. Especially those with cognitive disabilities, who may find the creation of a new window, spawned without warning, to be disorienting. In addition to this, new windows also break the back button, which a lot of users, disabled or not, find very useful. If you must open a new window, then you had better do right by accessibility! Here is one way to handle it:

... <a href="..." target="_blank" aria-label="my link text (opens in new window)">my link text<a> ...

In this technique, I am using aria-label to repeat the link text and add an additional message that indicates that the link will open in a new window. The aria-label attribute will override the text within. We are not done yet, though. ARIA (Accessible Rich Internet Applications) will benefit some assistive technology users, but it won't cover all use cases, so we need to improve upon this a little more by adding a visual indicator, which often looks something like this:

I really enjoy what Jenn Simmons has to say about CSS Grid. Her experimental layout lab has many wonderful examples to learn from.

Here is the CSS that I use for this visual cue. Feel free to steal it!

a[target="_blank"]::after {
background-color: transparent;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAV1BMVEUAAAAWJmEWJmEWJmEWJmEWJmEWJmEWJmEWJmEWJmEWJmEWJmEWJmEWJmEWJmEWJmEWJmEWJmEWJmEWJmEWJmEWJmEWJmEWJmEWJmEWJmEWJmEWJmEWJmFtOP0GAAAAHHRSTlMAj5fWItGGkZqc8tuwk3wn48aliIBwaGIqEskP9S1ThQAAAL1JREFUOMu9kt0OgjAMRruBg41/BATd+z+nriyN3VIvvODc0PCd0jYBLuGhu4pQWquIXQ/MjRdZsd/LzEF4ehkdhCJUjr1347dw+xT1qySGoQSbCgYYi08FxfLK/xYUZu3IhCw34JiQfr+Gg4/IctjxmQkV7TaEwqaC8tRXZiOo34Ig0HxJUHG+JCyxXxQ6yqURLeXSkvoOsnDyv9BDDvsnp94k9HiUPQUZe14ns+E2Tszj2fvcNEVOM20YvwFVpS/vjLAbQwAAAABJRU5ErkJggg==);
background-position: center right;
background-repeat: no-repeat;
background-size: contain;
content: "";
display: inline-block;
height: 14px;
margin-left: 10px;
vertical-align: middle;
width: 14px;
}

There are other ways to pass helpful text to assistive technology users, too. Some may not like the redundancy of text in aria-label, so you can do this:

... <a href="..." target="_blank">my link text <span class="sr-only">(opens in new window)</span><a> ...

With this method, I am including visually hidden text that can still be accessed by assistive technology. I like doing it this way because it is progressive enhancment friendly, but to each their own. There are a thousand ways to handle visually hidden text and Scott O'Hara knows them all.

Finally, this is the most simple way to do it:

... <a href="..." target="_blank">my link text (opens in new window)<a> ...

I really enjoy what Jenn Simmons has to say about CSS Grid. Her experimental layout lab (opens in new window) has many wonderful examples to learn from.

I think I like this most of all! Simple and direct. Yes, it is a bit of a poor man's method, but it'll work in a pinch. There is no shame in it.

Security

Let's briefly talk about security. Full disclosure: I am no security expert, but I know enough to be dangerous. (In a good way—I swear!)

A developer by the name of Mathias Bynens discovered that linking to pages with just target="_blank", could leave your visitors exposed to reverse tabnabbing. The page you are linking to, if compromised, can gain full access to the window.opener object of the parent page. (Your website.) The parent page can then be redirected to a phishing page using window.opener.location. Since the user trusts the parent page they just left, they would have little reason to suspect that it has been hacked. Imagine your parent page beinging seamlessly redirected to a look-alike page, which then requests sensative information from your users! This is terrifying!

To prevent this, it has been recommended that we should be including, in addition to our accessibility improvements, the following attribute:

... <a href="..." target="_blank" aria-label="my link text (opens in new window)" rel="noopener">my link text<a> ...

For older browsers, you would need to add noreferrer:

... <a href="..." target="_blank" aria-label="my link text (opens in new window)" rel="noopener noreferrer">my link text<a> ...

Browsers that support rel="noopener" can be found on Can I Use.

Google Lighthouse even recommends that rel="noopener" be used on links that use target="_blank".

Performance

Finally, it is has also been revealed that target="_blank", when used alone, can cause a slight performance hit when a user is going from one page to another in a new window. Read The Performance Benefits of rel=noopener by Jake Archibald. Once again, rel="noopener" can be helpful here, too! Users like zippy experiences, so why not oblige them whenever you can?

Conclusion

As you can see, there is much to consider before nonchalantly deciding to open new windows with good ol' target="_blank". Throughout this article, I have been very careful to not outright deter use of target="_blank", because there are times where you may need it. However, if you do choose to use it, you should strongly consider all I have mentioned above. This is information that should be shared with fellow colleagues and clients, who often make this request without understanding many of the complexities that may arise due to improper implementation of this functionality.

Given all that could go wrong, whether it be by the hand of a front-end developer or content editor, sometimes the best decision may be not to launch new windows at all. This is a rule I often abide by personally. For clients, I would absolutely approach the launching of new windows with a healthy amount of caution, as a poor implementation can have a negative impact on users, and through that, a negative impact on your client's brand.

Before signing off, let's recap what we should be doing. Feel free to use this to succinctly educate colleagues and clients:

  • Ask Why - Have a really good reason as to why a new window should be opened. Opening new windows, just to keep users on your site, is not a good enough reason.
  • Trust Users - Let your users decide if opening a new window is the best course of action.
  • Accessibility - If a new window is a necessity, use aria-label or alternative techniques for assistive technology and include visual indicators.
  • Security & Performance - If a new window is a necessity, make use of rel="noopener". This will prevent tabnabbing and improve page load between parent and child windows.

Thank you for reading!