files/en-us/web/api/document/visibilitystate/index.md
{{ApiRef("DOM")}}
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 {{domxref("Document/visibilitychange_event", "visibilitychange")}} event is sent to the {{domxref("Document")}}.
The {{domxref("Document.hidden")}} property provides an alternative way to determine whether the page is hidden.
A string with one of the following values:
visible
hidden
document.addEventListener("visibilitychange", () => {
console.log(document.visibilityState);
// Modify behavior…
});
{{Specifications}}
{{Compat}}