CSS Reference ยท Box Model and Sizing
The visibility property
Reference for the CSS visibility property: hide an element while keeping its space in the layout. Values, comparison with display: none and opacity, examples.
The visibility property controls whether an element is drawn. An element with visibility: hidden is invisible, but it still takes up exactly the space it would have taken, so nothing around it moves. This is the main difference from display: none, which removes the element from the layout entirely.
.placeholder { visibility: hidden; }
Try it
The first row has an empty slot where B would be. The second row closes the gap. In the third, the parent is hidden but the child is switched back to visible, so only the child shows.
Syntax
visibility: visible | hidden | collapse
- Initial value:
visible - Applies to: all elements
- Inherited: yes
- Animatable: yes, as a discrete step that flips between visible and hidden (so
visibleis used for the whole transition when one end is visible) - Computed value: as specified
Values
| Value | Description |
|---|---|
visible |
The element is drawn normally. |
hidden |
The element is invisible but still affects layout. It does not receive pointer events and is removed from the accessibility tree. |
collapse |
For table rows, row groups, columns and column groups, removes the row or column without changing the table's other dimensions. On flex items it acts like hidden. |
Usage notes
- Inheritance lets children opt back in. Because it is inherited, a descendant with
visibility: visibleshows even inside a hidden parent. - Hidden means unreachable. Hidden elements cannot be focused, clicked or read by screen readers, which makes
visibility: hiddena good way to hide off-screen menus without extra work. - Compared with
opacity: 0. An element with zero opacity is still clickable, focusable and announced. Usevisibility(orinert) when it should be inaccessible too. - Compared with
display: none. Usenonewhen the space should disappear. Usehiddento avoid layout shift. - Fading out properly. To fade an element out and then make it unreachable, transition
opacityandvisibilitytogether;visibilityflips at the end of the fade when going to hidden. - Visually hidden text for screen readers needs a different technique (a clipped, absolutely positioned element), not
visibility: hidden.
Browser support
Supported in every browser. The collapse value for table rows and columns works in all current browsers.