🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to CSS Notes
Topic #66

Visibility / Hide


CSS display: none;

When using display: none; the element is completely hidden from the document flow and does not take up any space.

It is commonly used with JavaScript to hide or show elements without deleting and recreating them.

Click to show hidden panel

This panel contains a

element, which is hidden by default, with display: none.

We use JavaScript to show it (change it to display: block).

Example

  <style>
#panel {
  display:
  none;
}
</style>

<script>
function myFunction() {

  document.getElementById("panel").style.display = "block";
}
</script>

Example

  <style>
#panel {
  display:
  none;
}
</style>

<script>
function myFunction() {

  var x = document.getElementById("panel");
  if (x.style.display ===
  "none") {
    x.style.display = "block";
  } else {

  x.style.display = "none";
  }
}

  </script>

Hide an Element - Use display:none or visibility:hidden?

Hiding an element can be done by setting the display property to none. The element will be hidden, and the page will be displayed as if the element is not there:

Example

h1.hidden {
  display: none;
}

You can also use visibility:hidden; to hide an element.

However, with this property, the element will be hidden, but it will still take up the same space as if it was visible:

Example

h1.hidden {
  visibility: hidden;
}

CSS Display/Visibility Properties

Property Description
display Specifies how an element should be displayed
visibility Specifies whether or not an element should be visible

Want to go beyond the notes?

Join CodingNow 2.0's CSS course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Visibility / Hide – FAQs

Quick answers about learning Visibility / Hide in CSS.

This free note from CodingNow 2.0 explains Visibility / Hide in CSS — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every CSS topic on CodingNow 2.0, including Visibility / Hide, is 100% free with no signup required.
With focused practice, most students grasp Visibility / Hide in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now