HTML DOM

HTML DOM URL Property

The URL property returns the full URL of the current document as a string. It is a read-only property that reflects the address the page was loaded from.


Definition and Usage

document.URL returns the entire URL of the document, including protocol, host, path, and any query string. Unlike window.location, document.URL is read-only - you cannot assign to it to navigate.

Syntax

document.URL

It takes no arguments and returns a string containing the document's full URL.

Example

console.log(document.URL);
// e.g. "https://www.example.com/learn-html/dom?tab=1"

// Show it on the page
document.getElementById("out").innerHTML =
  "You are viewing: " + document.URL;

The example logs and displays the complete address of the current page. If the page URL includes a query string, it is included in the returned value.

ℹ️

To change the URL or read individual parts (hostname, pathname, search), use the window.location object, which is both readable and writable.

Ready to use your HTML skills?

Find web development internships and fresher jobs across India.

Browse Web Dev Internships