asp.net.ph

Skip Navigation Links

visibility Attribute | visibility Property

CSS Attributes Index   Positioning Properties


Sets or retrieves whether the content of the object is displayed.

Syntax


CSS { visibility: 'inherit' | 'visible' | 'hidden' }
Script object.style.visibility = sVisibility ]

Possible Values


inherit Object inherits the visibility of the next parent object.
visible The object is visible.
hidden The object is hidden.

The property is read/write with a default value of inherit; the CSS attribute is not inherited, unless the value is set to inherit.

Remarks

Unlike display: none, objects that are not visible still reserve the same physical space in the content layout as they would if they were visible. Changing the visibility through scripting is useful for showing and hiding overlapping content based on user interaction. Note that for a child object to be visible, the parent object must also be visible. See Dynamic Styles for document style scripting information.

Example

The following examples demonstrate use of inline event handlers to dynamically set whether the content of an element is visible. Both methods yield the same effect.

The sample below defines visibility style attributes in an embedded stylesheet, and invokes calls to the stylesheet to hide or show an element in response to mouse events.

<style type="text/css">
   .vis { visibility: visible }
   .hid { visibility: hidden }
</style>
...
<p onmouseover="theImg.className='hid'" onmouseout="theImg.className='vis'"> ... </p>

<img id="theImg" src="imgs/sample.jpg">

 Show me 

The sample below uses inline event handlers to dynamically set an object’s visibility property in response to mouse events.

<script language="JavaScript">
function disappear ( ) {
   theImg.style.visibility = "hidden";
}
function reappear ( ) {
   theImg.style.visibility = "visible";
}
</script>

<body onclick="reappear ( )" ondblclick="disappear ( )">
...
<img style="visibility:hidden" src="sample.jpg">

 Show me 

See Also

display, Showing and hiding objects in different browsers



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note