Base href attribute

Definition and usage

href Sets or returns the value of the href attribute of the base element.

The href attribute of the <base> element Specify the base URL for all relative URLs on the page.

By default, the base URL is the location of the current document, but it can be overridden by this attribute.

See also:

HTML Reference Manual:HTML <base> Tag

Example

Example 1

Return the base URL for all relative URLs on the page:

var x = document.getElementById("myBase").href;

Try it yourself

Example 2

Change the value of the base URL:

document.getElementById("myBase").href = "https://www.codew3c.com/html/";

Try it yourself

Syntax

Return the href attribute:

baseObject.href

Set the href attribute:

baseObject.href = URL

Attribute Value

Value Description
URL Specifies the base URL.

Technical Details

Return Value: A string value that represents the base URL for all relative URLs on the page, including the protocol (such as http://).

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support

Related Pages

HTML Reference Manual:HTML <base> href Attribute