Document.readyState is a read-only instance property that returns the page loading phase: "loading", "interactive", or "complete". Learn MDN’s switch pattern, readystatechange, and alternatives to DOMContentLoaded and load with five examples.
01
Kind
Read-only property
02
Returns
string
03
States
3 values
04
Event
readystatechange
05
Pair with
DOMContentLoaded
06
Status
Baseline
Fundamentals
Introduction
When a web page loads, the browser moves through distinct phases: parsing HTML, building the DOM, fetching images and stylesheets, and firing load events. document.readyState exposes where the document is in that pipeline right now.
MDN: the property describes the loading state of the document. When its value changes, a readystatechange event fires on the document object.
💡
Three string values
"loading" → HTML parser still working. "interactive" → DOM ready, sub-resources may still load. "complete" → everything finished (MDN).
"complete" — document and sub-resources loaded; load event about to fire (MDN).
Event — readystatechange on each transition (MDN).
Status — Baseline Widely available since July 2015 (MDN).
Foundation
📝 Syntax
JavaScript
document.readyState
Value
A string: "loading", "interactive", or "complete" (MDN).
MDN example — switch on readiness
JavaScript
switch (document.readyState) {
case "loading":
// The document is loading.
break;
case "interactive": {
// DOM parsed; sub-resources may still load.
const span = document.createElement("span");
span.textContent = "A <span> element.";
document.body.appendChild(span);
break;
}
case "complete":
// The page is fully loaded.
console.log("Page complete");
break;
}
Document.readyState is marked Baseline Widely available on MDN (since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
Document.readyState
Read-only loading state string — loading, interactive, or complete.
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerSupported in legacy IE
Full support
Document.readyStateExcellent
Bottom line: Use document.readyState and readystatechange to inspect or react to page load phases. Prefer DOMContentLoaded and load for most init code.
Wrap Up
Conclusion
Document.readyState tells you whether the page is still loading, DOM-interactive, or fully complete. Pair it with readystatechange to schedule init code at the right moment in the load lifecycle.
Use DOMContentLoaded for DOM-only setup in modern code
Check readyState before touching document.body in early scripts
Listen for readystatechange when you need both phases
Log states while debugging slow page loads
Run layout-sensitive code at complete
❌ Don’t
Assign to document.readyState
Assume interactive means all images loaded
Poll readyState in a tight loop instead of using events
Confuse readystatechange with window.onload target
Block rendering while waiting for complete if DOM work suffices
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about document.readyState
Three loading states — one standard Document property.
5
Core concepts
📄01
Returns
string
API
🔄02
States
3 phases
MDN
⚡03
Event
readystatechange
Listen
🛠04
DOM ready
interactive
Init
✓05
Full load
complete
MDN
❓ Frequently Asked Questions
A string describing document loading state: loading (HTML still parsing), interactive (DOM parsed, sub-resources may still load), or complete (document and sub-resources finished) — MDN.
No. MDN marks Document.readyState as Baseline Widely available (since July 2015). It is a standard HTML Document property.
MDN: whenever the value of readyState changes. Listen on document to react as the page moves from loading to interactive to complete.
interactive means the HTML parser finished and DOMContentLoaded is about to fire; sub-resources may still load. complete means everything including images and stylesheets finished and the load event is about to fire (MDN).
Yes. MDN shows checking document.readyState === 'interactive' in a readystatechange handler as an alternative to DOMContentLoaded.
No. It is a read-only property reflecting browser loading progress. You observe it; you cannot set it from script.
Did you know?
If your script runs when the page is already past a state, assigning document.onreadystatechange may miss earlier transitions. Check the current readyState immediately after registering, or use addEventListener("readystatechange", ...) plus an initial guard.