Differences between CSS display: none; and visibility: hidden;

CSSWeb DevelopmentFront End Technology

CSS display: none; 

The display: none property is used to hide elements without deleting them. It does not take up any space.

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <style>
         h3 {
            display: none;
         }
      </style>
   </head>
   <body>
      <h2>This heading is visible</h2>
      <h3>This is a hidden heading</h3>
      <p>The hidden heading does not take up space even after hiding it since we have used display: none;.</p>
   </body>
</html>

CSS visibility: hidden;

The visibility: hidden property also hides an element, but affects the layout i.e. takes up space. Let us see an example

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <style>
         h3 {
            visibility: hidden;
         }
      </style>
   </head>
   <body>
      <h2>This heading is visible</h2>
      <h3>This is a hidden heading</h3>
      <p>The hidden heading takes up space even after hiding it.</p>
   </body>
</html>
raja
Published on 08-May-2018 09:35:01
Advertisements