Document.location is a read-only property that returns a Location object for the document’s URL, with parts like href, pathname, and hash, plus methods to navigate (MDN).
Read the notes below before you get or set this property. Prefer feature detection when support is limited.
Syntax
Use document.location. Start with this line.
JavaScript
document.location
Call
What it does
document.location
Primary signature.
Built into the browser. Read or assign document.location — no import required.
Library declarations
JavaScript
document.location
Parameters
Parameter
Description
location
Required. Location object (read-only accessor)
Navigation methods
Optional. assign, replace, reload
Return Value
Return Value
Description
*
The current value of document.location.
JavaScript Examples
Example 1 — Read location.href
Log the Location object and its full URL string (MDN pattern).
Read document.URL. Same idea as a plain string (MDN).
Compare. On a normal page they match.
When to choose which. Need parts or navigation → location; string only → URL.
Compatibility
Browser Support
Document.location is Baseline Widely available on MDN (since July 2015). It works across modern browsers as a standard Document property.
✓ Baseline · Widely available
Document.location
Read-only Location object for the document URL — inspect parts or navigate with href / assign / replace.
99%Browser support
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
Android WebViewSupported · Modern WebView
Full support
locationExcellent
Bottom line: Safe everywhere you teach DOM APIs. Use document.URL for a string-only read. Treat assign/replace as real navigation, not logging helpers.
Frequently Asked Questions
A Location object with information about the document URL and methods to change it (such as assign and replace). If the document is not in a browsing context, MDN says the value is null.
No. MDN marks Document.location as Baseline Widely available (since July 2015). It is a standard Document instance property.
On a normal page they refer to the same Location object for that browsing context. Document.location is on the Document; Window.location is on the Window.
Yes. Although you cannot replace the Location object itself, assigning a URL string to document.location is equivalent to assigning to location.href and navigates the page (MDN).
Use document.URL when you only need the current page URL as a read-only string. Use document.location when you also need URL parts (pathname, search, hash) or navigation methods.
Both load a new URL. location.replace() does not keep the current page in session history, so the Back button will not return to it. location.assign() (or setting href) does keep history.