visibility
Quick Summary for visibility
The visibility CSS property shows or hides an element without changing the layout of a document. The property can also hide rows or columns in a <table>.
Code Usage for visibility
/* Keyword values */ visibility: visible; visibility: hidden; visibility: collapse;  /* Global values */ visibility: inherit; visibility: initial; visibility: revert; visibility: unset; 
More Details for visibility

visibility

The visibility CSS property shows or hides an element without changing the layout of a document. The property can also hide rows or columns in a <table>.

To both hide an element and remove it from the document layout, set the display property to none instead of using visibility.

Syntax

/* Keyword values */ visibility: visible; visibility: hidden; visibility: collapse;  /* Global values */ visibility: inherit; visibility: initial; visibility: revert; visibility: unset; 

The visibility property is specified as one of the keyword values listed below.

Values

visible

The element box is visible.

hidden

The element box is invisible (not drawn), but still affects layout as normal. Descendants of the element will be visible if they have visibility set to visible. The element cannot receive focus (such as when navigating through tab indexes).

collapse

The collapse keyword has different effects for different elements:

For <table> rows, columns, column groups, and row groups, the row(s) or column(s) are hidden and the space they would have occupied is removed (as if display: none were applied to the column/row of the table). However, the size of other rows and columns is still calculated as though the cells in the collapsed row(s) or column(s) are present. This value allows for the fast removal of a row or column from a table without forcing the recalculation of widths and heights for the entire table. Collapsed flex items and ruby annotations are hidden, and the space they would have occupied is removed. For other elements, collapse is treated the same as hidden.

Accessibility concerns

Using a visibility value of hidden on an element will remove it from the accessibility tree. This will cause the element and all its descendant elements to no longer be announced by screen reading technology.

Interpolation

Visibility values are interpolated between visible and not-visible. One of the start or ending values must therefore be visible or no interpolation can happen. The value is interpolated as a discrete step, where values of the timing function between 0 and 1 map to visible and other values of the timing function (which occur only at the start/end of the transition or as a result of cubic-bezier() functions with y values outside of [0, 1]) map to the closer endpoint.

Notes

Support for visibility: collapse is missing or partially incorrect in some modern browsers. It may not be correctly treated like visibility: hidden on elements other than table rows and columns. visibility: collapse may change the layout of a table if the table has nested tables within the cells that are collapsed, unless visibility: visible is specified explicitly on nested tables.

Formal definition

Initial valuevisible
Applies toall elements
Inheritedyes
Computed valueas specified
Animation typea visibility

Formal syntax

visible | hidden | collapse

Examples

Basic example

HTML
<p class="visible">The first paragraph is visible.</p> <p class="not-visible">The second paragraph is NOT visible.</p> <p class="visible">The third paragraph is visible. Notice the second paragraph is still occupying space.</p> 
CSS
.visible {   visibility: visible; }  .not-visible {   visibility: hidden; } 

Table example

HTML
<table>   <tr>     <td>1.1</td>     <td class="collapse">1.2</td>     <td>1.3</td>   </tr>   <tr class="collapse">     <td>2.1</td>     <td>2.2</td>     <td>2.3</td>   </tr>   <tr>     <td>3.1</td>     <td>3.2</td>     <td>3.3</td>   </tr> </table> 
CSS
.collapse {   visibility: collapse; }  table {   border: 1px solid red; }  td {   border: 1px solid gray; } 

Specifications

Specification
Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification # visibility

See also

display Select your preferred language English (US)DeutschEspañolFrançais日本語한국어Português (do Brasil)Русский中文 (简体) Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote
“We ought to take outdoor walks in order that the mind may be strengthened and refreshed by the open air and much breathing.".
Seneca
Random CSS Property

margin-left

The margin-left CSS property sets the margin area on the left side of an element. A positive value places it farther from its neighbors, while a negative value places it closer.
margin-left css reference