HTML target Attribute

The target attribute of the <a> element is used to set where the linked document will open. You can set the document to open in a new window, same frame, parent frame, etc.

Following is the syntax −

<a target="_blank|_self|_parent|_top| frame">

Here, _blank is used to open the linked document in new window or tab, _self opens the linked document in the same frame as it was clicked, _parent opens the document in the parent frame, _top opens the linked document in the entire body of the window, frame opens the linked document in a named frame.

Let us now see an example to implement target attribute in <a> element −


 Live Demo

<!DOCTYPE html>
<h2>Learning is Fun</h2>
   <p><strong>Note −</strong> The links will open in new window.</p>
   <p><a href="https −//" target="_blank">Tutorials Library</a><br>
   <a href="https −//" target="_blank">Codes</a><br>
   <a href="https −//" target="_blank">Computer Glossary</a>

This will produce the following output. The below links will open in new window −

In the above example, we have set the target in the target attribute −

<a href="https −//" target="_blank"> Tutorials Library </a>

The attribute set above has value _blank, which opens the link in the href attribute in a new window −


Updated on: 30-Jul-2019


Kickstart Your Career

Get certified by completing the course

Get Started