JavaScript Document readyState Property

Beginner
⏱️ 12 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline Widely available
Instance property

What You’ll Learn

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

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).

Related Document tutorials: hidden, currentScript, body, Document constructor.

Understanding Document.readyState

A read-only instance property on Document. Its value is always one of three strings defined by HTML (MDN).

  • "loading" — document still loading; HTML parser active (MDN).
  • "interactive" — document parsed; deferred/module scripts run; DOMContentLoaded fires (MDN).
  • "complete" — document and sub-resources loaded; load event about to fire (MDN).
  • Eventreadystatechange on each transition (MDN).
  • Status — Baseline Widely available since July 2015 (MDN).

📝 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;
}

⚡ Quick Reference

GoalCode / note
Current statedocument.readyState
Still parsing?document.readyState === "loading"
DOM ready?document.readyState !== "loading"
Fully loaded?document.readyState === "complete"
Watch changesdocument.addEventListener("readystatechange", ...)
MDN statusBaseline Widely available (since Jul 2015)

🔍 At a Glance

Four facts about document.readyState.

Type
string

Read-only

States
3 values

loading → complete

Event
readystatechange

On change

Status
baseline

Widely available

📋 interactive vs complete

"interactive""complete"
DOM parsed?YesYes
Images / CSS done?May still be loadingFinished (MDN)
Related eventDOMContentLoadedload
Typical initDOM manipulation, app bootMeasure full page ready

Examples Gallery

Examples follow MDN Document: readyState. In try-it labs the page is usually already complete when the script runs.

📚 Getting Started

Read the current loading state.

Example 1 — Read the Current State

Log document.readyState to see where the page is now.

JavaScript
console.log(document.readyState);
// "complete" after full load (typical in try-it)
Try It Yourself

How It Works

Scripts at the end of <body> usually see interactive or complete.

Example 2 — MDN Switch on Readiness

Branch behavior for each loading phase (MDN example).

JavaScript
switch (document.readyState) {
  case "loading":
    console.log("Still loading");
    break;
  case "interactive":
    console.log("DOM ready");
    break;
  case "complete":
    console.log("Fully loaded");
    break;
}
Try It Yourself

How It Works

Use the switch when your script may run at different points during page load.

📈 Events & readystatechange

MDN alternatives to common load events.

Example 3 — Alternative to DOMContentLoaded

Call init when state becomes interactive (MDN).

JavaScript
document.onreadystatechange = () => {
  if (document.readyState === "interactive") {
    initApplication();
  }
};
Try It Yourself

How It Works

DOMContentLoaded is often simpler, but readystatechange covers edge cases in older patterns.

Example 4 — Alternative to load Event

Call init when state becomes complete (MDN).

JavaScript
document.onreadystatechange = () => {
  if (document.readyState === "complete") {
    initApplication();
  }
};
Try It Yourself

How It Works

Equivalent timing to window.addEventListener("load", ...) for full resource load.

Example 5 — readystatechange Listener (MDN)

Run different inits at interactive and complete.

JavaScript
document.addEventListener("readystatechange", (event) => {
  if (event.target.readyState === "interactive") {
    initLoader();
  } else if (event.target.readyState === "complete") {
    initApp();
  }
});
Try It Yourself

How It Works

MDN uses this to insert or modify the DOM before and after full load.

🚀 Common Use Cases

  • Boot apps early — start DOM work at interactive.
  • Defer heavy work — wait for complete before measuring layout.
  • Debug load timing — log each readystatechange transition.
  • Legacy compatibility — single handler instead of multiple events.
  • Inline script guards — check state before touching document.body.
  • Progress UI — update a loader as state advances.

🧠 How Page Loading States Progress

1

loading

HTML parser is still building the document tree (MDN).

Parse
2

interactive

DOM parsed; deferred scripts run; DOMContentLoaded fires (MDN).

DOM ready
3

Sub-resources finish

Images, stylesheets, and frames complete loading (MDN).

Assets
4

complete

Full page loaded; load event fires; readyState stays complete.

📝 Notes

  • MDN: Baseline Widely available (since July 2015) — no Deprecated / Experimental / Non-standard banner.
  • Read-only string; assigning does not change browser load behavior.
  • readystatechange fires on document, not window (MDN).
  • For most apps, DOMContentLoaded and load remain the clearest APIs.
  • Related: currentScript, hidden, Document constructor.

Universal Browser Support

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.

Universal Widely available
Google Chrome Full support · Desktop & Mobile
Full support
Mozilla Firefox Full support · Desktop & Mobile
Full support
Apple Safari Full support · macOS & iOS
Full support
Microsoft Edge Full support · Chromium
Full support
Opera Full support · Modern versions
Full support
Internet Explorer Supported in legacy IE
Full support
Document.readyState Excellent

Bottom line: Use document.readyState and readystatechange to inspect or react to page load phases. Prefer DOMContentLoaded and load for most init code.

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.

Continue with referrer, hidden, prerendering, or the JavaScript hub.

💡 Best Practices

✅ Do

  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about document.readyState

Three loading states — one standard Document property.

5
Core concepts
🔄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.

Next: referrer

Learn how to read the previous page URL with document.referrer.

referrer →

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.

6 people found this page helpful