visibility
Hides an element but leaves behind the empty space it occupied.
- Initial value
visible- Inherited
- Yes
- Animatable
- yes, abruptly (it stays visible for the whole transition)
- Applies to
- all elements
- JavaScript
element.style.visibility = "hidden"
Example
#.tooltip {
visibility: hidden;
opacity: 0;
transition: opacity 0.2s, visibility 0.2s;
}
.trigger:hover .tooltip {
visibility: visible;
opacity: 1;
}<p class="trigger stage">Hover here
<span class="tooltip box" style="display: inline-grid; margin-left: 8px;">Tooltip</span>
</p>Definition and usage
#The visibility property shows or hides an element without changing the page layout. An element with visibility: hidden becomes invisible and unclickable, but its spot stays reserved. That sets it apart from display: none, which removes the element entirely.
Unlike most properties, visibility is inherited. A child of a hidden parent can still set visibility: visible and show itself again.
The property can transition smoothly, which is handy for menus and tooltips. It’s usually paired with opacity, so the element fades out first and only becomes unclickable afterward.
Syntax
#visibility: visible | hidden | collapse;Values
#Values in practice
#visible
.demo { visibility: visible; }collapse
hidden..demo { visibility: collapse; }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- An element hidden with
visibility: hiddenstill takes up space. If it should disappear along with the gap, usedisplay: noneinstead. - Screen readers skip elements with
visibility: hidden, the same as withdisplay: none.
Related entries
#Spotted a mistake or missing an example? Write to us.