What is the difference between visibility:hidden and display:none ?
Last Updated : 07 Oct, 2021
Both the visibility & display property is quite useful in CSS. The visibility: "hidden"; property is used to specify whether an element is visible or not in a web document but the hidden elements take up space in the web document. The visibility is a property in CSS that specifies the visibility behavior of an element. The display property in CSS defines how the components( such as div, hyperlink, heading, etc) are going to be placed on the web page. The display: "none" property is used to specify whether an element exists or not on the website.
Visibility property: This property is used to specify whether an element is visible or not in a web document but the hidden elements take up space in the web document.
Syntax:
visibility: visible| hidden | collapse | initial | inherit;
Property Values:
- visible: It is used to specify the element to be visible. It is a default value.
- hidden: Element is not visible, but it affects layout.
- collapse: It hides the element when it is used on a table row or a cell.
- initial: It sets the visibility property to its default value.
- inherit: This property is inherited from its parent element.
Display property: The Display property in CSS defines how the components(div, hyperlink, heading, etc) are going to be placed on the web page.
Syntax:
display: none | inline | block | inline-block;
Property Values:
- none: It will not display any element.
- inline: It is the default value. It renders the element as an inline element.
- block: It renders the element as a block-level element.
- inline-block: It renders the element as a block box inside an inline box.
So, the difference between display: "none"; and visibility: "hidden"; right from the name itself we can tell the difference as display: "none"; completely gets rids of the tag, as it had never existed in the HTML page whereas visibility: "hidden"; just makes the tag invisible, it will still on the HTML page occupying space it's just invisible.
Example: This example illustrates the use of the visibility property & display property in CSS.
HTML <!DOCTYPE html> <html> <head> <title> Difference between display:"none"; and visibility: "hidden"; </title> </head> <body> <center> <h1 style="color:green;"> GeeksforGeeks </h1> <h3> display:"none"; and visibility: "hidden"; </h3> <div class="display"> <b> display: <span style="display:none"> display:none </span> "none"; </b> </div> <br> <div class="visibility"> <b> visibility: <span style="visibility:hidden"> visibility:hidden </span> "hidden"; </b> </div> <p> You can see that the display: "none"; don't have any blank space and visibility: "hidden": has the blank space. </p> </center> </body> </html>
Output: In the visibility span, the tag still exists as you can see space between, whereas as display got rid of the tag.

Display and Visibility in JavaScript:
Syntax:
display = "none";
document.getElementById("Id").style.display = "none";
visibility = "hidden";
document.getElementById("Id").style.visibility = "hidden";
Example: This example illustrates the use of display property & visibility property in Javascript.
HTML <!DOCTYPE html> <html> <head> <style> .container { width: 800px; height: 200px; border: 2px solid black; } .right { float: right; margin: 10px; } .left { float: left; margin: 10px; } #geek { width: 200px; height: 55px; background-color: yellow; } #geek1 { width: 200px; height: 55px; background-color: purple; } </style> </head> <body> <center> <h1 style="color:green"> GeeksforGeeks </h1> <b> Effect of <code>display:"none"</code> and <code>visibility="hidden"</code> </b> <br> <div class="container"> <div class="right"> <div id="geek1"> On clicking the below button this div tag still exists but invisible. </div> <br> <button onclick="visibility()"> visibility="hidden" </button> <p> This line will be still and won't go up as the <br>above div tag still exists but invisible. </p> </div> <div class="left"> <div id="geek"> On clicking the below button this div tag won't exist. </div> <br> <button onclick="display()">display="none"</button> <p>This line will go up as the above div tag none.</p> </div> </div> </center> <script> function display() { document.getElementById("geek").style.display = "none"; } function visibility() { document.getElementById("geek1").style.visibility = "hidden"; } </script> </body> </html>
Output: From the below output, when the display button is clicked then the whole page shifts upward & occupying the space of the deleted <div> tag while when the visibility button is clicked, it doesn't shift as the <div> tag still exists in invisible form.
Similar Reads
What is the difference between display:inline-flex and display:flex in CSS ? In this article, we will see the display property & its values, i.e. the inline-flex & flex, in order to specify the display behavior of an element, along with understanding their basic differences & will illustrate them through the examples. Both CSS display: inline-flex and display: fl
3 min read
What is the difference between display: inline and display: inline-block in CSS? The display property in CSS is a very useful and commonly used property that contains many values. The display property defines how an HTML element should be displayed on the webpage. The property also specifies the type of box used for an HTML element and how it should be laid out on the page. If w
4 min read
Difference between disabled and readonly attribute in HTML In this article, we will see the basic difference between the disabled & readonly attributes in HTML, along with understanding through the basic examples. Both disabled and readonly attributes in HTML are used to restrict user input in form fields. They only differ in how they restrict input and
3 min read
Difference between 'hidden' and 'aria-hidden' attributes in HTML The HyperText Markup Language (HTML) is a powerful web development tool combined with CSS and JavaScript. Apart from these, HTML also uses Accessible Rich Internet Application (ARIA) to make web content affable for a person with disabilities. Although ARIA is beneficial, there are keywords common to
2 min read
What is default visibility for properties/methods in Typescript classes ? In Typescript, by default, the visibility of all properties or methods in Typescript classes is "public". A method with which is public can be accessed from anywhere, it has no restrictions. There are three types of member visibilities: public, private and protected. Example 1: Class with public mem
4 min read