Easy Tutorial
❮ Css Padding Css Dropdowns ❯

CSS Display (Display) and Visibility (Visibility)


The display property sets how an element should be displayed, and the visibility property specifies whether an element should be visible or hidden.


Hiding Elements - display:none or visibility:hidden

An element can be hidden by setting the display property to "none" or the visibility property to "hidden". However, note that these two methods produce different results.

visibility:hidden can hide an element, but the hidden element still takes up the same space as before it was hidden. This means that although the element is hidden, it still affects the layout.

Example

display:none can hide an element, and the hidden element does not take up any space. This means that not only is the element hidden, but the space it originally occupied also disappears from the page layout.

Example


CSS Display - Block and Inline Elements

A block element occupies the full width available, with line breaks before and after.

Examples of block elements:

Inline elements take up only the necessary width and do not force line breaks.

Examples of inline elements:


How to Change an Element's Display

You can change inline elements and block elements, and vice versa, allowing the page to appear combined in a specific way while still adhering to web standards.

The following example displays list items as inline elements:

Example

The following example displays a span element as a block element:

Example

Note: Changing an element's display type affects how the element is displayed, and what type of element it is. For example, an inline element set to display:block is not allowed to have nested block elements inside it.


More Examples

How to display an element as an inline element.

This example demonstrates how to display an element as an inline element.

How to display an element as a block element.

This example demonstrates how to display an element as a block element.

How to use the table's collapse property.

This example demonstrates how to use the table's collapse property.

❮ Css Padding Css Dropdowns ❯