Full answer
All four make something invisible, but they differ in layout, interaction and what assistive technology sees.
display: noneremoves the element from layout and from the accessibility tree. It takes no space, cannot be focused and its children are gone too. The HTMLhiddenattribute is a built-in way to get the same effect.visibility: hiddenkeeps the space the element would use but draws nothing. It cannot be clicked or focused, and browsers normally leave it out of the accessibility tree. A child can opt back in withvisibility: visible.opacity: 0makes the element fully transparent but it is still there. It still takes space, still receives clicks and focus, and screen readers still read it. It is used for fade animations.
B takes no room, so E moves left. C is invisible but keeps its 80px slot, except for the child span that was marked visible. D is invisible, but the button inside can still be reached with the Tab key and clicked.
Because opacity: 0 content is still interactive, hiding something with opacity alone is an accessibility and security problem for forms and menus. Combine it with visibility: hidden after the fade, or use display: none. Modern CSS can animate display and visibility together with transitions in supporting browsers, but check support before relying on it.
<style>
.row { display: flex; gap: 8px; margin-bottom: 8px; }
.box { width: 80px; height: 30px; background: #9cf; }
#none { display: none; }
#vis { visibility: hidden; }
#vis span { visibility: visible; }
#op { opacity: 0; }
</style>
<div class="row">
<div class="box">A</div>
<div class="box" id="none">B</div>
<div class="box" id="vis"><span id="kid">C</span></div>
<div class="box" id="op"><button id="btn">D</button></div>
<div class="box">E</div>
</div>Run in Chrome 156 (headless) as a page; the snippet is wrapped in a minimal HTML document with doctype, charset and viewport meta tag. Two full runs gave identical results, and the measured values in the answer come from them.
Key points
- display: none: no space, not focusable, not in the accessibility tree.
- visibility: hidden: keeps space, not clickable or focusable, normally not announced.
- opacity: 0: fully interactive and announced, only invisible.
- The hidden attribute behaves like display: none.
- Hiding a menu with opacity alone leaves invisible links in the tab order.
Common mistakes
- using opacity: 0 to hide a dropdown and leaving invisible links that keyboard users can still tab to.
- using visibility: hidden to hide content from sighted users while expecting screen readers to still read it. Use a visually-hidden class for that.
Follow-ups
- which of these can be transitioned?
- Can you transition from display: none?
- How would you fade out a dropdown and also remove it from the tab order?
Tips
- For a toggled menu, use display: none or the hidden attribute so hidden links are not in the tab order.
- Mention the accessibility side for each option; it is the usual follow-up.
- Use a small table in your head: space, clicks, focus, screen reader.