docs.rodeo

MDN Web Docs mirror

: The Document Base URL element

{{HTMLSidebar}} 

The <base> HTML 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 {{domxref('Node.baseURI')}} . If the document has no <base> elements, then baseURI defaults to {{domxref("location.href")}} .

Attributes

This element’s attributes include the global attributes.

[!WARNING] A <base> element must have an href attribute, a target attribute, or both. If at least one of these attributes are specified, the <base> element must come before other elements with attribute values that are URLs, such as a {{HTMLElement("link")}} 's href attribute.

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">To anchor</a>. The link points to https://example.com/#anchor.

target may not contain ASCII newline, tab, or <

If the target attribute contains an ASCII newline, tab, or the < character, the value is reset to _blank. This is to prevent dangling markup injection attacks, a script-less attack in which an unclosed target attribute is injected into the page so that any text that follows is captured until the browser reaches a character that closes the attribute.

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/" />

Technical summary

Content categories Metadata content.
Permitted content None; it is a `{{Glossary("void element")}}` .
Tag omission Must have a start tag and must not have an end tag.
Permitted parents A `{{HTMLElement("head")}}`  that doesn't contain another <base> element.
Implicit ARIA role No corresponding role
Permitted ARIA roles No role permitted
DOM interface `{{domxref("HTMLBaseElement")}}` 

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

In this article

View on MDN