Hide or show HTML elements using visibility property in JavaScript Last Updated : 20 Dec, 2023 Comments Improve Suggest changes Like Article Like Report The visibility property is used to hide or show the content of HTML elements. The visibility property specifies that the element is currently visible on the page. The 'hidden' value can be used to hide the element. This hides the element but does not remove the space taken by the element, unlike the display property. Syntax:element.style.visibility = 'hidden';element.style.visibility = 'visible';Example: This example shows the visibility shown and hidden for a div. html <!DOCTYPE html> <html> <head> <style> .container { height: 80px; width: 250px; border: 2px solid black; background-color: green; color: white; } </style> </head> <body> <div class="container"> <h1>GeeksforGeeks</h1> </div> <p> Click the buttons to show or hide the green box </p> <button onclick="showElement()"> Show Element </button> <button onclick="hideElement()"> Hide Element </button> <script type="text/javascript"> function showElement() { element = document.querySelector('.container'); element.style.visibility = 'visible'; } function hideElement() { element = document.querySelector('.container'); element.style.visibility = 'hidden'; } </script> </body> </html> Output: Comment More info S sayantanm19 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Properties Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings6 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in Javascript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)9 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readJavascript Scope3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like