visibility: hidden makes an element completely invisible, indistinguishable from not being rendered at all visually, but it still fully participates in layout, reserving exactly the same space it would occupy if visible, unlike display: none, which removes the element from layout entirely, causing surrounding elements to shift and fill in the space it would have occupied. A nested child element inside a visibility: hidden parent can override that inheritance by explicitly setting its own visibility: visible, making that specific child visible again even while its parent remains hidden, a capability display: none simply doesn't offer, since a display: none parent removes its entire subtree from rendering with no possible override.
1Understanding Visibility
visibility: hidden makes an element completely invisible, indistinguishable from not being rendered at all visually, but it still fully participates in layout, reserving exactly the same space it would occupy if visible, unlike display: none, which removes the element from layout entirely, causing surrounding elements to shift and fill in the space it would have occupied. A nested child element inside a visibility: hidden parent can override that inheritance by explicitly setting its own visibility: visible, making that specific child visible again even while its parent remains hidden, a capability display: none simply doesn't offer, since a display: none parent removes its entire subtree from rendering with no possible override.
Use visibility: hidden specifically when you want an element to become invisible while still reserving its layout space, preventing surrounding content from shifting to fill the gap — use display: none instead when the element should be completely removed from the layout, letting surrounding content reflow into that space.
.tooltip {
visibility: hidden;
}
.trigger:hover .tooltip {
visibility: visible;
}2Practical Example
Here is a real-world application of Visibility showing how it is used in production CSS code.
.hidden-section {
visibility: hidden;
}
.hidden-section .always-show {
visibility: visible;
}3Best Practices
Follow these guidelines when working with Visibility:
1. Use visibility: hidden when an element's layout space should remain reserved even while it's invisible, avoiding a layout shift in surrounding content
2. Use display: none instead when an invisible element's space should also be freed up, letting surrounding content reflow to fill the gap
3. Take advantage of a nested child's ability to override an ancestor's visibility: hidden with its own visibility: visible, a capability display: none doesn't provide
Tip: Use visibility: hidden specifically when you want an element to become invisible while still reserving its layout space, preventing surrounding content from shifting to fill the gap — use display: none instead when the element should be completely removed from the layout, letting surrounding content reflow into that space.
.tooltip {
visibility: hidden;
}
.trigger:hover .tooltip {
visibility: visible;
}