on
'target' : Blank or New?
Links. Links to other pages, internal links, links that aren’t links. No matter what we do with them, they’re one of the basic building blocks of the World Wide Web (why don’t we call it that as much anymore?).
Anyway, this is a short and simple post to detail one thing and one thing only. What do we do when we want to open a link in a new tab? It’s pretty easy, but I always forget which of the following forms it takes:
<a href="https://example.com" target="_blank">Open in new Tab</a>
<a href="https://example.com" target="_new">Open in new Tab</a>
And here’s the answer: _blank
. Why? Because _new
doesn’t have any special meaning. It’s that simple.
<a href="https://example.com" target="_blank">Open in new Tab</a>
Never shall I have to do a Google Search to find this StackOverflow post target=“_blank” vs. target=“_new” again.
On that note, only _blank
, _self
, _parent
, and _top
have any special meaning. See the
HTML Spec for more details.
Security Note
Just note that if using _blank
when pointing to an untrusted website, you should also add rel="noopener"
as well. This ensures that the site being opened won’t have access to the opener
property and hence the ability to find out information about your site from their JavaScript
<a href="https://example.com" target="_blank" rel="noopener">Open in new Tab</a>
There is further info on Google’s Web Developers site and About rel=“noopener” by Mathias Bynens.