Open In App

HTML DOM document visibilityState Property

Last Updated : 19 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The visibilityState property returns the visibility of the document. This is a read-only property.

Syntax:

letvis = document.visibilityState;

Return Value:

  • visible: When page content may be visible to the user.
  • hidden: When page content is not visible to the user.
  • prerender: when the document is being prerendered and is not visible to the user.

Example: In this example, we are using the above-explained property.

HTML




<!DOCTYPE html>
<html>
   
<body>
    <h1>GeeksforGeeks</h1>
 
    <button onclick="get()">
        Get visibility
    </button>
 
    <script type="text/javascript">
        function get() {
            let m = document.visibilityState;
            console.log(m);
        }
    </script>
</body>
   
</html>


Output:

 

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Opera
  • Safari

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads