HTML DOM

HTML DOM baseURI Property

The baseURI property returns the absolute base URI of the document. The browser uses the base URI to resolve any relative URLs (such as links and images) on the page.


Definition and Usage

document.baseURI is a read-only property that returns the absolute base URL of the document as a string. By default it equals the document's own URL, but it changes if the page includes a <base href="..."> element in the <head>.

Syntax

document.baseURI

It takes no arguments and returns a string containing the absolute base URI.

Example

// Show the base URI used to resolve relative links
console.log(document.baseURI);
// e.g. "https://www.example.com/learn-html/dom"

If the document contains <base href="https://cdn.example.com/">, then baseURI returns that value instead, and a relative link like <a href="page.html"> resolves against the base URL rather than the page URL.

ℹ️

Every node also has a baseURI property (Node.baseURI), so you can read it from any element, not just document.

Ready to use your HTML skills?

Find web development internships and fresher jobs across India.

Browse Web Dev Internships