HTML <base> target Attribute


The target attribute of the <base> element is used to set the default target for the hyperlinks in a document.

Syntax

Following is the syntax −

<base 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.

Example

Let us now see an example to implement the target attribute of the element −

<!DOCTYPE html>
<html>
   <head>
      <base href="https://www.example.com/tutorials/" target="_blank">
   </head>
   <body>
      <h2>Tutorials List</h2>
      <p><a href="https://www.tutorialspoint.com/java/index.htm">Java Tutorial</a></p>
      <p>(This will act as https://www.tutorialspoint.com/java/index.htm)</p>
      <p><a href="https://www.tutorialspoint.com/jquery/index.htm">jQuery Tutorial</a></p>
      <p>(This will act as https://www.tutorialspoint.com/jquery/index.htm)</p>
      <p><a href="https://www.tutorialspoint.com/blockchain/index.htm">Blockchain Tutorial</a></p>
      <p>(This will act as https://www.tutorialspoint.com/blockchain/index.htm)</p>
      <p><a href="https://www.tutorialspoint.com/python/index.htm">Python Tutorial</a></p>
      <p>(This will act as https://www.tutorialspoint.com/python/index.htm)</p>
   </body>
</html>

This will produce the following output. When you will click on any of the below link, it will open in a new window since it is set _blank −

Above, we have set the base URL −

<base href="https://www.tutorialspoint.com/tutorialslibrary.htm" target="_blank">

All the URLs will now open in anew window since we have set the target attribute for <base> element as −

target="_blank"

Updated on: 29-Feb-2024

309 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements