Open In App

HTML | DOM Style visibility Property

The Style visibility property in HTML DOM used to set the visibility for an element. It is used to hide or show the element. It returns the visibility property that is given to an element.

Syntax: 



object.style.visibility
object.style.visibility = "visible | hidden | collapse | initial | inherit"

Property Values: 
 

Return Value: It returns a string representing the content to be displayed or not for an element.
Example-1: 






<!DOCTYPE html>
<html>
<body>
 
    <center>
        <h1 style="color:green;">
                GeeksForGeeks
            </h1>
        <h2>DOM Style visibility Property </h2>
        <p id="gfg"> A Computer science portal for geeks</p>
 
 
 
        <button type="button" onclick="geeks()">
            Change visibility
        </button>
 
        <script>
            function geeks() {
                document.getElementById(
                  "gfg").style.visibility = "hidden";
            }
        </script>
    </center>
</body>
 
</html>

Output: 

Example-2: 




<!DOCTYPE html>
<html>
<body>
 
    <center>
        <h1 style="color:green;;">
                GeeksForGeeks
            </h1>
        <h2>DOM Style visibility Property </h2>
        <p id="gfg" style="visibility:hidden;">
          A Computer science portal for geeks</p>
 
 
 
        <button type="button" onclick="geeks()">
            Change visibility
        </button>
        <p id="y"></p>
 
 
 
        <script>
            function geeks() {
                var x = document.getElementById(
                  "gfg").style.visibility;
               
                document.getElementById('y').innerHTML = x;
            }
        </script>
    </center>
</body>
 
</html>

Output: 

Supported Browsers: The browser supported by DOM Style visibility property are listed below: 


Article Tags :