HTMLBaseElement: href property - Web APIs | MDN

Value

A string that contains a URL, or the empty string ("") if the corresponding <base> element does not include the href attribute.

Examples

HTML with base URL

This example demonstrates that the href attribute in <base> is reflected in the href property of HTMLBaseElement.

const logElement = document.querySelector("#log");
function log(text) {
  logElement.innerText = text;
}

HTML

html

<base href="https://developer.mozilla.org/example" />

JavaScript

js

const base = document.getElementsByTagName("base")[0];
log(`base.href="${base.href}"`);

Result

Specifications

Specification
HTML
# dom-base-href

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.