Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Box Model and Sizing

The visibility property

Reference for the CSS visibility property: hide an element while keeping its space in the layout. Values, comparison with display: none and opacity, examples.

The visibility property controls whether an element is drawn. An element with visibility: hidden is invisible, but it still takes up exactly the space it would have taken, so nothing around it moves. This is the main difference from display: none, which removes the element from the layout entirely.

CSS
.placeholder {
  visibility: hidden;
}

Try it

Hidden, but still taking space

The first row has an empty slot where B would be. The second row closes the gap. In the third, the parent is hidden but the child is switched back to visible, so only the child shows.

Syntax

CSS
visibility: visible | hidden | collapse
  • Initial value: visible
  • Applies to: all elements
  • Inherited: yes
  • Animatable: yes, as a discrete step that flips between visible and hidden (so visible is used for the whole transition when one end is visible)
  • Computed value: as specified

Values

Value Description
visible The element is drawn normally.
hidden The element is invisible but still affects layout. It does not receive pointer events and is removed from the accessibility tree.
collapse For table rows, row groups, columns and column groups, removes the row or column without changing the table's other dimensions. On flex items it acts like hidden.

Usage notes

  • Inheritance lets children opt back in. Because it is inherited, a descendant with visibility: visible shows even inside a hidden parent.
  • Hidden means unreachable. Hidden elements cannot be focused, clicked or read by screen readers, which makes visibility: hidden a good way to hide off-screen menus without extra work.
  • Compared with opacity: 0. An element with zero opacity is still clickable, focusable and announced. Use visibility (or inert) when it should be inaccessible too.
  • Compared with display: none. Use none when the space should disappear. Use hidden to avoid layout shift.
  • Fading out properly. To fade an element out and then make it unreachable, transition opacity and visibility together; visibility flips at the end of the fade when going to hidden.
  • Visually hidden text for screen readers needs a different technique (a clipped, absolutely positioned element), not visibility: hidden.

Browser support

Supported in every browser. The collapse value for table rows and columns works in all current browsers.