HTML DOM Style visibility Property

HTMLWeb DevelopmentFront End Technology

The HTML DOM style visibility property returns and modify whether an element should be visible or not in an HTML document.

Syntax

Following is the syntax −

  • Returning visibility

object.style.visibility
  • Modifying visibility

object.style.visibility = “value”

Values

Here, value can be −

ValueExplanation
initialIt set this property value to its default value.
inheritIt inherits this property value from its parent element.
hiddenIn it the element is not visible but still its presence will affect the layout.
visibleIn it the element is visible.
collapseIn it the element in table row or column is not visible but still its presence will affect the layout.

Example

Let us see an example of HTML DOM style visibility property −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
   body {
      color: #000;
      background: lightblue;
      height: 100vh;
   }
   .btn {
      background: #db133a;
      border: none;
      height: 2rem;
      border-radius: 2px;
      width: 40%;
      display: block;
      color: #fff;
      outline: none;
      cursor: pointer;
      margin: 1rem 0;
   }
</style>
</head>
<body>
<h1>DOM Style visibility Property Example</h1>
<p>I'm paragraph element with some dummy text</p>
<button onclick="add()" class="btn">Set visibility</button>
<script>
   function add() {
      document.querySelector('p').style.visibility = "hidden";
   }
</script>
</body>
</html>

Output

This will produce the following output −

Click on “Set visibility” button to set visibility with hidden as value on paragraph element −

raja
Published on 24-Jul-2019 13:32:37
Advertisements