The target attribute of the <base> element is used to set the default target for the hyperlinks in a document.
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.
Let us now see an example to implement the target attribute of the <base> element −
Example
<!DOCTYPE html> <html> <head> <base href="https://www.example.com/tutorials/" target="_blank"> </head> <body> <h2>Tutorials List</h2>Java Tutorial
(This will act as https://www.example.com/tutorials/java.html)
jQuery Tutorial
(This will act as https://www.example.com/tutorials/jquery.html)
Blockchain Tutorial
(This will act as https://www.example.com/tutorials/blockchain.html)
Python Tutorial
(This will act as https://www.example.com/tutorials/python.html)
</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.example.com/tutorials/" target="_blank">
All the URLs will now open in anew window since we have set the target attribute for <base> element as −
target="_blank"