Document: visibilityState property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

The Document.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 of this property changes, the visibilitychange event is sent to the Document.

The Document.hidden property provides an alternative way to determine whether the page is hidden.

Value

A string with one of the following values:

visible

The page content may be at least partially visible. In practice this means that the page is the foreground tab of a non-minimized window.

hidden

The page content is not visible to the user. In practice this means that the document is either a background tab or part of a minimized window, or the OS screen lock is active.

Examples

js
document.addEventListener("visibilitychange", () => {
  console.log(document.visibilityState);
  // Modify behavior…
});

Specifications

Specification
HTML
# dom-document-visibilitystate

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
visibilityState

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Requires a vendor prefix or different name for use.
Has more compatibility info.

See also