Home JavaScript Document Properties readyState JavaScript Document readyState Property Definition document.readyState describes the loading state of the document (MDN). When it changes, a readystatechange event fires on document.
Read the notes below before you get or set this property. Prefer feature detection when support is limited.
Syntax Use document.readyState. Start with this line.
Call What it does document.readyStatePrimary signature.
Built into the browser. Read or assign document.readyState — no import required.
Library declarations Parameters Parameter Description Writable? Optional. Read-only Related event Optional. readystatechange when the value changes
Return Value Return Value Description * "loading" | "interactive" | "complete"
JavaScript Examples 1. Read state 2. MDN switch 3. readystatechange Example 1 — Read Current readyState A script at the end of <body> often sees "interactive" or "complete".
console.log(document.readyState);
// "loading" | "interactive" | "complete" interactive
(or complete — depends on when the script runs) How It Works Read the property — MDN returns one of three strings.Timing matters — early scripts may see "loading".Late body scripts often see "interactive".After full load , you see "complete".Example 2 — Branch with switch (MDN) MDN pattern: handle each readiness state differently.
switch (document.readyState) {
case "loading":
console.log("Still loading");
break;
case "interactive":
console.log("DOM ready");
break;
case "complete":
console.log("Fully loaded");
break;
} DOM ready
(or Fully loaded) How It Works Switch on the string returned by readyState.loading — parser still working (MDN).interactive — DOM accessible; sub-resources may continue (MDN).complete — page fully loaded (MDN).Example 3 — readystatechange Listener (MDN) MDN: use readystatechange as an alternative to DOMContentLoaded / load.
document.addEventListener("readystatechange", () => {
if (document.readyState === "interactive") {
console.log("like DOMContentLoaded");
}
if (document.readyState === "complete") {
console.log("like load");
}
}); like DOMContentLoaded
like load
(order depends on when the listener is attached) How It Works Listen on document for readystatechange (MDN).Check interactive — similar timing to DOMContentLoaded (MDN).Check complete — similar timing to the load event (MDN).Attach early — a late listener may miss earlier states.Compatibility
Browser Support Document.readyState is a core HTML Document property. MDN marks it Baseline Widely available (since July 2015).
✓ Baseline · Widely available
Document.readyState loading | interactive | complete. Safe for everyday page-load timing.
Google Chrome Yes
Yes
Microsoft Edge Yes
Yes
Mozilla Firefox Yes
Yes
Apple Safari Yes
Yes
Opera Yes
Yes
Internet Explorer Yes (legacy)
Yes Frequently Asked Questions What does document.readyState return? MDN: a string describing document loading — loading, interactive, or complete.
Is readyState deprecated? No. MDN marks Document.readyState as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
When does readystatechange fire? MDN: when the value of readyState changes. Listen on document to react as the page moves through loading → interactive → complete.
What is the difference between interactive and complete? MDN: interactive means the document is parsed (DOMContentLoaded is about to fire) while sub-resources may still load. complete means the document and all sub-resources finished (load is about to fire).
Can I use readyState instead of DOMContentLoaded? Yes. MDN shows checking readyState === "interactive" in a readystatechange handler as an alternative to DOMContentLoaded.
Can I assign to readyState? No. It is read-only. You observe the browser’s loading progress; you do not set it.
Next: referrer Continue with the Document referrer property.
referrer → About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
14 people found this page helpful
Helpful Share Copy link Suggestion