The HTML <base>
element specifies the base URL to use for all
relative URLs contained within a document. There can be only one
<base>
element in a document.
The base URL of a document can be queried from a script using
document.baseURI
.
Attributes
This element supports the global attributes as well as the following element-specific attributes:
href
: URLThe base URL to be used throughout the document for relative URL addresses. If this attribute is specified, this element must come before any other elements with attributes whose values are URLs. Absolute and relative URLs are allowed.
target
: StringA name or keyword indicating the default location to display the result when hyperlinks or forms cause navigation, for elements that do not have an explicit target reference. It is a name of, or keyword for, a browsing context (for example: tab, window, or inline frame). The following keywords have special meanings:
-
_self
: Load the result into the same browsing context as the current one. This value is the default if the attribute is not specified. -
_blank
: Load the result into a new unnamed browsing context. -
_parent
: Load the result into the parent browsing context of the current one. If there is no parent, this option behaves the same way as_self
. -
_top
: Load the result into the top-level browsing context (that is, the browsing context that is an ancestor of the current one, and has no parent). If there is no parent, this option behaves the same way as_self
.
If this attribute is specified, this element must come before any other elements with attributes whose values are URLs.
-
Usage notes
If multiple <base>
elements are specified, only the first href
and
first target
value are used; all others are ignored.
Examples
This example shows two uses of the <base>
element, one of which also uses the target
attribute.
HTML
<base href="http://www.example.com/page.html">
<base target="_blank" href="http://www.example.com/page.html">
Desktop | Mobile | |||
---|---|---|---|---|
Chrome | Edge | Chrome | Edge | |
video | 3 | Yes | ? | No |
mfuji09, LucasLombardo, jonhickman, Sheppy, jacob-israel-turner, fscholz, snuggs, teoli, noformnocontent, marymar, MJCD, sideshowbarker, erikadoyle, aeinbu, Legioinvicta, Nyansu, shmulim, Tigt, renoirb, sotos, kynikos, Velmurugan, jpmedley, cgatesman, Jeremie, SpyMaster356, sureshronaldo, kscarfone, rodneyrehm, justleroy, tregagnon, Nickolay, medicdude, trevorh, ethertank, lazd, Marsf, cers, Jürgen Jeka, McGurk, hobophobe, jswisher, Ptak82, ZmyO5v, Mgjbot, PablO, Victory