×

注意!页面内容来自https://www.geeksforgeeks.org/css/css-visibility-property/,本站不储存任何内容,为了更好的阅读体验进行在线解析,若有广告出现,请及时反馈。若您觉得侵犯了您的利益,请通知我们进行删除,然后访问 原网页

<> #nprogress { pointer-events: none; } #nprogress .bar { background: #29D; position: fixed; z-index: 9999; top: 0; left: 0; width: 100%; height: 3px; } #nprogress .peg { display: block; position: absolute; right: 0px; width: 100px; height: 100%; box-shadow: 0 0 10px #29D0 0 5px #29D; opacity: 1; -webkit-transform: rotate(3deg) translate(0px-4px); -ms-transform: rotate(3deg) translate(0px-4px); transform: rotate(3deg) translate(0px-4px); } #nprogress .spinner { display: block; position: fixed; z-index: 1031; top: 15px; right: 15px; } #nprogress .spinner-icon { width: 18px; height: 18px; box-sizing: border-box; border: solid 2px transparent; border-top-color: #29D; border-left-color: #29D; border-radius: 50%; -webkit-animation: nprogresss-spinner 400ms linear infinite; animation: nprogress-spinner 400ms linear infinite; } .nprogress-custom-parent { overflow: hidden; position: relative; } .nprogress-custom-parent #nprogress .spinner, .nprogress-custom-parent #nprogress .bar { position: absolute; } @-webkit-keyframes nprogress-spinner { 0% { -webkit-transform: rotate(0deg); } 100% { -webkit-transform: rotate(360deg); } } @keyframes nprogress-spinner { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
  • Courses
  • Tutorials
  • Interview Prep

CSS visibility Property

Last Updated : 11 Jul2025

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.

html
<!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>.

html
<!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.

html
<!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:

Comment

Explore