Summary
The display property specifies the type of rendering box used for an element. In HTML, default display property values are taken from behaviors described in the HTML specifications or from the browser/user default stylesheet. The default value in XML is inline.
In addition to the many different display box types, the value none lets you turn off the display of an element; when you use none, all descendant elements also have their display turned off. The document is rendered as though the element doesn't exist in the document tree.
| Начальное значение | inline |
|---|---|
| Применяется к | все элементы |
| Наследуется | нет |
| Отображение | всё |
| Обработка значения | как указанное значение, кроме как для позиционированных и плавающих элементов и корневого элемента. В обоих случаях вычисляемое значение может быть ключевым словом, отличным от указанного. |
| Анимируемость | нет |
| Канонический порядок | уникальный неоднозначный порядок, определённый формальной грамматикой |
Syntax
display: none; display: inline; display: block; display: contents; display: list-item; display: inline-block; display: inline-table; display: table; display: table-cell; display: table-column; display: table-column-group; display: table-footer-group; display: table-header-group; display: table-row; display: table-row-group; display: flex; display: inline-flex; display: grid; display: inline-grid; display: ruby; display: ruby-base; display: ruby-text; display: ruby-base-container; display: ruby-text-container ; display: run-in; display: inherit display: initial display: unset
Values
display-value
- Is a keyword defining the rendering type to apply to the element. Its possible values and their meanings are:
Value set Value Description Basic values (CSS 1) noneTurns off the display of an element (it has no effect on layout); all descendant elements also have their display turned off. The document is rendered as though the element did not exist.
To render an element box's dimensions, yet have its contents be invisible, see the
visibilityproperty.inlineThe element generates one or more inline element boxes. blockThe element generates a block element box. list-itemThe element generates a block box for the content and a separate list-item inline box. Extended values (CSS 2.1) inline-blockThe element generates a block element box that will be flowed with surrounding content as if it were a single inline box (behaving much like a replaced element would) Table model values (CSS 2.1) inline-tableThe inline-tablevalue does not have a direct mapping in HTML. It behaves like a<table>HTML element, but as an inline box, rather than a block-level box. Inside the table box is a block-level context.tableThese elements behaves like <table>HTML elements. It defines a block-level box.table-captionThese elements behave like <caption>HTML elements.table-cellThese elements behave like <td>HTML elements.table-columnThese elements behave like <col>HTML elements.table-column-groupThese elements behave like <colgroup>HTML elements.table-footer-groupThese elements behave like <tfoot>HTML elements.table-header-groupThese elements behave like <thead>HTML elements.table-rowThese elements behave like <tr>HTML elements.table-row-groupThese elements behave like <tbody>HTML elementsFlexbox model values (CSS3) flexThe element behaves like a block element and lays out its content according to the flexbox model. inline-flexThe element behaves like an inline element and lays out its content according to the flexbox model. Grid box model values (CSS3) gridThe element behaves like a block element and lays out its content according to the grid model.
As this is experimental, most browsers don't support it. Especially pay attention that-moz-gridis not the prefixed version of this, but a XUL layout model that must not be used on a Web site.inline-gridThe element behaves like an inline element and lays out its content according to the grid model. Ruby formatting model values (CSS3) rubyThe element behaves like an inline element and lays out its content according to the ruby formatting model. It behaves like the corresponding <ruby>HTML elements.ruby-baseThese elements behave like <rb>elements.ruby-textThese elements behave like <rt>elements.ruby-base-containerThese elements behave like <rbc>elements generated as anonymous boxes.ruby-text-containerThese elements behave like <rtc>elements.Experimental values run-in- If the run-in box contains a block box, same as block.
- If a block box follows the run-in box, the run-in box becomes the first inline box of the block box.
- If an inline box follows, the run-in box becomes a block box.
contentsThese elements don't produce a specific box by themselves. They are replaced by their pseudo-box and their child boxes.
Formal syntax
none | inline | block | list-item | inline-list-item | inline-block | inline-table | table | table-cell | table-column | table-column-group | table-footer-group | table-header-group | table-row | table-row-group | flex | inline-flex | grid | inline-grid | run-in | ruby | ruby-base | ruby-text | ruby-base-container | ruby-text-container | contents
Examples
p.secret { display: none }
<p style="display:none"> invisible text </p>
Specifications
| Specification | Status | Comment |
|---|---|---|
| CSS Display Module Level 3 Определение 'display' в этой спецификации. |
Рабочий черновик | Added the run-in and contents values. |
| CSS Ruby Layout Module Level 1 Определение 'display' в этой спецификации. |
Рабочий черновик | Added the ruby, ruby-base, ruby-text, ruby-base-container, and ruby-text-container |
| CSS Grid Layout Определение 'display' в этой спецификации. |
Рабочий черновик | Added the grid box model values. |
| CSS Flexible Box Layout Module Определение 'display' в этой спецификации. |
Кандидат в рекомендации | Added the flexible box model values. |
| CSS Level 2 (Revision 1) Определение 'display' в этой спецификации. |
Рекомендация | Added the table model values and inline-block. |
| CSS Level 1 Определение 'display' в этой спецификации. |
Рекомендация | Basic values: none, block, inline, and list-item. |
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
|---|---|---|---|---|---|
none, inline and block |
1.0 | 1.0 (1.7 или ранее) | 4.0 | 7.0 | 1.0 (85) |
inline-block |
1.0 | 3.0 (1.9) | 5.5 [4] | 7.0 | 1.0 (85) |
list-item |
1.0 | 1.0 (1.7 или ранее) | 6.0 | 7.0 | 1.0 (85) |
run-in |
1.0 [5] | Нет | 8.0 | 7.0 | 1.0 (85) [5] |
|
4.0 Removed in 32 |
5.0 (532.5) | ||||
inline-table |
1.0 | 3.0 (1.9) | 8.0 | 7.0 | 1.0 (85) |
table, table-cell, table-column, table-column-group, table-header-group, table-row-group, table-footer-group, table-row, and table-caption |
1.0 | 1.0 (1.7 или ранее) | 8.0 | 7.0 | 1.0 (85) |
flex |
21.0-webkit | 18.0 (18.0) [1] 20.0 (20.0) |
11 | 12.50 | 6.1-webkit |
inline-flex |
21.0-webkit | 18.0 (18.0) [1] 20.0 (20.0) |
11 | 12.50 | 6.1-webkit |
grid |
? | Нет | 10.0-ms | ? | ? |
inline-grid |
? | Нет | 10.0-ms | ? | ? |
ruby, ruby-base, ruby-text, ruby-base-container, ruby-text-container |
? | 34.0 (34.0) [3] | ? | ? | ? |
contents |
Нет | 37 (37) [2] | Нет | Нет | Нет |
| Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
| Basic support | 4.4 | ? | ? | ? | 7.0-webkit |
[1] To activate flexbox support, for Firefox 18 and 19, the user has to change the about:config preference "layout.css.flexbox.enabled" to true. Multi-line flexbox are supported since Firefox 28.
[2] In Firefox 36, it the preference governing this feature was off by default.
[3] CSS Ruby support is behind pref "layout.css.ruby.enabled". The user has to change this pref to true to activate this.
[4] Natural inline elements only
[5] Not before inline-elements