CSS Layout - The display Property
Note:
Setting the display property of an element only changes how the element is displayed, NOT what kind of element it is.
display: none; is commonly used with JavaScript to hide and show elements without deleting and recreating them.
The (<)script(>) element uses display: none; as default.
The display property is the most important CSS property for controlling layout.
The display property specifies if or how an element is displayed.
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:
As mentioned, every element has a default display value. However, you can override this.
Changing an inline element to a block element, or vice versa, can be useful for making the page look a specific way, and still follow the web standards.
visibility:hidden; also hides an element.
However, the element will still take up the same space as before. The element will be hidden, but still affect the layout:
Examples of block-level elements:
(1) (<)div(>) (2) (<)h1(>)- (<)h6(>) (3) (<)p(>) (4) (<)form(>) (5) (<)header(>) (6) (<)footer(>) (7) (<)section(>)
Examples of inline elements:
(1) (<)span(>) (2) (<)a(>) (3) (<)img(>)