Signup/Sign In

How to open link in new tab in HTML?

When we click on some links on a webpage, either the link will open on the same page or may it will open in the new tab.

HTML links open in the same tab by default. But we can change this behavior of link opening to a new tab using the HTML target attribute.

Target Attribute

The target attribute can be added to the <a> element to control how the new page open when clicked on the link.

The target attribute uses _blank value to open the link in the new tab. The target="_blank" changes the default behavior of links opening in the same tab.

Example: Default link opening

Here, we have not used the target attribute. We can see that the link opens on the same page.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>HTML</title>
  </head>
  <body>
    <h2>Open link by default</h2>
    <a href="https://www.studytonight.com/"> Visit page </a>
  </body>
</html>

Output

Here is the output of the above program. The link opens in the same window when clicked.

Default click

Example: Opening link in a new tab using the target attribute

Here is an example where we have used the target="_blank" attribute to open a link in a new tab.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>HTML</title>
  </head>
  <body>
    <h2>Open link in new tab</h2>
    <a href="https://www.studytonight.com/" target="_blank"> Visit page </a>
  </body>
</html>

Output

Here is the output of the above program.

out put

Conclusion

Opening links can make your task easy when you do not want to lose your previous page. It can be useful for multitasking. You can process your works in a new tab without leaving the current page.