JavaScript Document URL Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Property

Definition

Document.URL is a read-only property that returns the document location as a string (MDN) — the full address of the current page.

Read the notes below before you get or set this property. Prefer feature detection when support is limited.

Syntax

Use document.URL. Start with this line.

JavaScript
document.URL
CallWhat it does
document.URLPrimary signature.

Built into the browser. Read or assign document.URL — no import required.

Library declarations
JavaScript
document.URL

Parameters

This member has no parameters beyond those shown in the signature.

Return Value

Return ValueDescription
*String (full location)

JavaScript Examples

Example 1 — Read document.URL

Log the current document location string.

JavaScript
console.log(document.URL);
// e.g. "https://example.com/page?x=1#top"
Try It Yourself

How It Works

  1. Read the property. No arguments — access document.URL.
  2. Get a string. It is the full document location, not a Location object.
  3. Expect the full address. Path, query, and hash are included when present.
  4. Observe only. Assigning does not navigate the page.

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

Write document.URL into an element’s text content.

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

How It Works

  1. Find a target. getElementById("url") picks the span/container.
  2. Read document.URL. That string is the document location.
  3. Assign to textContent. The UI shows the address safely as text.
  4. MDN pattern. Same idea as the official Document.URL example.

Example 3 — Compare URL, documentURI, and href

Confirm the three common location strings usually match.

JavaScript
console.log(document.URL === document.documentURI);
console.log(document.URL === location.href);
console.log(document.URL);
Try It Yourself

How It Works

  1. Compare with documentURI. Same location string on typical HTML pages.
  2. Compare with location.href. Usually the same in the active browsing context.
  3. Log the value. See the full address once.
  4. Choose by need. String only → document.URL; navigate/parts → location.

Browser Support

Document.URL is Baseline Widely available (MDN: since July 2015). Safe to use in modern and older evergreen browsers.

✓ Baseline · Widely available

Document.URL

Read-only document location string — supported across browsers for years.

99% Widely available
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
document.URL Excellent

Bottom line: Safe for production. Use document.URL (or documentURI) to read the address; use location when you need navigation or URL parts.

Frequently Asked Questions

A read-only string with the document location — the full address of the current page (MDN).
No. MDN marks Document.URL as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
On typical pages they return the same string. document.URL is the familiar name; documentURI is the standards-oriented Document alias.
No. It is read-only on Document. To navigate, use location.href, location.assign(), location.replace(), or the History APIs.
Both often return the same string on the active page. Use location when you also need to navigate or read pathname, search, and hash. Use document.URL when you only need the location string from a Document.
Yes — it is the full location string, typically including path, query (?key=value), and fragment (#section) when present.

Next: visibilityState

Learn the string form of the Page Visibility API.

visibilityState tutorial →

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.

11 people found this page helpful