---
title: "display: none vs visibility: hidden vs opacity: 0: what is the difference?"
description: "All three hide an element, but they differ in layout space, clicks, keyboard focus, screen readers and animation. Here is when to use each, plus how to hide visually only."
url: https://www.danny.engineering/answer/css/display-none-vs-visibility-hidden-vs-opacity-0-what-is-the-difference
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T20:30:00.000Z
tags: ["CSS"]
---

# display: none vs visibility: hidden vs opacity: 0: what is the difference?

## The short answer


`display: none` removes the element completely: no space, no clicks, no focus, and screen readers skip it. `visibility: hidden` keeps its space but hides it from everyone. `opacity: 0` only makes it transparent: it still takes space, can be clicked and focused, and is still read by screen readers.


```css
.gone      { display: none; }      /* no box at all */
.invisible { visibility: hidden; } /* empty space left behind */
.clear     { opacity: 0; }         /* still there, just see-through */
```


## Why it happens


The three properties work at different stages of how the browser renders a page.

- `display` controls whether a box is generated at all. With `none`, the element and all its children are taken out of layout, so the content around them moves up to fill the gap. It is also removed from the accessibility tree.
- `visibility` controls whether a box that is already laid out gets painted. The space is reserved, but nothing is drawn, pointer events do not hit it, it cannot receive focus, and it is removed from the accessibility tree.
- `opacity` controls how transparent the painted box is. At `0` it is fully see-through, but in every other way it is a normal element.

|                         | `display: none`      | `visibility: hidden` | `opacity: 0` |
| ----------------------- | -------------------- | -------------------- | ------------ |
| Takes up space          | No                   | Yes                  | Yes          |
| Receives clicks         | No                   | No                   | Yes          |
| Keyboard focusable      | No                   | No                   | Yes          |
| Read by screen readers  | No                   | No                   | Yes          |
| Children can be shown   | No                   | Yes                  | No           |
| Can transition smoothly | Only with extra work | Yes, as a step       | Yes          |


## How to fix it


### Use display: none to remove something


When content should not be there at all, such as a closed menu, an inactive tab panel or a step not yet reached, use `display: none`. The HTML `hidden` attribute does the same job and keeps the state in your markup.


```html
<div id="panel-2" role="tabpanel" hidden>...</div>
```


If your CSS sets `display` on that element, it overrides `hidden`. Add `[hidden] { display: none !important; }` to your reset if that keeps catching you out.


### Use visibility: hidden to keep the layout stable


When you need the space to stay reserved, for example a loading spinner that should not shift the button text, use `visibility: hidden`. Unlike the others, a child can override it with `visibility: visible`.


```css
.button[aria-busy="true"] .label {
  visibility: hidden;
}
```


### Use opacity for fades, and pair it with visibility


`opacity` animates smoothly, which makes it the best choice for fade effects. On its own, though, an invisible element still blocks clicks and traps keyboard users on controls they cannot see. Combine it with `visibility`, and delay the visibility change until the fade has finished.


```css
.dropdown {
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms ease, visibility 0s linear 200ms;
}

.dropdown.is-open {
  opacity: 1;
  visibility: visible;
  transition: opacity 200ms ease, visibility 0s linear 0s;
}
```


Because `visibility` is a discrete property, it flips in one step, so the delay keeps the menu visible while it fades out. Modern browsers can also animate to and from `display: none` with `transition-behavior: allow-discrete` and `@starting-style`, which is worth looking at for new code.


### Hide visually but keep it for screen readers


None of the three is right for text that should be read aloud but not shown, such as a label on an icon button. Use a visually hidden utility class instead.


```css
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
```


## Common pitfalls

- **opacity: 0 on interactive elements.** Hidden buttons and links can still be clicked and tabbed to. Add `visibility: hidden` or `pointer-events: none` plus `inert`.
- **Expecting display: none to animate.** Toggling `display` alone jumps instantly. Fade with `opacity`, or use `allow-discrete` where supported.
- **Hiding focusable content with visibility on a parent, then showing a child.** A child set to `visibility: visible` becomes visible and focusable again, which can surprise you.
- **Using display: none for screen reader text.** It hides the text from assistive technology too. Use the visually hidden class.
- **Layout shift.** Switching between `display: none` and visible moves surrounding content. If that jump is unwanted, use `visibility`.

## Related reading

- [MDN: visibility](https://developer.mozilla.org/en-US/docs/Web/CSS/visibility)
- [MDN: transition-behavior](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-behavior)
