Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Hide or show HTML elements using visibility property in JavaScript

  • Last Updated : 02 Mar, 2021

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: = 'hidden'; = 'visible';



<!DOCTYPE html>
        .container {
            height: 80px;
            width: 250px;
            border: 2px solid black;
            background-color: green;
            color: white;
    <div class="container">
        Click the buttons to show or hide the green box
    <button onclick="showElement()">
            Show Element
    <button onclick="hideElement()">
            Hide Element
    <script type="text/javascript">
        function showElement() {
            element = document.querySelector('.container');
   = 'visible';
        function hideElement() {
            element = document.querySelector('.container');
   = 'hidden';




Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!