IMG-LOGO

What is the difference between display:none to visibility:hidden in CSS?

andy - 21 Jan, 2019 2342 Views 0 Comment

What is the difference between display:none to visibility:hidden in CSS? Well, there is a big difference between those two CSS properties. The first one which is the display:none will not preserve or occupy any space on the web page. While the visibility:hidden will preserve and occupy the space on a page.

Let's create the following two CSS class for each CSS property and we are going to apply it to UL LI list elements, so you can actually see the differences between both properties in a real example.

<style>
	.vis-none{
		visibility:hidden;
	}
	
	.dis-none{
		display:none;
	}
</style>

Here is the html codes for our example list 1 and list 2.

<h5>Example of using .vis-none css class which will apply visibility:hidden to the li element.</h5>
<ul>
	<li>This is a first line.</li>
	<li class="vis-none">This is a second line.</li>
	<li>This is a third line.</li>
</ul>


<h5>Example of using .dis-none css class which will apply display:none to the li element.</h5>

<ul>
	<li>This is a first line.</li>
	<li class="dis-none">This is a second line.</li>
	<li>This is a third line.</li>
</ul>
Example of using .vis-none css class which will apply visibility:hidden to the li element.
  • This is a first line.
  • This is a second line.
  • This is a third line.
Example of using .dis-none css class which will apply display:none to the li element.
  • This is a first line.
  • This is a second line.
  • This is a third line.

If you see on above example, you can see the first UL LI List, the second line list still preserve the space of the hidden element. While the second example does not. If you have any question regarding with this tutorial, feel free to post your question below if you need help regarding with this tutorial.

Comments

There are no comments available.

Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.

Related Articles

How to style pagination links with CSS?

Do you need to create a beautiful, simple and elegant pagination links with css? Simply follow our easy and quick tutorial on how to create the pagination links easily with CSS.

Optimizing your site for printing

The easy way to optimize your site for printing is to create a separated external css targeting a media to print only When a printing action is being executed the browser will send over the information from your page to ...