95

This is a line for a hyperlink in HTML:

<a href="http://www.starfall.com/">Starfall</a>

Thus, if I click on "Starfall" my browser - I am using FireFox - will take me to that new page and the contents of my window will change. I wonder, how can I do this in HTML so that the new page is opened in a new window instead of changing the previous one? Is there such a way in HTML?

And if yes, is there a way to open the requested page in another tab (not another window) of my browser?

9 Answers 9

140
<a href="http://www.starfall.com/" target="_blank">Starfall</a>

Whether it opens in a tab or another window though is up to how a user has configured her browser.

2
  • 6
    Not all browsers support tabs and in those that do, pages opening in a new tab vs. a new window is a user-configurable setting. There is no current way to specify a link needs to open in a tab vs. a window.
    – bta
    Feb 26, 2010 at 18:37
  • 2
    remember that the target attribute has to be declared AFTER the href attribute
    – M.C.
    Aug 29, 2016 at 12:40
109

Simplest way is to add a target tag.

<a href="http://www.starfall.com/" target="Starfall">Starfall</a>

Use a different value for the target attribute for each link if you want them to open in different tabs, the same value for the target attribute if you want them to replace the other ones.

3
  • 47
    +1 for pointing out that the target doesn't have to be '_blank'.
    – GSto
    Feb 26, 2010 at 18:40
  • 4
    It's worth noting that this is a valid HTML5.
    – AeroCross
    Mar 6, 2013 at 13:41
  • What do you mean by 'name'?
    – Vnge
    Jul 24, 2013 at 22:34
9

use target="_blank"

<a target='_blank' href="http://www.starfall.com/">Starfall</a>

0
8

You should be able to add

target="_blank"

like

<a href="http://www.starfall.com/" target="_blank">Starfall</a>
7

The target attribute is your best way of doing this.

<a href="http://www.starfall.com" target="_blank">

will open it in a new tab or window. As for which, it depends on the users settings.

<a href="http://www.starfall.com" target="_self">

is default. It makes the page open in the same tab (or iframe, if that's what you're dealing with).
The next two are only good if you're dealing with an iframe.

<a href="http://www.starfall.com" target="_parent">

will open the link in the iframe that the iframe that had the link was in.

<a href="http://www.starfall.com" target="_top">

will open the link in the tab, no matter how many iframes it has to go through.

1
  • how do i use that colored text in everyone elses examples?
    – hellol11
    Nov 9, 2015 at 18:51
6

the target = _blank is will open in new tab or windows based on browser setting.

To force a new window use javascript onclick all three parts are needed. url, a name, and window width and height size or it will just open in a new tab.

<a onclick="window.open('http://www.starfall.com/','name','width=600,height=400')">Starfall</a>
5

You can also accomplish this by adding the following to your page's header:

<base target="_blank">

This will make ALL links on your page open in a new tab

5

Since web is evolving quickly, some things changes with time. For security issues, you might want to use the rel="noopener" attribute in conjuncture with your target="_blank".

Like stated in Google Dev Documentation, the other page can access your window object with the window.opener property. Your external link should looks like this now:

<a href="http://www.starfall.com/" target="_blank" rel="noopener">Starfall</a>
1
  • <a href="http://www.starfall.com/" target="_blank" rel="noopener noreferrer">Starfall</a> these days it seem to be best practice to have both
    – ContextCue
    Aug 21, 2020 at 18:15
1

below example with target="_blank" works for Safari and Mozilla

<a href="http://www.starfall.com" `target="_blank"`>

Using target="new"worked for Chrome

<a href="http://www.starfall.com" `target="new"`>
1
  • 2
    what distinguishes your answer among dozen of others?
    – Farside
    Apr 19, 2016 at 22:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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