English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS Reference Manual

CSS @rules (RULES)

Comprehensive List of CSS Properties

CSS visibility attribute usage and examples

The visibility attribute specifies whether an element is visible.

The following table provides usage instructions and version history of this attribute, as well as the syntax of its usage in JavaScript scripts.

Default value:visible
Applies to:All elements
Inheritance:Yes
Animatable:Yes.Please refer to Animation properties.
Version:CSS 2、3
JavaScript syntax:object.style.visibility="hidden"

Syntax of visibility usage

The syntax of this attribute is as follows:

visibility: visible | hidden | collapse | initial | inherit

The following example demonstrates how to use the visibility attribute.

  p {
   visibility: hidden;
  }
  div {
   visibility: hidden;
  }
Test to see‹/›

Attribute value

The following table describes the values of this attribute.

ValueDescription
visibleThe box and its content are visible. This is the default value.
hiddenThe box and its content are invisible but still affect the page layout.
collapse

Only applies to some internal table objects: rows, row groups, columns, and column groups. It deletes the object but does not affect the table layout in any other way. The space occupied by the table object will be filled by the subsequent same-level objects.

If collapse is specified for other elements, its behavior is the same as hidden.

initialSet this attribute to its default value.
inheritIf specified, the associated elements adopt the visibility attribute value of their parent element.

Browser compatibility

The compatibility of visibility attribute in browsers, the numbers in the following table represent the minimum version number of browsers that support this attribute; all mainstream browsers support this attribute.

  • Firefox 1+

  • Google Chrome1+

  • Internet Explorer 4+

  • Apple Safari 1+

  • Opera 4+

Read more

Please refer to the following tutorials:CSS visibility,CSS display.

Related properties:display.