Lesson 14 of 50
cssVisibility & Opacity
5 mins
Course progress28%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 14 of 50
css5 mins
Keep these ideas in mind as you work through the lesson.
Two (often confused) ways to hide an element:
| Property | Visual Result | Layout Impact | Accessibility |
|---|---|---|---|
visibility:hidden | Not visible but still takes up space. | No layout change. | Still read by screen‑readers. |
opacity:0 | Fully transparent; still participates in layout and can receive pointer events. | No layout change. | Still read by screen‑readers. |
display:none | Neither visible nor present in the DOM tree. | Element is removed; surrounding elements collapse. | Removed from accessibility tree. |
Both visibility:hidden and opacity:0 are handy as animation start‑states, because you can transition them to visible without affecting layout.
.hidden {
opacity:0;
transition:opacity .3s ease;
}
.visible {
opacity:1;
}
/* JS toggles the class */
If you hide something from sight but want screen‑reader users to still access it, use visibility:hidden plus aria-hidden="false" or better yet keep the element visible and only visually clip it (clip-path or transform).