document.visibilityState is a read-only string from the Page Visibility API that tells you whether the document is "visible" or "hidden" (MDN). When it changes, the browser fires visibilitychange on document.
Read the notes below before you get or set this property. Prefer feature detection when support is limited.
Syntax
Use document.visibilityState. Start with this line.
JavaScript
document.visibilityState
Call
What it does
document.visibilityState
Primary signature.
Built into the browser. Read or assign document.visibilityState — no import required.
Library declarations
JavaScript
document.visibilityState
Parameters
Parameter
Description
Writable?
Optional. Read-only
Event
Optional. visibilitychange on change
Return Value
Return Value
Description
*
"visible" or "hidden"
JavaScript Examples
Example 1 — Read visibilityState
Log the current Page Visibility string on the active tab.
JavaScript
console.log(document.visibilityState);
// "visible" on an active foreground tab
hidden
visible
/* after switching away and back */
How It Works
Attach the listener on document for visibilitychange.
Read the property inside the handler — it already reflects the new state.
Branch on the string to pause or resume work (MDN use cases).
Switch tabs in Try It Yourself to see live updates.
Compatibility
Browser Support
Document.visibilityState 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.visibilityState
Read-only Page Visibility string — visible or hidden — with visibilitychange on change.
WidelyAvailable
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 ExplorerIE 10+ with prefixes historically
Partial support
Document.visibilityStateBaseline support
Bottom line: Use document.visibilityState (or document.hidden) to detect background tabs and pause work. See the MDN Document.visibilityState reference.
Frequently Asked Questions
A read-only string describing document visibility. MDN documents two values: visible (page may be at least partially visible) and hidden (page content is not visible to the user).
No. MDN marks Document.visibilityState as Baseline Widely available (since July 2015). It is part of the standard Page Visibility API.
document.hidden is a boolean shortcut. document.visibilityState returns the exact string state. MDN notes hidden as an alternative way to determine whether the page is hidden.
MDN: when the document is a background tab, part of a minimized window, or the OS screen lock is active — the page content is not visible to the user.
The visibilitychange event on document. Read document.visibilityState inside the handler to react (MDN example).
No. It is read-only. You observe visibility; you cannot force the page hidden from script.