References

Beginner-friendly references for web development, with live, editable examples.

The HTML <base> tag

Element All modern browsers Updated
Quick answer

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.

Attribute Value Description
href A URL — absolute, relative, or a special scheme such as mailto:, tel: or a #fragment. Specifies the URL a hyperlink points to.
target _self (default) _blank _parent _top a named browsing context Specifies where to open a link or form result.

Example

Live 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 target attribute to set a default link target if needed.

Frequently asked questions

What is the base element for?
It sets the base URL against which all relative links on the page resolve, and an optional default link target.
How does base affect relative URLs?
Every relative URL on the page resolves against the href of the <base> instead of the document's own location.
Can a page have more than one base element?
No. Only one <base> is allowed, and it must come before any element that uses a URL.
Does base affect anchor links?
Yes — it affects in-page fragment links too, which can be surprising. This is a reason to use it sparingly.