HTML <base> Tag

In this article, we will cover HTML Tag <base> ,with the aim that it would serve the learning requirements.

The HTML <base> tag is used to specify the base URL for all relative URLs on a webpage. When a browser encounters a relative URL on a webpage, it uses the base URL specified in the <base> tag to construct the complete URL. The <base> tag must be placed in the head section of an HTML document and should only be used once.

Create a default URL and target for every link on the page:

Example: 

<!DOCTYPE html> <html> <head> <base href="https://mrexamples.com/" target="_blank"> </head> <body> <img src="https://mrexamples.com/wp-content/uploads/2023/03/Animated-Gif-Images-Download.gif" width="48" height="78" alt="Smiling Face"> <a href="tags/tag-base/">HTML base Tag</a> </body> </html>

Here is another example of the <base> tag with target attribute:

Example: 

<!DOCTYPE html> <html> <head> <base href="https://mrexamples.com/" target="_self"> <title>My page</title> </head> <body> <a href="tags/tag-base/">HTML base Tag</a> </body> </html>


Uses and Definition

This Tag Base <base> indicates the URL of the document’s base or target for all associated URLs.

At least one or both of the following attributes must be present in the <base> tag: href and target.

In a document, the base element must only exist within the head element.


Browser Compatibility

Element
<base>YesYesYesYesYes

Global Attributes and Events

HTML’s Tag Base <base> accepts Global Attributes as well.


Event Attributes

It doesn’t accept any event attributes in Tag Base <base>.


Attributes

AttributeValueOverview
hrefURLThe base URL determines all relative URLs on the page
target_blank
_parent
_self
_top
Across all hyperlinks and forms on the page, indicate the default target

HTML Base Tag Benefits

The HTML <base> tag provides several benefits. Such as:

  1. The <base> tag makes it easy to manage the URLs of a webpage by allowing you to specify a common base URL for all relative URLs. This simplifies the construction of URLs on the webpage, making it easier to maintain links if the base URL changes in the future.
  2. The <base> tag can improve the performance of a webpage by reducing the amount of data that needs to be transmitted to the browser. By specifying a common base URL, the browser can cache the base URL and use it to construct all relative URLs, which reduces the amount of data that needs to be transmitted.
  3. The <base> tag ensures that all relative URLs on the webpage are constructed correctly, regardless of the location of the webpage or the user’s browser settings. This helps to avoid broken links and improves the user experience of the webpage.
  4. The <base> tag provides you with the flexibility to change the base URL of a webpage without having to update all the relative URLs on the webpage. This can be useful if the webpage is moved to a different server or domain, or if the URL structure of the webpage needs to be changed.

Share your opinion about this site by leaving a reaction below.
We value your feedback.
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0

Subscribe To Our Newsletter
Enter your email to receive a weekly round-up of our best posts. Learn more!
icon

Leave a Reply

Your email address will not be published. Required fields are marked *