CSS Property: visibility
[this page | pdf | back links]
The CSS (CSS2) visibility property indicates whether
an element is visible or not. Note: Invisible (hidden)
elements still take up some space on a page; if you want to avoid this then set
the display
property to none.
Valid property values
(other than inherit
and initial) are:
Value
|
Description
|
collapse
|
Only applies to table
elements. Row or column is removed, but table layout is otherwise left
unaltered. For non-table elements is equivalent to "hidden"
|
hidden
|
Element is hidden (but
still takes up space)
|
visible
|
(default value). Element
is visible
|
Default Value:
|
visible
|
JavaScript syntax:
|
e.g. object.style.visibility="hidden"
|
Inherited:
|
No
|
Animatable:
|
Yes
|
EXAMPLE:
HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
div {border: 2px solid red; width: 100px; height: 30px; background-color: yellow}
.x1 {visibility: hidden;}
</style>
</head>
<body>
1. Element with default property<br>
<div><span>1</span></div><br>
2. Property set using HTML<br>
<div><span class="x1">2</span></div><br>
3. Property set using JavaScript<br>
<div><span id="x2">3</span></div>
<script>
document.getElementById("x2").style.visibility = "hidden";
</script>
</body>
</html>
|
FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedCSSPropertyVisibility() {
var x = document.createElement("DIV"); x.style.visibility = "hidden"; return (window.getComputedStyle(x, null).visibility == "hidden");
} |
NAVIGATION LINKS
Contents | Prev | Next | CSS Properties