CSS display property

December 22, 2019

CSS Layout - The display Property

The display property is the most important CSS property for controlling layout. 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.

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:

<h1> - <h6>

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:


Display: none

display: none; is commonly used with JavaScript to hide and show elements without deleting and recreating them.

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:

h1.hidden {
  display: none;

visibility:hidden; also hides an element. However, the element will still take up the same space as before.

CSS display property

CSS Syntax

display: Value;

inlineDisplays an element as an inline element (like <span>). Any height and width properties will have no effect
blockDisplays an element as a block element (like <p>). It starts on a new line, and takes up the whole width
contentsMakes the container disappear, making the child elements children of the element the next level up in the DOM
flexDisplays an element as a block-level flex container
gridDisplays an element as a block-level grid container
inline-blockDisplays an element as an inline-level block container. The element itself is formatted as an inline element, but you can apply height and width values
inline-flexDisplays an element as an inline-level flex container
inline-gridDisplays an element as an inline-level grid container
inline-tableThe element is displayed as an inline-level table
list-itemLet the element behave like a <li> element
noneThe element is completely removed