The visibility Property: visible, hidden, and collapse
You'll learn how visibility hides elements differently from display by keeping their layout space reserved.
What visibility Does
The visibility property controls whether an element is visible on the page, but unlike display: none, it keeps the element's space in the layout. Think of it like an invisibility cloak: the person is still physically there, taking up space, you just can't see them.
The Three Main Values
visibility: visible (default)
The element displays normally—this is the standard behavior you see every day.
visibility: hidden
The element becomes invisible but still occupies space in the layout. It's there, just unseen. Users can't interact with it (no clicks, no selection), but the layout flows as if it's visible.
.ghost-element {
visibility: hidden;
}
This differs from display: none, which removes the element from layout entirely, collapsing its space.
visibility: collapse
Originally designed for table rows and columns, collapse removes them from display like display: none. For other elements, it typically behaves like hidden. This value has limited practical use in modern layouts.
When to Use visibility
Use visibility: hidden when you want to temporarily hide something but maintain the page's layout structure—like hiding a placeholder while keeping spacing consistent, or creating smooth transitions where space shouldn't shift.
Key Takeaway: The visibility property hides elements while preserving their layout space, unlike display: none which removes them entirely from the document flow.