✅ display: none
- Completely removes the element from the layout.
- It does not occupy space on the page.
- DOM still holds the element, but it’s not rendered visually.
<div style="display: none;">This is hidden</div>
- 🔸 Use Case: Temporarily removing elements like modals, dropdowns, etc.
✅ visibility: hidden
- The element is invisible, but it still occupies space in the layout.
- No visual display, but the layout remains unaffected.
<div style="visibility: hidden;">This is hidden but space is reserved</div>
- 🔸 Use Case: When you want to hide something but maintain layout (e.g., hide a tooltip while preserving alignment).
🟢 Summary:
| Property | Renders? | Takes Space? | Use When |
|---|---|---|---|
display: none |
❌ No | ❌ No | Fully remove from layout |
visibility: hidden |
❌ No | ✅ Yes | Hide without affecting layout |