THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Base href Property

Base Object Reference Base Object

Example

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

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

The result of x will be:

http://www.w3schools.com/jsref/
Try it yourself »

Definition and Usage

The href property sets or returns the value of the href attribute in a base element.

The href attribute specifies a base URL for all relative URLs on a page.

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


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The href property is supported in all major browsers.


Syntax

Return the href property:

baseObject.href

Set the href property:

baseObject.href=URL

Property Values

Value Description
URL Specifies the base URL

Technical Details

Return Value: A String, representing the base URL for all relative URLS on a page, including the protocol (like http://)

More Examples

Example

Change the value of the base URL:

document.getElementById("myBase").href = "http://www.w3schools.com/html/";
Try it yourself »

Related Pages

HTML reference: HTML <base> href attribute


Base Object Reference Base Object