HTML Tags
HTML <base> Tag
The <base> tag specifies a base URL and/or default target for all relative URLs in a document. It is a void element placed inside the <head>.
The <base> Tag
The <base> element sets a base URL against which all relative links, images, and other resources on the page are resolved. It can also set a default target for every link and form on the page.
There can be at most one <base> element per document, and it must appear inside <head> before any element that uses a URL. It is a void element, so it has no closing tag.
Syntax
<base href="https://example.com/" target="_blank" />Example
<!DOCTYPE html>
<html>
<head>
<base href="https://picsum.photos/" />
</head>
<body>
<h1>Base URL Demo</h1>
<img src="200" alt="Random image resolved against the base URL" />
<p>The relative src "200" resolves to https://picsum.photos/200.</p>
</body>
</html>More Examples
<!DOCTYPE html>
<html>
<head>
<base target="_blank" />
</head>
<body>
<p>
<a href="https://www.wikipedia.org/">This link opens in a new tab</a>
because of the default target set by base.
</p>
</body>
</html>Attributes
| Attribute | Description |
|---|---|
| href | The base URL used to resolve all relative URLs in the document. |
| target | The default browsing context for links and forms: _self, _blank, _parent, or _top. |
Use <base> with care. Because it affects every relative URL on the page, including anchors like #section, it can produce surprising behaviour. Most sites use full or root-relative URLs instead.
Key Takeaways
- <base> sets a base URL for all relative links and resources.
- It can set a default target for links and forms.
- At most one <base> is allowed, inside <head>.
- It is a void element with no closing tag.
- It must come before any URL-using element in the head.
