The
<base>tag specifies the base URL and/or target for all relative URLs in a document.
It defines a reference point so that links and resources (like images, CSS, or JavaScript files) without absolute URLs are resolved relative to the<base>URL.You can only use one
<base>tag inside a document, and it must appear inside the<head>element before any other relative URL.
Syntax
<base href="https://example.com/" target="_blank">- href: Specifies the base URL for all relative links in the document.
- target: Defines the default target for all hyperlinks (e.g.,
_blank,_self,_parent,_top).
Example
<!DOCTYPE html>
<html>
<head>
<title>Base Tag Example</title>
<base href="https://html5andcss3.org/" target="_blank">
</head>
<body>
<a href="learn-html/">Learn HTML</a>
<img src="wp-content/uploads/2025/10/chrome.webp" alt="Chrome Logo" width="80">
</body>
</html>
Output
Browser Output
<base> tag has no any visible output
Browser Support
Chrome | Firefox | Edge | Safari | Opera | IE9+ |
|---|---|---|---|---|---|
| ✅Yes | ✅Yes | ✅Yes | ✅Yes | ✅Yes | ✅Yes |
All major browser supports the <base> tag.
Notes
- The
<base>tag must be placed inside the<head>section. - Only one
<base>tag is allowed per document. - If both
hrefandtargetattributes are used, they affect all relative URLs and hyperlinks in the page. - To override the default target for specific links, use the
targetattribute directly on the<a>tag. - Improper use may cause resource links to break if relative URLs are incorrectly resolved.
Conclusion
The <base> tag helps maintain consistent and predictable link behavior across a website by defining a single reference point for all relative URLs. It simplifies development when multiple relative resources share a common base path.