HTML provides the benefits of different tags in different ways. The important point is that developers need to choose the right HTML tag at the right time. In this tutorial, you will learn how HTML base tag works.
What Is HTML
<base> tag in HTML specifies the base URL for all relative URLs in an HTML document. It allows the developer to set a default URL that will be used to resolve any relative URLs that appear in the document.
The base tag should be placed in the head of the HTML document and only occur once per document.
Here is an example of how to use the base element in an HTML page:
In this example, the base element specifies that the base URL for the document is https://www.w3schools.in/. Any relative URLs in the document (e.g., /img/logo.png) will be resolved relative to this base URL (e.g., https://www.w3schools.in/img/logo.png).
<base> Tag Attributes
The HTML base tag has two attributes: href and target.
href: This attribute specifies the base URL for the document. Any relative URLs in the document will be resolved relative to this base URL.
target: This attribute specifies the default target for all links in the document. It can be used to control where linked documents will be displayed (e.g., in the current window, in a new window or tab, etc.).
Here is an example of how a base element can be used with both attributes in an HTML page:
<base href="https://www.w3schools.in/" target="_blank">
In this example, the base tag specifies that the base URL for the HTML document is https://www.w3schools.in/ and that all links in the document should open in a new window or tab when clicked.
It's worth noting that the base tag's target attribute is deprecated in HTML5, and its use is not recommended. Instead, it would be best if you used the element's target attribute to specify targets for individual links.