The CSS display Property

The display property is an important CSS property for controlling layout. It specifies whether an HTML element is treated as a block or an inline element.

Every HTML element has a default display value, depending on what type of element it is. The default display value for most elements is block or inline.

The display property is used to change the default display behavior of HTML elements.


Block-level Elements

A block-level element ALWAYS starts on a new line and takes up the full width available (stretches out to the left and right as far as it can).

Examples of block-level elements:

Inline Elements

An inline element DOES NOT start on a new line and only takes up as much width as necessary.

Examples of inline elements:

Example of More Display Values

The following example demonstrates some more display values:

CSS Hide Elements

CSS display: none;

When using display: none; the element is completely hidden from the document flow and does not take up any space.

It is commonly used with JavaScript to hide or show elements without deleting and recreating them.

You can also use visibility:hidden; to hide an element.

However, with this property, the element will be hidden, but it will still take up the same space as if it was visible:

Example

CSS Display/Visibility Properties