Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML HTML Links Anchors

Daniel Scalia
Daniel Scalia
8,545 Points

How do you generate a hyperlink that browser opens another window, so visitors doesn't necessarily leaves your site?

Sometimes I want a hyperlink from one page to another page on my site. Sometimes, I want the hyperlink to open up another window that leads visitor to another site. How can you control whether the hyperlink opens a new window or uses the same window?

3 Answers

Mikkel Rasmussen
Mikkel Rasmussen
31,772 Points
          <a href="#" target="_blank">Link</a>

You can read more about target here link

Daniel Scalia
Daniel Scalia
8,545 Points

Thanks a bunch! Very helpful.

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Hi Daniel,

You can use a target attribute in each anchor element to achieve this.

To make the browser open a new tab you do something like this.

<a href="#" target="blank">Link text</a>

Good luck :)

Daniel Scalia
Daniel Scalia
8,545 Points

Thanks a bunch! Very helpful.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

Having tested in Chrome Dev tools, it worked without adding the preceding _ underscore. :-)

Immanuel Jaeggi
Immanuel Jaeggi
5,164 Points

As a matter of practice, you should always write the attribute like so:

target="_blank"

Some people may have older browsers that may not recognize this piece of code. Better to begin learning the correct way and then make allowances for shortcuts when you are confident of the results.

You'll need to use target="_blank"

it is the _blank that opens up a new window. example.

<a href="teamtreehouse.com" target="_blank">Learn how to code</a>