CSS: Display Property

By Xah Lee. Date: . Last updated: .

The display property

The display property lets you specify the layout model of an element.

Two-value syntax (new since 2024)

display: outer inner;

.x {
 /* classic block */
 display: block flow;

 /* classic inline */
 display: inline flow;

 /* classic inline-block */
 display: inline flow-root;

 /* classic flex */
 display: block flex;

 /* classic inline-flex */
 display: inline flex;

 /* classic grid */
 display: block grid;

 /* classic inline-grid */
 display: inline grid;

 /* classic flow-root */
 display: block flow-root;
}

.x {
 /* no two-value equivalent */
 display: none;
 display: contents;
}

Outer display Values

block
Element starts on a new line and takes full width
inline
Element flows with text.

Inner display Values

flow
Normal document flow (block + inline)
flow-root
Creates a new Block Formatting Context (BFC)
flex
CSS: Flexbox Layout
grid
CSS: Grid Layout
table
CSS: display: table (emulate HTML table)

Special value: none, contents

display: contents

pretent the tag does not exist, only its children or the inner text.

🟢 tip: this is great to “remove” an extra html container element.

display: none

as if the element (and its children) does not exist.

Legacy one-value shortcuts

The one-value form are older syntax since 1990s.

The one-value form is now considered shortcuts since the intro of two-value form. They are not going to be removed.

Legacy value Equivalent
block block flow
inline inline flow
inline-block inline flow-root
flex block flex
inline-flex inline flex
grid block grid
inline-grid inline grid
flow-root block flow-root
none no equivalent
contents no equivalent

Example. Legacy fallback

.box {
 /* legacy syntax as fallback. */
 display: inline-flex;

 /* modern syntax. */
 display: inline flex;
}

Display values examples

display: block flow

.card {
 display: block flow;
}

display: inline flow

.badge {
 display: inline flow;
}

display: inline flow-root

.button {
 display: inline flow-root;
 padding: 0.6em 1.2em;
 width: 120px; /* has width! */
}

display: block flex

.navbar {
 display: block flex;
 gap: 16px;
}

display: block grid

.gallery {
 display: block grid;
 grid-template-columns: 1fr 1fr 1fr;
}

display: block flow-root

.clearfix-box {
 display: block flow-root;
 /* Better than the old overflow: hidden clearfix trick. */
}

display: none

.hidden {
 display: none; /* completely removed from layout and accessibility tree */
}

display: contents

.wrapper {
 display: contents;
 /* element disappears, children promote to parent.
 great for removing a extra container element. */
}

Useful for accessibility or semantic wrappers you don’t want affecting layout.

browser support

the 2-values form are supported by all major browsers since 2024.