The visibility property specifies whether or not an element is visible. It can take values such as visiblehiddenor collapse. Unlike display: nonewhich removes the element from the layoutvisibility: hidden hides the element but maintains its space in the layout.
Syntax
visibility: visible|hidden|collapse|initial|inherit;Property values
- visible: It is the default value. The element is shown or visible normally in the web document.
- hidden: The element is not visible and does not take up any space in the layout. It is effectively removed from view.
- collapse: For table elementsthis value hides the row or column and it does not take up any space in the layoutsimilar to hidden. It is often used with table rows or columns.
- inherit: The element takes on the property value from its parent elementmaking it inherit the visibility setting from its containing element.
- initial: The element is set to the default value of the property as defined by the CSS specification. For visibilitythis is typically visible.
Syntax
visibility:hidden;Example: In this examplewe use CSS to elements. The .geeks class sets visibility: visible;making the paragraph visible while <h1> is d green and <body> text aligned center.
<!DOCTYPE html>
<html>
<head>
<title>
CSS | visibility Property
</title>
<>
h1 {
color: green;
}
.geeks {
visibility: visible;
}
body {
text-align: center;
}
</>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>visibility:visible;</h2>
<p class="geeks">
A computer science portal for geeks
</p>
</body>
</html>
Output:

visibility: hidden
This property hide the element from the page but takes up space in the document.
Syntax:
visibility:hidden;Example: In this example we hides the <p> element with class .geeks using visibility: hidden;making it invisible while styling <h1> in green and center-aligning text within <body>.
<!DOCTYPE html>
<html>
<head>
<title>
CSS | visibility Property
</title>
<>
h1 {
color: green;
}
.geeks {
visibility: hidden;
}
body {
text-align: center;
}
</>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>visibility:hidden;</h2>
<p class="geeks">
A computer science portal for geeks
</p>
</body>
</html>
Output:

visibility: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: In this example we sets visibility: collapse; on a <table> with class .geekshiding its borders and content. The page also s <h1> green and <p> elements within <center> alignment.
<!DOCTYPE html>
<html>
<head>
<title>
CSS visibility Property
</title>
<>
table.geeks {
visibility: collapse
}
table,
th,
td {
border: 1px solid red;
p {
color: green;
font-size: 25px;
}
</>
</head>
<body>
<center>
<h1 ="color:green;">
GeeksForGeeks
</h1>
<h2>visibility:collapse;</h2>
<p>geeksforgeeks</p>
<table ="border:1px solid red;"
class="geeks">
<tr>
<th>geeks</th>
<th>for</th>
<th>geeks</th>
</tr>
</table>
<p>A computer science portal for geeks</p>
</center>
</body>
</html>
Output:

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