CSS visibility Property

This property is used to specify whether an element is visible or not in a web document but the hidden elements take up space in the web document. Use the display property to remove or display property to both hide and delete an element from the browser. 

Syntax:

visibility: visible|hidden|collapse|initial|inherit;

Property values:

visible: It is the default value. The element is show or visible normally in the web document. 

Syntax:

visibility:hidden;

Example: 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        CSS | visibility Property
    </title>
    <style>
        h1 {
            color: green;
        }
 
        .Beginner {
            visibility: visible;
        }
 
        body {
            text-align: center;
        }
    </style>
</head>
 
<body>
    <h1>w3wiki</h1>
    <h2>visibility:visible;</h2>
    <p class="Beginner">
        A computer science portal for Beginner
    </p>
</body>
 
</html>


Output:

 

hidden: This property hide the element from the page but takes up space in the document. 

Syntax:

visibility:hidden;

Example: 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        CSS | visibility Property
    </title>
    <style>
        h1 {
            color: green;
        }
 
        .Beginner {
            visibility: hidden;
        }
 
        body {
            text-align: center;
        }
    </style>
</head>
 
<body>
    <h1>w3wiki</h1>
    <h2>visibility:hidden;</h2>
    <p class="Beginner">
        A computer science portal for Beginner
    </p>
</body>
 
</html>


Output:

 

collapse: This property only used for the table elements. It is used to remove the rows and column from the table but it does not affect the layout of the Table. But their space is available for other content. 

Note:This property is not used for other elements except table elements. 

Syntax:

visibility:collapse;

Example: 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        CSS | visibility Property
    </title>
    <style>
        table.Beginner {
            visibility: collapse
        }
 
        table,
        th,
        td {
            border: 1px solid red;
 
            p {
                color: green;
                font-size: 25px;
            }
    </style>
</head>
 
<body>
    <center>
        <h1 style="color:green;">
            w3wiki
        </h1>
        <h2>visibility:collapse;</h2>
        <p>w3wiki</p>
        <table style="border:1px solid red;"
               class="Beginner">
            <tr>
                <th>Beginner</th>
                <th>for</th>
                <th>Beginner</th>
            </tr>
        </table>
        <p>A computer science portal for Beginner</p>
    </center>
</body>
 
</html>


Output:

 

Supported browsers: The browsers supported by visibility Property are listed below:

  • Google Chrome 1.0
  • Edge 12.0 
  • Internet Explorer 4.0
  • Firefox 1.0
  • Opera 4.0
  • Safari 1.0


Contact Us