Skip to content
Related Articles

Related Articles

Improve Article

HTML DOM document visibilityState Property

  • Last Updated : 05 Jul, 2020

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

Syntax:

var vis = document.visibilityState;

Return Value:

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

Example:

HTML




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

Output:



Before Click the Button:

After Click the Button:

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Opera
  • Safari

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :