How to show or hide an element with visibility in CSS?

The visibility property controls the visibility of elements.
The allowed values for the visibility property:

Value Description
collapse The element isn’t visible and doesn’t occupy space.
hidden The element isn’t visible, but it still occupies space.
visible The element is visible on the page(default value).
The collapse value is only applicable to table-related elements, such as tr and td.