CSS
HTML
JavaScript
jQuery
PHP
SQL
WordPress
CSS Tutorials

Overview

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)

We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.

CSS
HTML
JavaScript
jQuery
PHP
SQL
WordPress

Why 1SMARTchicken?

This site was built and is maintained to benefit my autistic son.
See More →

My Son's Name is Johnny

He was diagnosed as autistic quite late, at age four...
His story

Buy Me a Coffee

Thanks for your support!

Feedback

If you see an error on the page or the code itself is incorrect or incomplete, or just plain wrong, please let us know. We’re always learning. NOTE: we do not sell your information and will not send you spam emails.