Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSS display property

CSS display property

Example

Set different display values:

p

.ex1

{

display:

none

;

}

p

.ex2

{

display:

inline

;

}

p

.ex3

{

display:

block

;

}

p

.ex4

{

display:

inline-block

;

}

Try it »


Property definition and usage

The display property sets whether an element is treated as a block or inline element and the layout used for its children, such as flow layout, grid layout, or flex layout.

Formally, the display property sets the inner and outer display types of an element.

Default value: inline
Inherited: no
Version: CSS1
JavaScript syntax: object.style.display="inline"

/* preset values */

display

:

block

;

display

:

inline

;

display

:

inline-block

;

display

:

flex

;

display

:

inline-flex

;

display

:

grid

;

display

:

inline-grid

;

display

:

flow-root

;

/* generate boxes */

display

:

none

;

display

:

contents

;

/* two-value syntax */

display

:

block

flow

;

display

:

inline

flow

;

display

:

inline

flow-root

;

display

:

block

flex

;

display

:

inline

flex

;

display

:

block

grid

;

display

:

inline

grid

;

display

:

block

flow-root

;

/* other values */

display

:

table

;

display

:

table-row

;

/* All table elements have a value equivalent to a CSS display property */

display

:

list-item

;

/* global values */

display

:

inherit

;

display

:

initial

;

display

:

revert

;

display

:

revert-layer

;

display

:

unset

;


Browser support

The numbers in the table indicate the first browser version that supports this property.

A number immediately before -webkit-, -ms-, or -moz- indicates the first browser version that supports that prefixed property.

property
display 4.0 8.0
Partial from 5.5 3.0 3.1 7.0

Attribute values

Value Description
none This element is not displayed.
block This element is displayed as a block-level element, with line breaks before and after it.
inline Default. This element is displayed as an inline element, with no line breaks before or after it.
inline-block An inline-block element. (A value added in CSS2.1)
list-item This element is displayed as a list.
run-in This element is displayed as a block-level or inline element depending on the context.
compact CSS has a compact value, but it was removed from CSS2.1 due to lack of widespread support.
marker CSS has a marker value, but it was removed from CSS2.1 due to lack of widespread support.
table This element is displayed as a block-level table (like ), with line breaks before and after the table.
inline-table This element is displayed as an inline table (like ), with no line breaks before and after the table. ). ). ). ). ). )
table-row-group This element is displayed as a group of one or more rows (like
table-header-group This element is displayed as a group of one or more rows (like
table-footer-group This element is displayed as a group of one or more rows (like
flow-root Generates a block-level element box that establishes a new block formatting context, defining the root element of the formatting context.
table-row This element is displayed as a table row (like
table-column-group This element is displayed as a group of one or more columns (like
table-column This element is displayed as a column of cells (like
table-cell This element is displayed as a table cell (like and )
table-caption This element is displayed as a table caption (like
)
inherit Specifies that the value of the display property should be inherited from the parent element.

More examples

Example

Settings display: contents; Display:

.a

{

display:

contents

;

border:

2

px

solid

red

;

background-color:

#ccc

;

padding:

10

px

;

width:

200

px

;

}

.b

{

border:

2

px

solid

blue

;

background-color:

lightblue

;

padding:

10

px

;

}

Try it »

Example

Settings display: inherit; Display, demonstrating how to use the value of an inherited property:

body

{

display:

inline

;

}

p

{

display:

inherit

;

}

Try it »

Example

Settings display: flex; Display:

div

{

display:

flex

;

flex-direction:

row-reverse

;

}

Try it »


Related Articles

CSS Tutorial: CSS Display and visibility