The Node.baseURI property returns the absolute base URL of the document containing a node. Browsers use that base to resolve relative URLs. Learn the default (document location), how <base href> overrides it, and how to build absolute URLs with new URL()—with five examples and try-it labs.
01
Kind
Read-only property
02
Returns
Absolute URL string
03
Status
Baseline widely
04
Default
Document location
05
Override
<base href>
06
Use with
new URL()
Fundamentals
Introduction
Every HTML page lives at a URL. Relative paths like images/logo.png or ../styles.css only make sense when the browser knows a base URL. node.baseURI exposes that absolute base for the document that owns the node.
Elements such as <img src>, <a href>, and SVG href / xlink:href rely on the same idea. Reading baseURI helps you debug link resolution and build absolute URLs in JavaScript.
💡
Beginner tip
Document inherits from Node, so document.baseURI works too. For any element on the page, el.baseURI is usually the same string.
Concept
Understanding baseURI
MDN: the read-only baseURI property of the Node interface returns the absolute base URL of the document containing the node. The value is computed each time you access the property, so it can change if conditions change.
Default — the document location (related to window.location / the document URL).
HTML override — if an HTML document has a <base href="…">, that first matching href is used instead.
Read-only — you cannot assign node.baseURI = "…".
Purpose — resolve relative URLs to absolute ones in the browser and in your scripts.
Foundation
📝 Syntax
JavaScript
const absoluteBase = node.baseURI;
Return value
A string representing the absolute base URL of the node’s document.
Cheat Sheet
⚡ Quick Reference
Topic
Detail
Interface
Node (also document.baseURI)
Type
Read-only string (absolute URL)
Default base
Document location / URL
HTML override
First <base href> in the document
Resolve a relative path
new URL(rel, node.baseURI).href
MDN status
Baseline Widely available (since July 2015)
Snapshot
🔍 At a Glance
Four facts to remember about Node.baseURI.
Returns
string
Absolute URL
Baseline
widely
Since July 2015
Access
read-only
Computed on read
Override
<base>
HTML href wins
Hands-On
Examples Gallery
Examples follow MDN Node.baseURI patterns. Use View Output or Try It Yourself for each case.
📚 Getting Started
Read the base URL with and without a <base> element.
Example 1 — Default baseURI (No <base>)
MDN-style: print an element’s base URL when the document has no base tag.
JavaScript
const output = document.querySelector("output");
output.value = output.baseURI;
// Absolute URL of this document (page location)
baseURI is defined on Node. Both the document and its elements report the containing document’s base URL.
Example 4 — Resolve a Relative URL with new URL()
Turn a relative path into an absolute URL using the node’s base.
JavaScript
const el = document.querySelector("main");
const absolute = new URL("images/photo.jpg", el.baseURI).href;
console.log(absolute);
// e.g. "https://www.example.com/path/images/photo.jpg"
// (depends on el.baseURI)
https://www.example.com/.../images/photo.jpg
(joined from baseURI + relative path)
How It Works
The second argument to new URL() is the base. Passing el.baseURI matches how the browser resolves relative assets on that page.
Example 5 — Read-Only (Assignment Fails)
Confirm you cannot write to baseURI; change the base with HTML instead.
JavaScript
const el = document.documentElement;
try {
el.baseURI = "https://example.com/hacked/";
} catch (err) {
console.log("Assignment rejected:", err.name);
}
console.log("Still:", el.baseURI);
// To change the base, use a <base href> in the document (or navigate).
Node.baseURI is Baseline Widely available across modern browsers (MDN: since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
Node.baseURI
Safe for production. Read the absolute document base URL, respect any
, and resolve relative paths with new URL().
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium & Legacy
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerSupported in modern legacy IE (IE9+ era)
Full support
baseURIExcellent
Bottom line: Use node.baseURI (or document.baseURI) whenever you need the absolute base the browser uses for relative URLs.
Wrap Up
Conclusion
Node.baseURI gives you the absolute base URL for a node’s document—by default the page location, or a <base href> when present. Read it to understand relative URL resolution, and pair it with new URL() when you need absolute links in script.
Place at most one intentional <base href> in <head>
Compare document.baseURI in support / debug panels
Remember the value is recomputed on each read
❌ Don’t
Assign to baseURI (it is read-only)
Concatenate paths with + when URL can join safely
Scatter multiple conflicting <base> tags
Assume a relative path is absolute without checking the base
Confuse this DOM Node with the Node.js runtime
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about baseURI
Absolute document base for every Node.
5
Core concepts
🌐01
Absolute base
string URL
API
📄02
Default
document URL
Default
🔗03
<base href>
can override
HTML
🔒04
Read-only
no assignment
Access
🔢05
new URL()
resolve rel
Pattern
❓ Frequently Asked Questions
It is a read-only string: the absolute base URL of the document that contains the node. The browser uses that base when turning relative URLs into absolute ones (for example img src or a href).
No. MDN marks Node.baseURI as Baseline Widely available (since July 2015). It is a standard DOM property — not Deprecated, Experimental, or Non-standard.
By default the base URL matches the document location. If the HTML document has a <base href="...">, the href of the first such base element is used instead when computing baseURI.
No. The property is read-only. Its value is computed each time you read it, so it can change if the document URL or <base> changes.
For nodes in the same document they normally match, because baseURI comes from the containing document’s base URL algorithm. Always read it on the node you care about when debugging.
Use the URL constructor: new URL("images/photo.jpg", node.baseURI).href. That returns an absolute URL using the node’s base.
Did you know?
baseURI is recomputed on every read. If a script injects or updates a <base href> (uncommon, but possible), later reads of node.baseURI can return a different string without you assigning to the property.