files/en-us/web/api/htmlbaseelement/href/index.md
{{APIRef("HTML DOM")}}
The href property of the {{domxref("HTMLBaseElement")}} interface contains a string that is the URL to use as the base for relative URLs.
It reflects the href attribute of the {{HTMLElement("base")}} element.
A string that contains a URL, or the empty string ("") if the corresponding <base> element does not include the href attribute.
This example demonstrates that the href attribute in <base> is reflected in the href property of HTMLBaseElement.
<pre id="log"></pre>
const logElement = document.querySelector("#log");
function log(text) {
logElement.innerText = text;
}
#log {
height: 20px;
}
<base href="https://developer.mozilla.org/example" />
const base = document.getElementsByTagName("base")[0];
log(`base.href="${base.href}"`);
{{EmbedLiveSample('HTML with base URL', '100','50px')}}
{{Specifications}}
{{Compat}}