The Page Visibility API is a small browser interface that lets a web page learn whether it is on screen. It exposes a document.visibilityState property with the values visible and hidden, a boolean document.hidden shortcut, and a visibilitychange event that fires when the state flips. MDN defines visible as meaning the page content may be at least partially visible, which in practice means the foreground tab of a non-minimised window, and hidden as meaning the content is not visible because the tab is in the background, the window is minimised, or the device's screen is off. The API answers a narrow question about the document's place on the display. It says nothing about whether the window has keyboard focus, whether a particular element is scrolled into view, or whether anyone is paying attention, and each of those is handled by a different mechanism.
Visibility States and the visibilitychange Event
The state is read synchronously at any time and observed through the event. A page that wants to pause work while hidden registers a listener on the document, checks the state inside it, and acts accordingly. MDN's example pauses an audio element when the page becomes hidden and resumes it on return only if it was playing before, which captures the typical shape: record what was happening, suspend it, and restore it conditionally.
Common transitions include tab switches, minimising a window and turning off the display. Whether complete overlap by another window changes the state is browser-dependent, which MDN describes through the standby example of a user pressing the power button. Iframes inherit the visibility of their parent document, and hiding an iframe with CSS does not change the state of the document inside it or fire the event, because visibility here is about the browsing context's presence on screen rather than the layout of elements. A transition to hidden can precede navigation or a lifecycle change and is a useful opportunity to save state or queue a final analytics beacon. It is not a guarantee of delivery, and abrupt termination may leave no opportunity for another event. Saving important work continuously is safer than waiting for unload.
Tab Changes and Background Work
Knowing the state lets a page behave considerately. MDN lists the standard cases: a carousel that should not advance while unseen, a dashboard that should stop polling the server when hidden, and a site that should silence audio when the device goes to standby. A video player might pause, a game might suspend animation, and a chat client might delay marking messages as read. The right policy depends on the task: deliberately playing background music or maintaining a call may be exactly what the user wants.
Browsers also act on their own, independently of whether the page listens. MDN documents that most browsers stop delivering requestAnimationFrame callbacks to background tabs and hidden iframes, and that timers such as setTimeout are throttled in background tabs. The precise policy depends on browser version and activity. Chrome's published timer rules, for example, distinguish recent audio, active WebRTC and long-hidden pages rather than granting every background page the same schedule. An exception to one throttling rule does not make a tab visible or exempt it from every lifecycle restriction. A browser can later freeze or discard a hidden page, so a timer is not a dependable background clock. The practical consequence for a hidden browser tab is that scheduled work runs late or not at all, which code that assumes a steady clock will misread; the Page Visibility API is how a page can anticipate this rather than discover it.
Page Visibility Compared With Focus and Viewport Intersection
| Mechanism | Question it answers | Granularity | Typical signal |
|---|---|---|---|
| Page Visibility API | Is this document on screen at all? | Whole document | visibilityState, visibilitychange |
| Window focus and blur | Does this window receive keyboard input? | Whole window | focus, blur, document.hasFocus() |
| Intersection Observer | How much does this element intersect the chosen root or viewport? | Individual elements | IntersectionObserver entries with intersection ratios |
MDN explicitly warns against using focus and blur as a proxy for visibility: watching those events tells a page that it is not the active window, but it does not tell it that the page is hidden, since a window can lose focus while remaining fully visible beside another. Page Visibility vs focus separates the browser's display state from its input-focus state; neither establishes attention. A video call window that the user has clicked away from is unfocused but visible, and should keep rendering; the same window minimised is hidden, and may stop. Intersection Observer works at the other end of the scale, reporting geometric intersection between an element and the selected root, often the viewport. A page can be visible while an element in it is scrolled out of view, and an element can be fully intersecting while the whole tab is hidden, so the two signals are usually combined: a measurement system can require both signals, then apply its own area and duration thresholds. Ordinary intersection alone does not prove that an element is unobscured.
Where the API Is Used
Media and games use it to pause. Analytics tools use it to measure engaged time, counting only intervals when the page was visible, and to send final beacons when the page hides. Real-time applications reduce update frequency or drop to a lighter polling schedule while hidden, then refresh immediately on return. Advertising measurement combines visibility with intersection to decide whether an impression was viewable. Tests can read the state and exercise real tab or window transitions. The document property is read-only; changing a JavaScript mock does not reproduce the browser's scheduling and lifecycle behaviour. Security-sensitive pages may lock or blur content when hidden on shared devices.
Limits and Misreadings
The API reports the browser's view of the display, not the user's attention. A visible tab on an unattended machine is visible; a hidden tab with a person waiting for a notification is hidden. It cannot prove that someone is watching, and systems that treat visible as present overstate engagement. It is also coarse: it does not distinguish a tab that is partially covered, a window on a secondary monitor nobody is looking at, or a document in a picture-in-picture arrangement, and browsers differ at those edges. Throttling of hidden pages happens regardless of what the page does, and its exact parameters are implementation details that have changed across versions, so scheduling examples should not be treated as cross-browser API guarantees. The state is also observable by scripts, which means a page can tell when it has been backgrounded, a fact some sites use to alter behaviour and some users regard as a small privacy cost. The Page Visibility API is useful for what it reports, the browser's coarse visibility state, and its value comes from using it for exactly that and pairing it with focus or intersection signals when the question is finer.