DEV Community

Cover image for How to open a link in a new tab using HTML?
MELVIN GEORGE
MELVIN GEORGE

Posted on • Originally published at melvingeorge.me

How to open a link in a new tab using HTML?

Originally posted here!

To open a link in a new tab you can use the target attribute on an anchor tag and set its value to __blank.

For example, consider an anchor tag like this,

<a href="https://google.com">Google</a>
Enter fullscreen mode Exit fullscreen mode

Currently, if you click on this anchor tag it will open on the same page itself, which is the normal behavior of an anchor tag.

Now let's add the target="__blank" attribute to this anchor tag so that it will open the link in a new tab when the user clicks on it.

<a href="https://google.com" target="__blank">Google</a>
Enter fullscreen mode Exit fullscreen mode

That's it 🌟.

See this example live in JSBin.

Feel free to share if you found this useful 😃.


Top comments (0)