How To Set HTML Link Target?

HTML provides the <a> tag in order to create links in different types. The <a> tag provides the href attribute in order to set link target. The link target can an HTTP link, FTP file, Local file, or a new browser tab. In this tutorial we examine different link types for the HTML <a> link tag.

Open Link In A New Window or Tab

When a user navigates an HTML page it may click on the link. By default clicking a link opens the link target in the same tab or window where the user automatically leaves the current page. This is generally an unwanted case. We can open a new window or tab. In the following example, we open the WiseTut in a new tab without leaving the current page. We provide the target="_blank" .

<html>
<body>

<h1>The a target attribute</h1>

<p>Open link in a new window or tab: <a href="https://wisetut.com" target="_blank">Visit WiseTut!</a></p>

</body>
</html>

Open Link In The Same Window or Tab

We can use the target="_self" in order to open a specified link in the current window or tab. This means the user leaves the current page.

<html>
<body>

<h1>The a target attribute</h1>

<p>Open link in a new window or tab: <a href="https://wisetut.com" target="_self">Visit WiseTut!</a></p>

</body>
</html>

Open Link In Parent Window or Tab

A link can be located inside an iframe or similar container. We can open the link in the parent window or tab using the target="_parent" .

<html>
<body>

<h1>The a target attribute</h1>

<p>Open link in a new window or tab: <a href="https://www.w3schools.com" target="_parent">Visit W3Schools!</a></p>

</body>
</html>

Open Link In Specified Frame

We can also open the specified in the specified frame or iframe. The frame name is provided to the target attribute. In the following example, we open the link in the frame named “myframe”. We use the target="myframe" attribute in the link.

<html>
<body>

<h1>The a target attribute</h1>

<p>Open link in a new window or tab: <a href="https://www.w3schools.com" target="myframe">Visit W3Schools!</a></p>

</body>
</html>

Leave a Comment