HTML target Attribute

HTML target Attribute: This attribute  specifies where to open the linked document when <a> and <area> elements are used.is applied to <a>,<area>,<base> and <form> elements.

HTML target Attribute

This attribute specifies the default target for all hyperlinks and forms in the page when the <base> element is used. When <form> element is used the target attribute specifies a name or a keyword that indicates where to display the response that is received after submitting the form.

Browser Support

This attribute is supported by the following browsers:

  • Chrome
  • Internet Explorer
  • Firefox
  • Safari
  • Opera

Example: for <a> element

<!DOCTYPE html>
<html>
<body>
 <a href="https://tutorials.freshersnow.com/" target="_blank">Visit Freshersnow Tutorial!!</a></p>
</body>
</html>

Output:

Open link in a new window or tab: Visit freshersnow!

Example: for <area> element

<!DOCTYPE html>
<html>
<body>
<img src="planets.gif" width="145" height="126" alt="Planets" usemap="#planetmap">
<map name="planetmap">
  <area shape="rect" coords="0,0,82,126" alt="Sun" href="sun.htm" target="_blank">
  <area shape="circle" coords="90,58,3" alt="Mercury" href="mercur.htm">
  <area shape="circle" coords="124,58,8" alt="Venus" href="venus.htm">
</map>
</body>
</html>

Output:

HTML target attribute

Example: for <base> element

<!DOCTYPE html>
<html>
<head>
  <base target="_blank">
</head>
<body>
<p><a href="https://tutorials.freshersnow.com/">freshersnow</a> </p>
</body>
</html>

Output:

freshersnow – Notice that the link opens in a new window, even if it has no target=”_blank” attribute. This is because the target attribute of the base element is set to “_blank”.

Example: for <form> element

<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php" method="get" target="_blank">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br>
  <input type="submit" value="Submit">
</form>
</body>
</html>

Output:

HTML target attribute