- Home
- /
- Tutorials
- /
- HTML Tutorial
- /
- HTML <base> Tag
HTML Tags
HTML <base> Tag
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.
Syntax
html
<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
html
<!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="https://ik.imagekit.io/html5andcss3/browser-icons/chrome.webp" alt="Chrome Logo" width="80">
</body>
</html>Output
Browser Output
html
<base> tag has no any visible outputBrowser Support
Chrome | Edge | Firefox | 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 href and target attributes are used, they affect all relative URLs and hyperlinks in the page.
- To override the default target for specific links, use the target attribute 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.
