visibility Attribute | visibility Property
Gets or sets whether the content of the object is displayed.
Syntax
CSS { visibility : sVisibility } Scripting [ sVisibility = ] object.style.visibility
Possible Values
sVisibility String that specifies or receives one of the following values. The property is read/write for all objects except the following, for which it is read-only: currentStyle. The property has a default value of inherit. The Cascading Style Sheets (CSS) attribute is not inherited.
DHTML expressions can be used in place of the preceding value(s). As of Internet Explorer 8, expressions are supported in IE7 Standards mode and IE5 (Quirks) mode only. For more information, see About Dynamic Properties and Defining Document Compatibility.
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. You can change the visibility through scripting to show and hide overlapping content based on user interaction. For document style scripting information, see Introduction to Dynamic Styles.
As of Microsoft Internet Explorer 5, a child object can be
visiblewhen its parent ishidden. With Internet Explorer 4.0, the parent object must bevisiblefor a child object to bevisible.
Examples
The following examples use the visibility attribute and the visibility property to determine whether the object is visible.This example uses two calls to an embedded (global) style sheet to hide and then show the image when the user moves the mouse over and off the text.
<head> <style> .vis1 { visibility: visible; } .vis2 { visibility: hidden; } </style> </head> <body> <img id="oSphere" src="sphere.jpg" alt="sphere"> <p onmouseover="oSphere.className='vis2'" onmouseout="oSphere.className='vis1'"> Mouseover this text to make the sphere disappear.</p> </body>Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/visibility_h.htm
This example uses a call to a function to hide the image.
<head> <script type="text/javascript"> function disappear() { oSphere.style.visibility="hidden"; } function reappear() { oSphere.style.visibility="visible"; } </script> </head> <body> <img src="sphere.jpeg" id="oSphere"> <p id="oTxt" onmouseover="disappear()" onmouseout="reappear()">Move the mouse over this text to make the sphere disappear.</p> </body>Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/visibility_s.htm
Standards Information
This property is defined in Cascading Style Sheets (CSS), Level 2 (CSS2).
Applies To
A, ADDRESS, APPLET, B, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, CSSStyleDeclaration, currentStyle, CUSTOM, DD, defaults, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET, FORM, hn, HR, HTML, I, IFRAME, IMG, INPUT type=button, INPUT type=checkbox, INPUT type=file, INPUT type=image, INPUT type=password, INPUT type=radio, INPUT type=reset, INPUT type=submit, INPUT type=text, ISINDEX, KBD, LABEL, LEGEND, LI, LISTING, MARQUEE, MENU, NOBR, OBJECT, OL, P, PRE, runtimeStyle, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, style, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP, CSSCurrentStyleDeclaration Constructor, CSSRuleStyleDeclaration Constructor, CSSStyleDeclaration Constructor