JavaScript Document hidden Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Property

Definition

Document.hidden is a read-only Boolean that is true when the page is considered hidden (background tab, minimized window, or otherwise not visible to the user), otherwise false (MDN).

Read the notes below before you get or set this property. Prefer feature detection when support is limited.

Syntax

Use document.hidden. Start with this line.

JavaScript
document.hidden
CallWhat it does
document.hiddenPrimary signature.

Built into the browser. Read or assign document.hidden — no import required.

Library declarations
JavaScript
document.hidden

Parameters

ParameterDescription
visibilityStateOptional. Richer string alternative

Return Value

Return ValueDescription
*Boolean (true / false)

JavaScript Examples

Example 1 — Read document.hidden

Log whether the page is currently considered hidden.

JavaScript
console.log(document.hidden);
// false while you are looking at this tab
Try It Yourself

How It Works

  1. Read the Boolean. No arguments — access document.hidden.
  2. Expect false here. An active foreground tab is usually visible.
  3. Expect true later. Background tabs and minimized windows flip the flag.
  4. Observe only. The property is read-only; you cannot force visibility.

Example 2 — Listen for visibilitychange (MDN)

Log document.hidden whenever visibility changes.

JavaScript
document.addEventListener("visibilitychange", () => {
  console.log(document.hidden);
  // Modify behavior…
});
Try It Yourself

How It Works

  1. Attach one listener. Use visibilitychange on document.
  2. Read inside the handler. document.hidden reflects the new state.
  3. Act on the change. Pause/resume work in the same callback.
  4. No polling. The event tells you when to check again.

Example 3 — Pause Work When Hidden

Branch on hidden to stop a timer in the background and restart when visible.

JavaScript
let ticks = 0;
let timer = null;

function start() {
  if (timer) return;
  timer = setInterval(() => {
    ticks += 1;
    console.log("tick", ticks);
  }, 1000);
}

function stop() {
  clearInterval(timer);
  timer = null;
}

document.addEventListener("visibilitychange", () => {
  if (document.hidden) {
    stop();
  } else {
    start();
  }
});

if (!document.hidden) start();
Try It Yourself

How It Works

  1. Start when visible. Kick off the interval only if not hidden.
  2. Stop on hide. When hidden is true, clear the timer.
  3. Resume on show. When the user returns, start again.
  4. Save work. Same pattern works for video, WebSockets, and polling.

Browser Support

Document.hidden is Baseline Widely available (MDN: since July 2015). Part of the Page Visibility API — safe for modern and older evergreen browsers.

✓ Baseline · Widely available

Document.hidden

Read-only Boolean for page visibility — widely supported for years across major engines.

99% Widely available
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
document.hidden Excellent

Bottom line: Safe for production. Listen for visibilitychange, branch on document.hidden, and pair with visibilityState when you need the string form.

Frequently Asked Questions

A boolean: true if the page is considered hidden (background tab, minimized window, or otherwise not visible to the user), false otherwise (MDN).
No. MDN marks Document.hidden as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
document.hidden is a simple true/false. document.visibilityState returns a string such as visible or hidden — MDN notes it as an alternative way to determine whether the page is hidden.
When the user switches tabs, minimizes the window, or the page is otherwise not visible — common cases for saving battery and pausing media.
The visibilitychange event on document. Read document.hidden inside the handler to react when visibility changes (MDN example).
No. It is a read-only property. You observe visibility; you cannot force the page hidden state from script.

Next: images

Learn the Document property that lists every image in the page.

images tutorial →

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.

11 people found this page helpful