English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS Reference Manual

CSS @rules

Comprehensive List of CSS Attributes

CSS display property usage and examples

The CSS display property specifies the type of box generated by the element.

The table below provides usage instructions and version history for this property, as well as the syntax for using it in JavaScript scripts.

Default Value:inline
Applies to:All elements
Inheritance:None
Animated:No.See also Animation Properties.
Version:CSS 1,2,3
JavaScript Syntax:object.style.display="block"

Usage Instructions

  • The computed value of the display property may differ from the root element andfloatingorAbsolutely positioned elementsof different specified values.

  • If the value of the display property is set to none, the element does not generate any box and has no effect on the layout; the element and its content are completely removed from the formatting structure, and the document is presented as if the element does not exist in the document tree.

Display Usage Syntax

The syntax of this property is as follows:

display: inline | block | contents | flex | flow | flow-root | grid | inline-block | inline-flex | inline-grid | inline-table | list-item | run-in | table | table-caption | table-column-group | table-header-group | table-footer-group | table-row-group | table-cell | table-column | table-row | none | initial | inherit

The following examples demonstrate how to use the display property.

  div {
   display: inline;
  }
  span {
   display: block;
  }
Test to see‹/›

Property Value

The table below describes the value of this property.

valuedescription
inlineelement generates ainline-levelboxes.
blockelement generates ablock-levelboxes.
contentselement itself does not generate any box, but its childrenelementandpseudo-elementbox, and the text runs normally.
flexelement generates a block-levelFlexible container box.
flowelement uses flow layout (block and inline layout) to layout its content.
flow-rootelement generates a block container box and uses flow layout to layout the content.
gridelement generates a block-level grid container box.
inline-blockelement generates a block box, whose layout is like an embedded box.
inline-flexelement generates an inline-level flex container box.
inline-gridelement generates an inline-level grid container box.
inline-tableThis element behaves like a table, like an inline box.
list-itemelement generates a block box for content and a separate inline box for list markers.
run-inThis element generates a block or inline box depending on the context.
tableThe behavior of this element is similar to<table>HTML element.
table-captionThe behavior of this element is similar to<caption>HTML element.
table-column-groupThe behavior of this element is similar to<colgroup>HTML element.
table-header-groupThe behavior of this element is similar to<thead>HTML element.
table-footer-groupThe behavior of this element is similar to<tfoot>HTML element.
table-row-groupThe behavior of this element is similar to<tbody>HTML element.
table-cellThe behavior of this element is similar to<td>HTML element.
table-columnThe behavior of this element is similar to<col>HTML element.
table-rowThe behavior of this element is similar to<tr>HTML element.
noneClose the display of the element. Even if all the display attributes of the child elements are set to none, the display will also be closed.
initialSet this attribute to its default value.
inheritIf specified, the associated elements will adopt the display attribute value of their parent element.

Browser compatibility

Browser compatibility of the display attribute of browsers, the numbers in the following table indicate the minimum version number of browsers that support this attribute; all mainstream browsers support this attribute.

  • Firefox 1+

  • Google Chrome1+

  • Internet Explorer 4+

  • Apple Safari 1+

  • Opera 7+

Warning:values, such as contents, flow-root, run-in and others are not well supported in most browsers. It is best to avoid using them temporarily.

For further reading

Please refer to the following tutorials:CSS Display.

Related attributes:visibility,float,position.