The display property and visibility property are used to control the layout of the page. They dictate how, and if, an element is shown on the page.

The display property is often used to change the natural display manner of HTML tags. For instance, making an inline tag display as block, or vice versa.

Display

The following are some examples of using the display property.

				
					/* displays an element as a block element which starts on a new
line, and takes up the whole width of the parent element */
div {
    display: block;
}
				
			
				
					/* displays an element as an inline element which has no set
width and height and is the size of the content*/
div {
    display: inline;
}
				
			
				
					/* hides the element and collapses the space to be used by 
other elements; it will not appear and leaves no whitespace */
div {
    display: none;
}
				
			

Visibility

The following is the most common example of using the visibility property.

				
					/* hides the element but DOES NOT collapse the space, leaving
an area of whitespace the size of the hidden element */
div {
    visibility: hidden;
}
				
			

Display vs. Visibility

This is a brief comparison of how each removes an element from the page.

display: none;visibility: hidden;
Hides the element and collapses the space to be used by other elements; it will not appear and leaves no whitespaceHides the element but DOES NOT collapse the space, leaving
an area of whitespace the size of the hidden element
Good for completely hiding the element leaving no trace that it existed in that spotGood for temporarily hiding an element until the page loads and then using JavaScript to show the element (will not cause the content around it to shift as it appears)