Web/HTML/Element/base

From Get docs


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.

A document's used base URL can be accessed by scripts with document.baseURI. If the document has no <base> elements, then baseURI defaults to location.href.

Content categories Metadata content.
Permitted content None, it is an empty element.
Tag omission There must be no closing tag.
Permitted parents A <head> that doesn't contain another <base> element.
Implicit ARIA role No corresponding role
Permitted ARIA roles No role permitted
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 attribute values of 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 show the results of navigation from <a>, <area>, or <form> elements without explicit target attributes.
The following keywords have special meanings:
_self (default)
  • Show the result in the current browsing context.
  • _blank: Show the result in a new, unnamed browsing context.
  • _parent: Show the result in the parent browsing context of the current one, if the current page is inside a frame. If there is no parent, acts the same as _self.
  • _top: Show the result in the topmost browsing context (the browsing context that is an ancestor of the current one and has no parent). If there is no parent, acts the same 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:

  1. Given <base href="https://example.com%22>
  2. ...and this link: <a href="#anchor">Anker</a>
  3. ...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 StandardThe definition of '<base>' in that specification. Living Standard No change since last snapshot.
HTML5The definition of '<base>' in that specification. Recommendation Specified the behavior of target
HTML 4.01 SpecificationThe definition of '<base>' in that specification. Recommendation Added the target attribute

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
base Chrome

Full support Yes

Edge

Full support 12

Firefox

Full support 1

IE 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 Yes

Safari

Full support Yes

WebView Android

Full support Yes

Chrome Android

Full support Yes

Firefox Android

Full support 4

Opera Android

Full support Yes

Safari iOS

Full support Yes

Samsung Internet Android

Full support Yes

href Chrome

Full support Yes

Edge

Full support 12

Firefox

Full support 1

IE

Full support Yes

Opera

Full support Yes

Safari

Full support Yes

WebView Android

Full support Yes

Chrome Android

Full support Yes

Firefox Android

Full support 4

Opera Android

Full support Yes

Safari iOS

Full support Yes

Samsung Internet Android

Full support Yes

target Chrome

Full support Yes

Edge

Full support 12

Firefox

Full support Yes

IE

Full support Yes

Opera

Full support Yes

Safari

Full support Yes

WebView Android

Full support Yes

Chrome Android

Full support Yes

Firefox Android

Full support Yes

Opera Android

Full support Yes

Safari iOS

Full support Yes

Samsung Internet Android

Full support Yes

Legend

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