Skip to content
Related Articles
Open in App
Not now

Related Articles

How to open a hyperlink in another window or tab in HTML ?

Improve Article
Save Article
  • Last Updated : 13 Jun, 2022
Improve Article
Save Article

There are various methods of opening a hyperlink in another window or tab such as using javaScript, jQuery or HTML. For opening a hyperlink in another tab using HTML, use the target attribute and provide it value _blank in the anchor tab.

Syntax: 
 

<a target="target_name" rel="relation_name" href="link">Link Name</a>

Here, the rel attribute is used to describe the relation between the current document and the linked document and the target attribute is used to specify the target link.

Example 1: This example opens a hyperlink in a new window or tab. 

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>
        Open hyperlink in a
        new tab
    </title>
</head>
 
<body>
     
     
<p>A computer science portal for geeks
        <a target="_blank"
            href="https://www.geeksforgeeks.org/">
            GeeksforGeeks
        </a>
    </p>
 
 
</body>
 
</html>

Output: 

 

Explanation: Here, target=”_blank” is used to open a hyperlink in a new tab.

Example 2: Opening a hyperlink in a new window or tab using a security measure. 

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>
        Open hyperlink in a
        new tab
    </title>
</head>
 
<body>
     
     
<p>A computer science portal for geeks
        <a target="_blank" rel="noopener noreferrer"
            href="https://www.geeksforgeeks.org/">
            GeeksforGeeks
        </a>
    </p>
 
 
</body>
 
</html>

Output: 

 

Explanation: Here, rel=”noopener noreferrer” is used as a security measure.

Example 3: Opening an image hyperlink in a new tab. 

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>
        Open hyperlink in a
        new tab
    </title>
</head>
 
<body>
     
     
<p>
          A computer science portal for geeks
    </p>
 
   
      <a target="_blank" rel="noopener noreferrer"
       href="https://www.geeksforgeeks.org/">
                 
             alt="" class="aligncenter" />
      </a>
 
</body>
 
</html>

Output:

 

HTML is the foundation of web pages and is used for webpage development by structuring websites and web apps. You can learn HTML from the ground up by following this HTML Tutorial and HTML Examples.

JavaScript is best known for web page development but it is also used in a variety of non-browser environments. You can learn JavaScript from the ground up by following this JavaScript Tutorial and JavaScript Examples.


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!