Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Document.hidden — reading document visibility

Document.hidden is a read-only property indicating whether the browser considers the document hidden. Observe visibilitychange to track changes.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

document.hidden

Document.hidden, read as document.hidden, returns true when document.visibilityState === "hidden"; otherwise it returns false. Reading it does not hide the page.

The browser determines visibility, considering circumstances such as a background tab or minimized window. Do not confuse this property with HTMLElement.hidden, which controls an element's hidden state.

Listen for visibilitychange on document and read the property again. The example displays the current page's initial visibility in the status paragraph and updates that paragraph whenever visibility changes. The only value it logs to the console is the detached document's hidden value. This is a Web API specified in the HTML Standard, not an ECMAScript feature; having Node 24 does not establish its availability.

Examples

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Document.hidden</title>
</head>
<body>
  <h1>Document visibility</h1>
  <p id="status" role="status"></p>
  <script>
    const detached = document.implementation.createHTMLDocument('Detached example');
    console.log('Detached document.hidden: ' + detached.hidden);

    const status = document.getElementById('status');
    function showVisibility() {
      status.textContent = document.hidden ? 'This page is hidden.' : 'This page is visible.';
    }
    document.addEventListener('visibilitychange', showVisibility);
    showVisibility();
  </script>
</body>
</html>

Result

Detached document.hidden: true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources