The <base>
tag specifies a base URL or default target for all relative URLs in a webpage. It is placed inside the <head>
section and affects how browsers resolve links, images, scripts, and form actions.
✅ Syntax
<base href="https://example.com/" target="_blank">
href
sets the base URL for all relative links on the page.target
sets the default target for links (e.g.,_blank
,_self
,_parent
,_top
).
📌 Only one <base>
tag is allowed per document.
🖼 Example
<!DOCTYPE html>
<html>
<head>
<base href="https://example.com/">
</head>
<body>
<a href="about.html">About Us</a>
</body>
</html>
🔍 What happens?
The link will go to https://example.com/about.html
, even though only "about.html"
was written.
🎯 Practical Uses
- Set a common domain for all relative paths (useful in templates or large projects).
- Open all links in new tabs/windows by setting
target="_blank"
once. - Useful in documentation sites, SPAs, or when content is embedded.
⚠️ Important Notes
- Only one
<base>
tag is allowed. - It must come before any links that use relative URLs, otherwise those links won’t work as intended.
- Can cause confusion if used incorrectly — use it carefully.
Want to see a live demo with a base URL and multiple links? I can generate an example page for you!