JavaScript Node baseURI Property

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Read-only

What You’ll Learn

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()

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.

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.

📝 Syntax

JavaScript
const absoluteBase = node.baseURI;

Return value

A string representing the absolute base URL of the node’s document.

⚡ Quick Reference

TopicDetail
InterfaceNode (also document.baseURI)
TypeRead-only string (absolute URL)
Default baseDocument location / URL
HTML overrideFirst <base href> in the document
Resolve a relative pathnew URL(rel, node.baseURI).href
MDN statusBaseline Widely available (since July 2015)

🔍 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

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)
Try It Yourself

How It Works

Without a <base> element, the document location is the base. Any node in that document reports that absolute URL via baseURI.

Example 2 — With <base href>

A <base> tag changes the computed base for the whole document.

JavaScript
<base href="https://developer.mozilla.org/modified_base_uri/" />
<output>Not calculated</output>
<script>
  const output = document.querySelector("output");
  output.value = output.baseURI;
  // "https://developer.mozilla.org/modified_base_uri/"
</script>
Try It Yourself

How It Works

For HTML documents, the href of the first <base> with that attribute replaces the default document location when computing baseURI.

📈 Document, Resolve & Read-Only

Compare nodes, build absolute URLs, and respect read-only access.

Example 3 — document.baseURI vs Element

Document and elements in the same page share the same document base.

JavaScript
const el = document.body;
console.log(document.baseURI === el.baseURI); // true (same document)
console.log(document.baseURI);
Try It Yourself

How It Works

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)
Try It Yourself

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).
Try It Yourself

How It Works

The IDL marks baseURI as read-only. The browser recomputes it from the document URL and any <base> on each access.

🚀 Common Use Cases

  • Debug relative links — print el.baseURI when assets load from the wrong folder.
  • Build absolute URLs in JSnew URL(path, node.baseURI) for fetch or sharing.
  • Respect site <base> — match the same base the HTML engine uses.
  • CMS / preview iframes — understand why relative paths resolve to a preview host.
  • SVG / mixed documents — confirm the base used for href resolution.

🧠 How baseURI Is Determined

1

Find the document

Start from the node’s containing document.

Document
2

Default = location

Use the document URL (page location) as the base.

Default
3

Check <base>

In HTML, the first <base href> can replace the default.

Override
4

Return absolute string

Your script reads a full URL string from node.baseURI.

📝 Notes

  • Baseline Widely available (MDN, since July 2015).
  • Not Deprecated, Experimental, or Non-standard — no status banner required.
  • Read-only; value may change when the document URL or <base> changes.
  • Only the first HTML <base href> matters for this algorithm.
  • Prefer new URL(rel, base) over string concatenation for joining paths.
  • Related learning: Window, EventTarget, JavaScript hub.

Universal Browser Support

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().

Universal Widely available
Google Chrome Full support · Desktop & Mobile
Full support
Mozilla Firefox Full support · Desktop & Mobile
Full support
Apple Safari Full support · macOS & iOS
Full support
Microsoft Edge Full support · Chromium & Legacy
Full support
Opera Full support · Modern versions
Full support
Internet Explorer Supported in modern legacy IE (IE9+ era)
Full support
baseURI Excellent

Bottom line: Use node.baseURI (or document.baseURI) whenever you need the absolute base the browser uses for relative URLs.

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.

Continue with childNodes, EventTarget(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Read baseURI when debugging relative asset paths
  • Resolve with new URL(rel, node.baseURI)
  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about baseURI

Absolute document base for every Node.

5
Core concepts
📄 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.

Next: childNodes

Read the live NodeList of every direct child node.

childNodes →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful