The display property is one of those CSS properties and we are going to take advantage of this property to accomplish our goal.
In the following example, we have a button element and a div element. Upon click of a button, we will toggle the visibility of the div element. Please have a look over the code example and the steps given below.
HTML & CSS
We have 2 elements in the HTML file (button and div).
The button element has “Toggle” as innerText.
We have done some basic styling using CSS and added the link to our style.css stylesheet inside the head element.