JavaScript Tutorial

CSS Visibility

The CSS visibility property is used to control the visibility of an element. It determines whether the element is visible or hidden on the page.

Visibility Parameters

There are different parameter values for the visibility property:

Value

Description

visible

Default value. The box and its contents are visible.

hidden

The box and its content are invisible, but still affect the layout of the page.

collapse

This value causes the entire row or column to be removed from the display. This value is used for row, row group, column, and column group elements.

inherit

Specifies that the value of the visibility property should be inherited from the parent element i.e. takes the same visibility value as specified for its parent.

The style rule visibility: collapse, it removes the internal table elements, but it does not affect the layout of the table in any other way. The space normally occupied by the table elements will be filled by the subsequent siblings.

Note: If the style rule visibility: collapse; is specified for other elements rather than the table elements, it causes the same behavior as hidden.

 

CSS Visibility vs Display

The display and visibility CSS properties appear to be the same thing, but they are in fact very different from each other and sometimes confuse developers to understand.

Value

Description

visibility: hidden;

It hides the element, but it still takes up space in the layout. The child element of a hidden box will be visible if its visibility is set to visible.

display: none;

It turns off the display and removes the element completely from the document. It does not take up any space, even though the HTML for it is still in the source code. All child elements also have their display turned off, even if their display property is set to something other than none.

Input:-

 

Output:-

 


Go back to Previous Course