JavaScript Document documentURI Property

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline Widely available
Instance property

What You’ll Learn

Document.documentURI is a read-only instance property that returns the document location as a string. Learn how it relates to document.URL and location.href, when to use each, and five examples with try-it labs.

01

Kind

Read-only

02

Returns

URL string

03

Same as

document.URL

04

Related

location.href

05

Navigate?

Use location

06

Status

Baseline widely

Introduction

Every loaded page has an address—the URL you see in the browser bar. JavaScript can read that address in a few ways. One of them is document.documentURI.

MDN: the documentURI read-only property returns the document location as a string. MDN also notes that document.URL returns the same value.

💡
URI vs URL (beginner note)

People often say “URL” for web addresses. “URI” is a broader standards term. For everyday pages, documentURI is simply “this document’s address string.”

Related Document tutorials: documentElement, doctype, Document constructor.

Understanding Document.documentURI

A read-only instance property on Document. Its value is a string naming the document’s location.

  • Type — string (full location).
  • Read-only — you cannot assign a new URI here (MDN).
  • Same as document.URL — MDN documents matching values.
  • Navigation — use location / History APIs to change the address.
  • Useful for — logging, analytics, displaying the current URL in UI (MDN-style).

📝 Syntax

JavaScript
document.documentURI

Value

A string — the document location (MDN).

MDN-style display

JavaScript
document.getElementById("url").textContent = document.documentURI;

⚡ Quick Reference

GoalCode / note
Read document addressdocument.documentURI
Same valuedocument.URL
Show in the pageel.textContent = document.documentURI
Compare with locationdocument.documentURI === location.href
Change addresslocation.href = "…" (not documentURI)
MDN statusBaseline Widely available

🔍 At a Glance

Four facts about document.documentURI.

Type
string

Location

Access
read-only

No setter

Alias
document.URL

Same value

Status
baseline

Standard API

📋 What the string usually contains

PartExampleIn documentURI?
Origin + pathhttps://example.com/pageYes
Query string?q=1Yes (when present)
Hash / fragment#sectionYes (when present)
Separate path-only APIlocation.pathnameUse Location for pieces

Examples Gallery

Examples follow MDN Document: documentURI. Use View Output or Try It Yourself for each case.

📚 Getting Started

Read the location string and display it (MDN).

Example 1 — Log document.documentURI

Print the current document address.

JavaScript
console.log(document.documentURI);
// e.g. "https://www.codetofun.com/js/document/properties/document-uri"
Try It Yourself

How It Works

The browser reports the address associated with this Document object.

Example 2 — Show the URL in the Page (MDN)

MDN’s pattern: write documentURI into a text node.

JavaScript
document.getElementById("url").textContent = document.documentURI;
Try It Yourself

How It Works

Useful for debug panels or “copy page link” helpers that read the live address.

📈 URL, href & Parsing

Compare related APIs and break the string into parts.

Example 3 — Same as document.URL (MDN)

Confirm both Document properties match.

JavaScript
console.log(document.documentURI);
console.log(document.URL);
console.log(document.documentURI === document.URL); // true
Try It Yourself

How It Works

MDN: document.URL returns the same value as documentURI.

Example 4 — Compare with location.href

Location is the usual API when you also need to navigate.

JavaScript
console.log("documentURI:", document.documentURI);
console.log("location.href:", location.href);
console.log("Equal:", document.documentURI === location.href);
Try It Yourself

How It Works

Prefer location when you need path/search/hash helpers or assignment for navigation.

Example 5 — Parse Pieces with the URL Constructor

Turn the string into structured parts without reinventing parsing.

JavaScript
const u = new URL(document.documentURI);

console.log("origin:", u.origin);
console.log("pathname:", u.pathname);
console.log("search:", u.search);
console.log("hash:", u.hash);
Try It Yourself

How It Works

Or read location.pathname / search / hash directly when you already have the Location object.

🚀 Common Use Cases

  • Debug panels — show the live document address (MDN demo style).
  • Logging / analytics — record which document URL produced an event.
  • Share / copy link — seed a clipboard helper from documentURI.
  • Multi-document tools — when you hold a Document, read its URI without assuming global location.
  • Not for navigation — assign location.href or use History instead.
  • Alias awareness — teams often write document.URL; same value (MDN).

🧠 How documentURI Relates to Navigation

1

Browser loads a location

User opens a URL or a script navigates.

Load
2

Document is associated with that address

The Document knows its location string.

Document
3

Scripts read documentURI

Same family of value as document.URL / often location.href.

Read
4

To change address, use Location

location.href, assign, replace, or History APIs—not documentURI.

📝 Notes

  • MDN: Baseline Widely available (since April 2018) — no Deprecated / Experimental / Non-standard banner.
  • Read-only string — the document location.
  • document.URL returns the same value (MDN).
  • Do not confuse with assigning location.href for navigation.
  • Related: documentElement, doctype, Document constructor.

Universal Browser Support

Document.documentURI is marked Baseline Widely available on MDN (since April 2018). Logos use the shared browser-image-sprite.png sprite from this project.

Baseline · Widely available

Document.documentURI

Read-only string — the document location (same value as document.URL per MDN).

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
Full support
Opera Full support · Modern versions
Full support
Internet Explorer Not in legacy IE the same way — use document.URL / location
No / limited
Document.documentURI Excellent

Bottom line: Use document.documentURI (or document.URL) to read the document address. Use location / History to navigate.

Conclusion

Document.documentURI is the Document API for reading the page address as a string. It matches document.URL; for navigation and URL parts, reach for location.

Continue with domain, documentElement, doctype, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Use documentURI or document.URL to read the address
  • Parse with new URL(...) when you need structured parts
  • Prefer location when navigating or reading pathname/search/hash
  • Show URIs carefully in UI (user-facing privacy)
  • Log the URI next to errors for support tickets

❌ Don’t

  • Assign to document.documentURI
  • Reimplement URL parsing with brittle string splits
  • Assume every Document is the top-level page without checking
  • Confuse document address with document.referrer
  • Put secrets in the URL and then log documentURI

Key Takeaways

Knowledge Unlocked

Five things to remember about document.documentURI

Read-only document location string — same as document.URL.

5
Core concepts
02

Status

baseline

Standard
🔒03

Access

read-only

DOM
🔀04

Same as

document.URL

MDN
🚀05

Navigate

use location

Related

❓ Frequently Asked Questions

A string with the document's location (its URL / URI). On a normal web page it is the address of that page.
No. MDN marks Document.documentURI as Baseline Widely available (since April 2018). It is a standard read-only Document instance property.
MDN notes that document.URL returns the same value. Prefer either; many codebases use document.URL or location.href for everyday work.
location.href is on the Location object and is commonly used for reading and navigating. documentURI is a Document property that reports the document location as a string (read-only on Document).
No. It is read-only on Document. To navigate, use location.assign / location.href (or history APIs).
Yes — like a full page URL string, it typically includes path, query, and fragment when present (same family of values as document.URL / location.href).
Did you know?

The name documentURI comes from DOM / XML-oriented APIs that talk about “document URIs.” On the modern web you will see document.URL and location.href more often in tutorials—but MDN keeps documentURI as a first-class Document property with the same location string.

Next: domain

Learn why document.domain is deprecated and what to use instead.

domain →

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.

6 people found this page helpful