Path: blob/main/files/en-us/web/html/element/base/index.md
6520 views
------{{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")}}.
| Content categories | Metadata content. |
|---|---|
| Permitted content | None; it is a {{Glossary("void element")}}. |
| Tag omission | There must be no closing tag. |
| Permitted parents | A {{HTMLElement("head")}} that doesn't contain another {{HTMLElement("base")}} element. |
| Implicit ARIA role | No corresponding role |
| Permitted ARIA roles | No role permitted |
| DOM interface | {{domxref("HTMLBaseElement")}} |
Attributes
This element's attributes include the global attributes.
Warning: If either of the following attributes are specified, this element must come before other elements with attribute values of URLs, such as {{HTMLElement("link")}}'s
hrefattribute.
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 {{Glossary("browsing context")}} to show the results of navigation from {{HTMLElement("a")}}, {{HTMLElement("area")}}, or {{HTMLElement("form")}} elements without explicit
targetattributes. 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, given <base href="https://example.com/"> and this link: <a href="#anchor">To anchor</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:
Examples
Specifications
{{Specifications}}
Browser compatibility
{{Compat}}