CSS Portal

CSS visibility Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The visibility property controls whether an element is rendered (painted) and whether it participates in hit‑testing and visual output, while allowing you to preserve or remove its layout footprint depending on the chosen mode. Unlike display, which changes whether an element occupies space in the document flow, visibility lets you separate visual presence from layout - e.g., you can prevent an element from being drawn while still reserving the space it would have taken. This distinction is important when you want to keep surrounding content from reflowing but temporarily hide or reveal parts of the UI.

Because visibility affects painting and hit-testing, it interacts differently with interaction- and animation-related properties. An element that is not painted typically will not receive pointer events; for fine-grained control over whether an element receives mouse or touch input you can use pointer-events. For transitions and gradual effects, note that full on/off visibility changes are discrete; to create smooth fades you typically combine visibility changes with opacity or use transition rules to coordinate the change, toggling visibility at the start or end of an opacity animation so the element is removed from or returned to the painted tree at the appropriate moment.

visibility is inherited, so setting it on an ancestor can suppress or alter the rendering of many descendants without individually changing each of them. That inheritance can be convenient for toggling whole sections of a UI, but it can also lead to surprises if a child needs to remain visible while its parent is not - that requires lifting the child out of the ancestor’s context (for example by changing its layout with position and stacking behavior via z-index) or rethinking the element structure. Finally, be aware that some element types (notably table rows and columns) may be handled specially by browsers when visibility modes interact with table layout, so testing in your target scenarios is advisable.

Definition

Initial value
visible
Applies to
All elements
Inherited
No
Computed value
As specified
Animatable
Yes
JavaScript syntax
object.style.visibility

Interactive Demo

Hide me
Item 2
Item 3

Syntax

visibility: visible | hidden | collapse

Values

  • visibleThe generated box is visible.
  • hiddenObject is hidden. The box is invisible (fully transparent, nothing is drawn), but still affects layout. Descendants of the element will be visible if they have visibility:visible.
  • collapseThis value causes the entire row or column to be removed from the display, and the space normally taken up by the row or column to be made available for other content. This value is used for row, row group, column, and column group elements. If used on elements other than rows, row groups, columns, or column groups, 'collapse' has the same meaning as 'hidden'.

Example

<div class="demo">
<h2>CSS visibility property demo</h2>
<div class="row">
<div class="box visible">Visible</div>
<div class="box hidden">Hidden (visibility: hidden)</div>
<div class="box visible">Visible</div>
</div>
<p class="note">The middle box is invisible but still takes up space; the right box is removed from layout.</p>
</div>
.demo {
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
    max-width: 720px;
    margin: 24px auto;
    padding: 16px;
}

.row {
    display: flex;
    gap: 16px;
    align-items: center;
    margin: 16px 0;
}

.box {
    width: 140px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    border-radius: 8px;
    font-weight: 600;
}

.box.visible {
    background: #2ecc71;
}

.box.hidden {
    background: #f39c12;
    visibility: hidden; /* element is not visible but still occupies space */
}

.note {
    color: #444;
    font-size: 14px;
}

Browser Support

The following information will show you the current browser support for the CSS visibility property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!