<base>: The Document Base URL element

You’re reading the English version of this content since no translation exists yet for this locale. Help us translate this article!

The HTML <base> element specifies the base URL to use for all relative URLs in a document. There can be only one <base> element in a document.

The used base URL of a document can be accessed from scripts with document.baseURI. If the document contains no <base> elements, baseURI defaults to document.location.href.

Content categories Metadata content.
Permitted content None, it is an empty element.
Tag omission There must be no closing tag.
Permitted parents Any <head> that doesn't contain any other <base> element
Permitted ARIA roles None
DOM interface HTMLBaseElement

Attributes

This element's attributes include the global attributes.

If either of the following attributes are specified, this element must come before other elements with attributes whose values are URLs, such as <link>’s href attribute.

href
The base URL to be used throughout the document for relative URLs. Absolute and relative URLs are allowed.
target
A keyword or author-defined name of the default browsing context to display the result when links or forms cause navigation, for <a> or <form> elements without an explicit target attribute. The attribute value targets a browsing context (such as a tab, window, or <iframe>).
The following keywords have special meanings:
  • _self: Load the result into the same browsing context as the current one. (This is the default.)
  • _blank: Load the result into a new, unnamed browsing context.
  • _parent: Load the result into the parent browsing context of the current one. (If the current page is inside a frame.) If there is no parent, behaves the same way as _self.
  • _top: Load the result into the topmost browsing context (that is, the browsing context that is an ancestor of the current one, and has no parent). If there is no parent, behaves the same way as _self.

Usage notes

Multiple <base> elements

If multiple <base> elements are used, only the first href and first target are obeyed — all others are ignored.

In-page anchors

Links pointing to a fragment in the document — e.g. <a href="#some-id"> — are resolved with the <base>, triggering an HTTP request to the base URL with the fragment attached.

For example, given <base href="https://example.com">

...and this link: <a href="#anchor">Anker</a>

...the link points to https://example.com/#anchor.

Open Graph

Open Graph tags do not acknowledge <base>, and should always have full absolute URLs. For example:

<meta property="og:image" content="https://example.com/thumbnail.jpg">

Examples

<base href="https://www.example.com/">
<base target="_blank"> 
<base target="_top" href="https://example.com/">  

Specifications

Specification Status Comment
HTML Living Standard
The definition of '<base>' in that specification.
Living Standard No change since last snapshot.
HTML5
The definition of '<base>' in that specification.
Recommendation Specified the behavior of target
HTML 4.01 Specification
The definition of '<base>' in that specification.
Recommendation Added the target attribute

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
baseChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support Yes
Notes
Full support Yes
Notes
Notes Before Internet Explorer 7, <base> can be positioned anywhere in the document and the nearest value of <base> is used.
Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
hrefChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
targetChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support
See implementation notes.
See implementation notes.