Skip to content
Related Articles

Related Articles

How to open a hyperlink in another window or tab in HTML ?
  • Last Updated : 22 Apr, 2020

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 window or tab using HTML, use 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, rel attribute is used to describe the relation between current document and linked document and target attribute is used to specify the target link.

Example 1: This eample opening a hyperlink in a new window or tab.




<!DOCTYPE html>
<html>
  
<head>
    <title>
        Open hyperlink in a
        new window or 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 hyperlink in a new window or tab.

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




<!DOCTYPE html>
<html>
  
<head>
    <title>
        Open hyperlink in a
        new window or 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 window or tab.




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


Output:

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :