DEV Community

Nhan Nguyen
Nhan Nguyen

Posted on

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

🔥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).

🔥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.

🔥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.


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

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

Top comments (0)