CSS: Display Property

By Xah Lee. Date: . Last updated: .

CSS display property lets you control layout.

It is one of the most powerful property for layout, but is complex to understand.

Here's the basics.

There are 2 major types of “rendering box” for a HTML element:

Simple Example

Here's a example of changing list items as inline.

Here's a list, without style:

<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>

Here's the same list, but each li set to display:inline:

<ul>
<li style="display:inline">one</li>
<li style="display:inline">two</li>
<li style="display:inline">three</li>
</ul>

What's Rendering Box Type?

The details are fairly complex, but basically it's like this.

Each element, has a “rendering box type”.

The “rendering box type” determines 2 things:

  1. How it is positioned with respect to its neighbor elements. e.g. block level (like a paragraph p), inline (like a bold b word in a sentence.), table (like block but width does not span the window width, it's shrink wrapped to the table's content's width, which is automatically computed by default.), and others.
  2. How it is children elements behave. e.g. table, ul (list), their child elements all have special type of rendering box.

Display Property Values

Here's complete list of values for display.

⭐ means it's not widely supported by browsers yet.

display-outside

These controls their layout with respect to neighbor elements.

display-legacy

display-inside

These controls the layout of their child elements.

display-outside and display-inside

display-listitem

display-internal

display-box

Universal CSS Property Values

Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.