CSS Visibility

The CSS visibility property specifies whether an element is visible or hidden.

 

Controlling the Visibility of Elements

The visibility property lets you control whether an element is visible or not. The CSS visibility property can take one of the following values listed in the table below:

Value Description
visible It is the default value, and the box and its contents are visible.
hiddenAlthough the box and its content are invisible, they still affect the page's layout.
collapse 

Using this value, you can removeUsing this value, you can remove the entire row or column from the display. 

This value is used for a row, row group, column, and column group elements. the entire row or column from the display. 

This value is used for a row, row group, column, and column group elements.

inherit 

Specifies thSpecifies that the visibility property's value should be inherited from the parent element, 

i.e., it should take the same visibility value as specified for its parent.at the visibility property's value should be 

inherited from the parent element, i.e., it should take the same visibility value as specified for its parent.

The style rule visibility: collapse; however, the internal table elements are removed, but it does not affect the table's layout in any other way. The subsequent siblings will fill the space normally occupied by the table elements.

Note: If the style rule visibility: collapse; is defined for other elements instead of the elements of the table, it causes the same behavior as hidden.

 

CSS Visibility vs Display

Although the display and visibility CSS properties appear to be the same, they are still very different and may confuse those who are new to web development.

  • Visibility: hidden; Although it hides the element, it still takes up space in the layout. The hidden box's child element will be visible if their visibility is set to visible. 
  • Display: none; It turns off the display and deletes the element from the document. Furthermore, it will not take up any space, although its HTML is still in the source code. Also, the display is turned off for all child elements, even if their display property is set to something other than none.