Open In App

Which attribute is used to target the webpage to open into a new window in HTML ?

Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will learn how to open a webpage in a new window using the TARGET attribute of HTML.

The Target attribute of <a> anchor tag is used to specify the named frame or window the link will open. The <a> is paired tag, so both starting<a> tag must have closing</a> tag in the HTML document. Anchor tag has many attributes but href (hypertext reference) attribute is mandatory as it specifies the URL of the webpage the link will move to.

Syntax:

<a href="URL" target="_top"> Linked Text </a>

Attribute Values: This attribute refers to the target window for the URL mentioned with href attribute. It can take the following possible values:

  • _top: It loads the webpage into a browser window using full-body i.e. by replacing existing frames.
  • _self: By default, _self is the value for the target attribute. It loads the webpage in the same window/frame from which the link is clicked.
  • _blank: It loads the webpage in a new window of the browser.
  • _parent: It loads the webpage in the parent window/frameset.

If you want to load the contents of the webpage into another frame then the NAME attribute is to be specified within the <FRAME> element of HTML in which the contents of the linked page will be displayed. Also, there is a need to specify the target attribute of <a> element and the name of the frame in which contents will be shown.

Example1: The below example illustrate the use of  target=”_blank”. When a user clicks on the linked text the webpage will open up in the new window. 

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>TARGET ATTRIBUTE</title>
</head>
 
<body>
    <h2 style="color:green;">TARGET ATTRIBUTE</h2>
    <a href="https://www.geeksforgeeks.org/" target="_blank">
        Click here to visit Geeks website</a>
</body>
 
</html>


Output:


Last Updated : 17 Feb, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads