Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • CSS Tutorial
  • CSS Exercises
  • CSS Interview Questions
  • CSS Selectors
  • CSS Properties
  • CSS Functions
  • CSS Examples
  • CSS Cheat Sheet
  • CSS Templates
  • CSS Frameworks
  • Bootstrap
  • Tailwind
  • CSS Formatter
Open In App
Next Article:
What is the difference between visibility:hidden and display:none ?
Next article icon

What is the difference between visibility:hidden and display:none ?

Last Updated : 07 Oct, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

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.


Next Article
What is the difference between visibility:hidden and display:none ?

T

Tejashwi5
Improve
Article Tags :
  • Web Technologies
  • CSS
  • CSS-Properties
  • CSS-Questions

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
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences