Difference between "opacity: 0" vs "visibility: hidden" vs "display: none" in CSS with visual examples

Nhan Nguyen - Nov 30 '23 - - Dev Community

Image description

🔥opacity: 0
👉 The element will only be visually hidden, and space will still be allocated.
👉 Users can still focus on the element through the keyboard and the element receives click events.
👉 Allow to transition (to create a fading effect).

Image description

🔥visibility: hidden;
👉 The element will be visually hidden, but space will still be allocated.
👉 Users can not focus on the element or interact with it. The Element does not receive click events.
👉 Child elements can be made visible by changing their visibility.

Image description

🔥display: none;
👉 Space itself will not be allocated for the element.
👉 It is similar to if the element were not present in the DOM itself.

Image description


I hope you found it useful. Thanks for reading. 🙏

Let's get connected! You can find me on:

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .