Both visibility and display control element rendering in CSS, but they behave differently. visibility: hidden hides the element visually while preserving its layout space, whereas display: none removes the element completely from the document flow.
What is the difference between visibility: hidden and display: none?
Overview
The visibility and display properties determine whether elements appear and how they affect layout. They differ in whether the element continues to occupy space or not.
Property | Effect | Layout Impact | Can Be Animated? |
|---|---|---|---|
visibility: hidden | Element is invisible but still occupies space | ✅ Yes, layout remains intact | ✅ Yes (opacity transitions possible) |
display: none | Element is completely removed from layout flow | ❌ No space reserved | ❌ No (toggle only on re-render) |
Example Comparison
.hidden-element {
visibility: hidden; /* Space remains occupied */
}
.none-element {
display: none; /* Removed from layout entirely */
}
In this scenario, the .hidden-element will not be visible but its space will remain. The .none-element will collapse and other elements will move up to fill its place.
Accessibility Implications
visibility: hiddenelements are usually not focusable and hidden from assistive technologies.display: noneelements are completely removed from the accessibility tree.- Use
aria-hidden='true'explicitly when managing visibility dynamically for accessibility compliance.
Performance & Animations
- Use
visibilitywhen you need to hide/show elements smoothly with transitions (opacity fade). - Use
displaywhen you need to completely remove elements from the document flow (e.g., dropdown menus). - Combining both (
opacity+pointer-events: none) can create interactive fade effects without layout jumps.
visibility: hidden is like making a ghost — you can’t see it, but it still exists in the room. display: none is like removing the object from the room entirely.
visibility: hiddenhides elements but keeps layout space reserved.display: noneremoves elements from both view and flow.- Use
visibilityfor smooth transitions,displayfor structural layout changes. - Always handle visibility with accessibility in mind when toggling UI elements.
Use the relevant interview-question hub first, then move into a concrete study plan before targeted company sets.