X
HOME HTML5 CSS3 JAVASCRIPT SQL PHP5 JQUERY ANGULAR BOOTSTRAP3 XML MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

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

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook