The HTML <base> tag
The HTML <base> element sets a base URL (href) and/or a default target for all relative URLs in the document. It is a void element, goes in the <head>, and there can be only one per page.
Overview
The <base> element changes how relative URLs resolve across the whole page. With <base href="/app/">, a link to page.html resolves against /app/ rather than the current location. It can also set a default target for all of the page's links.
It comes with strict rules and a sharp edge. Only one <base> is allowed, it must appear in the <head> before any element that uses a URL, and it affects in-page fragment links too — so a simple <a href="#section"> may unexpectedly point at the base URL plus the fragment.
Because of that surprising reach, use it sparingly. Many projects avoid it entirely and write root-relative URLs instead, which are explicit and have no side effects.
Syntax
<base href="https://example.com/app/" target="_blank">
Attributes
The <base> element supports the following attributes, in addition to the global attributes available to every HTML element.
Example
<base href="https://example.com/" target="_blank">
Best practices
- Include at most one
<base>, in the <head> before any URL-using element. - Be aware it affects in-page fragment links, which can be surprising.
- Use it sparingly — root-relative URLs are often clearer and side-effect-free.
- Use its
targetattribute to set a default link target if needed.
Frequently asked questions
What is the base element for?
How does base affect relative URLs?
href of the <base> instead of the document's own location.Can a page have more than one base element?
<base> is allowed, and it must come before any element that uses a URL.