Document.visibilityState is a read-only instance property that returns a string describing whether the page is "visible" or "hidden". Learn the Page Visibility API, MDN’s visibilitychange event, how it relates to document.hidden, and five examples with try-it labs.
01
Kind
Read-only
02
Returns
string
03
visible
Foreground tab
04
hidden
Background tab
05
Event
visibilitychange
06
Status
Baseline widely
Fundamentals
Introduction
Users often leave a tab open but switch away. Your page may still run JavaScript in the background—burning battery, playing audio, or polling a server. The Page Visibility API lets scripts know when the document is actually visible.
MDN: the visibilityState read-only property returns the visibility of the document. It can be used to check whether the document is in the background or in a minimized window, or is otherwise not visible to the user. When the value changes, the visibilitychange event is sent to the Document.
💡
Two states (MDN)
"visible" — page content may be at least partially visible (foreground tab of a non-minimized window). "hidden" — page content is not visible (background tab, minimized window, or OS screen lock).
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 string — visible or hidden Page Visibility state.
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 ExplorerSupported (legacy)
Legacy support
Document.visibilityStateBaseline support
Bottom line: Use document.visibilityState with visibilitychange to pause media, timers, and polling when the tab is hidden.
Wrap Up
Conclusion
Document.visibilityState tells you whether the page is "visible" or "hidden". Listen for visibilitychange, read the string in your handler, and pause expensive work when the user is not looking at the tab. For a quick boolean check, MDN also documents document.hidden.
Pair with document.hidden when a boolean is enough
❌ Don’t
Assign to document.visibilityState (read-only)
Rely on window blur alone for tab visibility
Keep heavy polling running in hidden tabs
Assume visibility never changes on mobile
Forget to remove listeners in short-lived components
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about document.visibilityState
Page Visibility string — visible or hidden.
5
Core concepts
👁01
Type
String
Read-only
✅02
visible
Foreground
MDN
🚫03
hidden
Background
MDN
🔔04
Event
visibilitychange
Listen
📈05
Status
Baseline
2015+
❓ 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.
Did you know?
MDN states that when visibilityState changes, the visibilitychange event is sent to the Document. That means one listener can pause video, stop polling, and update analytics—all from a single event instead of checking visibility on every timer tick.