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

Nhan Nguyen
2 min readDec 8, 2023

--

🔥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:
- Medium: https://medium.com/@nhannguyendevjs/
- Dev: https://dev.to/nhannguyendevjs/
- Substack: https://nhannguyendevjs.substack.com/
- Linkedin: https://www.linkedin.com/in/nhannguyendevjs/
- X (formerly Twitter): https://twitter.com/nhannguyendevjs/

--

--

Nhan Nguyen
Nhan Nguyen

No responses yet