1324

Is it possible to open an a href link in a new tab instead of the same tab?

<a href="http://your_url_here.html">Link</a>
1

4 Answers 4

2375

You should add the target="_blank" and rel="noopener noreferrer" in the anchor tag.

For example:

<a target="_blank" rel="noopener noreferrer" href="http://your_url_here.html">Link</a>

Adding rel="noopener noreferrer" is not mandatory, but it's a recommended security measure. More information can be found in the links below.

Source:

12
  • 6
    there is no _tab... there is _new and _blank
    – Nathan
    Commented Mar 21, 2013 at 15:40
  • 6
    No new either according to w3schools: w3schools.com/tags/att_a_target.asp Commented Mar 21, 2013 at 15:41
  • 42
    _blank is handled on a vendor basis. Most modern browsers will, by default, open in a new tab. Older browsers, such as the IE hoard, will open in a new window - either because they don't have a tabbed feature, or because their default behaviour is a new window.
    – Larry
    Commented May 31, 2013 at 10:23
  • 6
    When not using a special name, as specified in links above, target is the name of the window (or "frame") you're targeting. If you set it to _tab or _new then it opens a window with that name. If a user clicks that link, goes back to your initial page and clicks another link with the same target, the tab/window opened the first time should have the content loaded into it. Commented Jan 5, 2015 at 3:00
  • 34
    A tip: be aware of vulnerability due _blank. More info medium.com/@jitbit/…
    – Aistis
    Commented May 5, 2016 at 10:39
223

It shouldn't be your call to decide whether the link should open in a new tab or a new window, since ultimately this choice should be done by the settings of the user's browser. Some people like tabs; some like new windows.

Using _blank will tell the browser to use a new tab/window, depending on the user's browser configuration and how they click on the link (e.g. middle click, Ctrl+click, or normal click).

Additionally, some browsers don't have a tabs feature and therefore cannot open a link in a new tab, only in a new window.

10
  • 11
    I have to agree fully with taking away the decision from the user or browser. The user will have a preference which they are accustomed to and this removes their right to their preference. However, that being said... there are times that this is needed. (print dialogs, etc)
    – avanderw
    Commented Nov 27, 2013 at 7:17
  • 7
    Although I feel this is true in many cases, for less technical users, I think (my opinion) that this simply is frequently not true. Some users may need this help or they risk the chance of not knowing how to get back to a page that they wanted left open. My two cents to try to put a little more of a user experience perspective on things. Commented Jan 30, 2014 at 5:44
  • 8
    I would agree with the "shouldn't" for websites, but remember that not all HTML is written for websites. I was thinking of something for an in-house web-app where it would be nice make some links open in new tabs without teaching everyone in the office how to ctrl+click.
    – TecBrat
    Commented Mar 14, 2014 at 17:15
  • 17
    How is this so highly rated when it doesn't even answer the question?
    – Yay295
    Commented Sep 9, 2015 at 1:23
  • 7
    I would patently disagree that this is a "best practice", and argue that it depends entirely on the use case. For instance, I work on a web application where the user is performing most of their daily work, and having a link navigate in the same tab would be terrible. Likewise, if I have a tutorial/instructional page, I would link out to related materials, and wouldn't want to navigate in-place. However, if the page is just intended to be consumed by the user, navigating in-place would likely be more ideal.
    – Spazmoose
    Commented Jun 28, 2017 at 20:02
56

set the target attribute of your <a> element to "_tab"

EDIT: It works, however W3Schools says there is no such target attribute: http://www.w3schools.com/tags/att_a_target.asp

EDIT2: From what I've figured out from the comments. setting target to _blank will take you to a new tab or window (depending on your browser settings). Typing anything except one of the ones below will create a new tab group (I'm not sure how these work):

From the link:

_blank  Opens the linked document in a new window or tab
_self   Opens the linked document in the same frame as it was clicked (this is default)
_parent Opens the linked document in the parent frame
_top    Opens the linked document in the full body of the window
framename   Opens the linked document in a named frame
9
  • 1
    you mean _blank or _new...from what i know there is no _tab
    – Nathan
    Commented Mar 21, 2013 at 15:38
  • 12
    W3Schools is NOT the W3C. See w3fools.com Commented Mar 21, 2013 at 15:41
  • 2
    @Jacedc You can use anything there instead of _tab. It creates a window-group. Commented Mar 21, 2013 at 15:46
  • 6
    Not everything at W3Schools is incorrect. But before you said the W3C (The World Wide Web Consortium), and then linked to W3Schools, which has no relation to the W3C or creating the web standards whatsoever. But I see you edited it. :) Commented Mar 21, 2013 at 15:47
  • 3
    Yeah, because you pointed it out and I stand corrected, thanks for that :) Commented Mar 21, 2013 at 15:48
42

You can simply do that by setting target="_blank", w3schools has an example.

2
  • simple and to the point, thanks
    – Emre
    Commented Aug 1, 2018 at 9:07
  • 1
    Beware that even though adding rel="noopener noreferrer" is optional, it has security problems. Just copy the accepted answer, or read the links mentioned in there to find out why it's needed.
    – Nick
    Commented Jul 22, 2019 at 20:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.