Base href attribute
Definition and usage
href
Sets or returns the value of the href attribute of the base element.
Base href attribute 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 property.
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;
Example 2
Change the value of the base URL:
document.getElementById("myBase").href = "https://www.codew3c.com/html/";
Syntax
Return href property:
baseObject.href
Set href property:
baseObject.href = URL
Attribute value
Value | Description |
---|---|
URL | Specify 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