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.


Following is the syntax −

  • Returning visibility
  • Modifying visibility = “value”


Here, value can be −

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.


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

 Live Demo

<!DOCTYPE html>
   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;
<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>
   function add() {
      document.querySelector('p').style.visibility = "hidden";


This will produce the following output −

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

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