Home 〉 HTML Tutorials 〉 HTML '<base>' Tag - Complete Guide with Syntax, Attributes, and Examples
HTML '<base>' Tag - Complete Guide with Syntax, Attributes, and Examples !
Do you want to manage all your page URLs more efficiently with just one tag?
Then understanding and using the HTML '<base>' tag is the key! This tutorial explains what the base tag does, its syntax, attributes like 'href' and 'target', and how they affect your web page. You've also seen real-world examples and how to style relevant elements for better design. The detailed blog post on HTML base tag is as follows.
The HTML '<base>' tag is used to define a base URL and/or target for all relative URLs in a document. It helps web browsers understand how to resolve links and media paths consistently from a single base address.
When working on large websites, the '<base>' tag can reduce redundancy and make relative URLs easier to manage.
Syntax ✍
<base href="https://www.example.com/" target="_blank">
Important: Only one '<base>' tag is allowed per document. If multiple are used, only the first one is considered.
The '<base>' tag is an empty element — it does not have any closing tag or inner content. It is also a metadata element and is used only in the '<head>' section.
The following are the attributes of HTML base tag:
Example 📄
<base href="https://www.mywebsite.com/">
<a href="about.html">About Us</a>
The 'href' attribute sets the base path. So, the anchor link points to 'https://www.mywebsite.com/about.html' instead of just 'about.html'.
Example 📄
<base target="_blank">
<a href="https://example.com">Visit</a>
All links will now open in a new tab because the base 'target' is set to '_blank'.
Although '<base>' doesn't render content on the page, here's a sample context to help visualize inline styling in a related element:
<!DOCTYPE html>
<html>
<body>
<a href="contact.html" style="color: blue; font-size: 16px; text-align: center; padding: 10px; border: 1px solid #ccc; border-radius: 5px;">
Contact Us
</a>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
The '<base>' tag is a powerful but often overlooked HTML element. It simplifies URL management and improves the consistency of resource linking across large websites. While it doesn't display anything on the page, it plays a crucial behind-the-scenes role in defining document behavior.
Use it correctly in the '<head>' section and ensure only one '<base>' tag per page.
No, only the first '<base>' tag is used. Others are ignored.
It should be placed inside the '<head>' tag.
Yes, it affects all relative URLs in the HTML document, including JS and CSS.
All relative URLs will resolve incorrectly, potentially breaking links and resources.