This translation is incomplete. Please help translate this article from English.

The display CSS property defines the  display type of an element, which consists of the two basic qualities of how an element generates boxes. These being the outer display type defining how the box participates in flow layout  and the inner display type defining how the children of this box are laid out.

Some values of display are fully defined in their individual specifications. See the table at the end of this document for links to all relevant specifications. The full list of values is as below.

/* <display-outside> values */
display: block;
display: inline;
display: run-in;

/* <display-inside> values */
display: flow;
display: flow-root;
display: table;
display: flex;
display: grid;
display: ruby;

/* <display-outside> plus <display-inside> values */
display: block flow;
display: inline table;
display: flex run-in;

/* <display-listitem> values */
display: list-item;
display: list-item block;
display: list-item inline;
display: list-item flow;
display: list-item flow-root;
display: list-item block flow;
display: list-item block flow-root;
display: flow list-item block;

/* <display-internal> values */
display: table-row-group;
display: table-header-group;
display: table-footer-group;
display: table-row;
display: table-cell;
display: table-column-group;
display: table-column;
display: table-caption;
display: ruby-base;
display: ruby-text;
display: ruby-base-container;
display: ruby-text-container;

/* <display-box> values */
display: contents;
display: none;

/* <display-legacy> values */
display: inline-block;
display: inline-table;
display: inline-flex;
display: inline-grid;

/* Global values */
display: inherit;
display: initial;
display: unset;

Initial valueinline
Applies toall elements
Inheritedno
Mediaall
Computed valueas the specified value, except for positioned and floating elements and the root element. In both cases the computed value may be a keyword other than the one specified.
Animation typediscrete
Canonical orderthe unique non-ambiguous order defined by the formal grammar

Syntax

The display property is specified using keyword values. Keyword values are grouped into six categories:

<display-outside>
These keywords specify the element’s outer display type, which is essentially its role in flow layout.
<display-inside>
These keywords specify the element’s inner display type, which defines the type of formatting context that lays out its contents (assuming it is a non-replaced element).
<display-listitem>
The element generates a block box for the content and a separate list-item inline box.
<display-internal>
Some layout models, such as table and ruby, have a complex internal structure, with several different roles that their children and descendants can fill. This section defines those "internal" display values, which only have meaning within that particular layout mode.
<display-box>
These values define whether an element generates display boxes at all.
<display-legacy>
CSS 2 used a single-keyword syntax for the display property, requiring separate keywords for block-level and inline-level variants of the same layout mode.

"Legacy" values of display

While the Level 3 specification details two values for the display property, enabling the specification of the outer and inner display type explicitly, this is not yet well supported by browsers. However the display-legacy methods allow the same results with single keyword values, and should be favoured by developers until the two keyword values are better supported. For example, using two values you might specify an inline flex container as follows:

.container {
    display: inline flex;
}

This can currently be specified using a single value.

.container {
    display inline-flex;
}

Values

<display-outside>

These keywords specify the element’s outer display type, which is essentially its role in flow layout. They are defined as follows:

Value Description
block The element generates a block element box, generating line breaks both before and after the element when in the normal flow
inline The element generates one or more inline element boxes that do not generate line breaks before or after themselves. In normal flow, the next element will be on the same line if there is space
run-in The element generates a run-in box. If the adjacent sibling of the element defined as display: run-in box is a block box, the run-in box becomes the first inline box of the block box that follows it. 

Run-in elements act like inlines or blocks, depending on the surrounding elements. That is:
  • 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.

Note that browsers which do support the two value syntax, on finding the outer value only, such as when display: block or display: inline is specified, inner value will be set to flow. This will result in expected behavior, as if you specify an element to be block, you would expect that the children of that element would participate in block and inline normal flow layout.

In the following example, span elements (normally displayed as inline elements) are set to display: block and so break onto new lines and expand to fill their container in the inline dimension.

<span>span 1</span>
<span>span 2</span>
span {
    display: block;
    border: 1px solid rebeccapurple;
}

For more information and examples see the document Block and Inline layout in Normal Flow and Formatting Contexts explained, these guides will help you to understand how flow layout works in CSS.

<display-inside>

These keywords specify the element’s inner display type, which defines the type of formatting context that lays out its contents (assuming it is a non-replaced element). They are defined as follows:

Value Description
flow The element lays out its contents using flow layout (block-and-inline layout).

If its outer display type is inline or run-in, and it is participating in a block or inline formatting context, then it generates an inline box. Otherwise it generates a block container box.

Depending on the value of other properties (such as position, float, or overflow) and whether it is itself participating in a block or inline formatting context, it either establishes a new block formatting context for its contents or integrates its contents into its parent formatting context.

flow-root The element generates a block element box that establishes a new block formatting context, defining where the formatting root lies
table These elements behave like <table> HTML elements. It defines a block-level box.
flex The element behaves like a block element and lays out its content according to the flexbox model .
grid The element behaves like a block element and lays out its content according to the grid model .
ruby

The 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.

In this example the parent box has been given display: flow-root and so establishes a new BFC and contains the floated item.

<div class="box">
  <div class="float">I am a floated box!</div>
  <p>I am content inside the container.</p>
</div>
.box {
    background-color: rgb(224, 206, 247);
    border: 5px solid rebeccapurple;
    display: flow-root;
}

.float {
    float: left;
    width: 200px;
    height: 150px;
    background-color: white;
    border:1px solid black;
    padding: 10px;
}

Note that browsers which do support the two value syntax, on finding the inner value only, such as when display: flex or display: grid is specified, the outer value will be set to block. This will result in expected behavior, as if you specify an element to be display: grid, you would expect that the box created on the grid container would be a block level box.

<display-listitem>

The element generates a block box for the content and a separate list-item inline box.

Value Description
list-item  

<display-internal>

Some layout models, such as table and ruby, have a complex internal structure, with several different roles that their children and descendants can fill. This section defines those "internal" display values, which only have meaning within that particular layout mode.

Unless otherwise specified, both the inner display type and the outer display type of elements using these display values are set to the given keyword.

Value Description
table-row-group These elements behave like <tbody> HTML elements
table-header-group These elements behave like <thead> HTML elements.
table-footer-group These elements behave like <tfoot> HTML elements.
table-row These elements behave like <tr> HTML elements.
table-cell These elements behave like <td> HTML elements.
table-column-group These elements behave like <colgroup> HTML elements.
table-column These elements behave like <col> HTML elements.
table-caption These elements behave like <caption> HTML elements.
ruby-base These elements behave like <rb> elements.
ruby-text These elements behave like <rt> elements.
ruby-base-container These elements behave like <rbc> elements generated as anonymous boxes.
ruby-text-container These elements behave like <rtc> elements.

<display-box>

These values define whether an element generates display boxes at all.

Value Description
contents These elements don't produce a specific box by themselves. They are replaced by their pseudo-box and their child boxes. Please note that CSS Display Level 3 spec defines how the contents value should affect "unusual elements" — elements that aren’t rendered purely by CSS box concepts such as replaced elements. See Appendix B: Effects of display: contents on Unusual Elements for more details.

Due to a bug in browsers this will currently remove the element from the accessibility tree — screen readers will not look at what's inside. See the accessibility concerns section below for more details.
none

Turns off the display of an element so that it has no effect on layout (the document is rendered as though the element did not exist). All descendant elements also have their display turned off.

To have an element take up the space that it would normally take, but without actually rendering anything, use the visibility property instead.

In this first example, the paragraph with a class of secret is set to display: none, the box and any content is now not rendered.

<p>Visible text</p>
<p class="secret">Invisible text</p>
p.secret {
  display: none;
}

In this example the outer div has a 2 pixel red border and a width of 300px. However it also has display: contents specified, therefore this div will not be rendered, the border and width will no longer apply, the child element will be displayed as if the parent had never existed.

<div class="outer">
  <div>Inner div.</div>
</div>
.outer {
  border: 2px solid red;
  width: 300px;
  display: contents;
}

.outer > div {
  border: 1px solid green;
}

<display-legacy>

CSS 2 used a single-keyword syntax for the display property, requiring separate keywords for block-level and inline-level variants of the same layout mode. They are defined as follows:

Value Description
inline-block

The 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)

It is equivalent to inline flow-root.

inline-table

The inline-table value 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.

It is equivalent to inline table.

inline-flex

The element behaves like an inline element and lays out its content according to the flexbox model.

It is equivalent to inline flex.

inline-grid

The element behaves like an inline element and lays out its content according to the grid model.

It is equivalent to inline grid.

XUL values

Non-standard
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

Firefox supports the following -moz- prefixed XUL display values:

Value Description
-moz-box XUL box, mostly equivalent to flex
-moz-inline-box XUL inline box, mostly equivalent to inline-flex
-moz-grid Obsolete since Gecko 62 XUL grid
-moz-inline-grid Obsolete since Gecko 62 XUL inline grid
-moz-grid-group Obsolete since Gecko 62 XUL grid group
-moz-grid-line Obsolete since Gecko 62 XUL grid line
-moz-stack Obsolete since Gecko 62 XUL stack
-moz-inline-stack Obsolete since Gecko 62 XUL inline stack
-moz-deck Obsolete since Gecko 62 XUL deck
-moz-popup Obsolete since Gecko 62 XUL popup

All XUL display values, with the exception of -moz-box and -moz-inline-box, have been removed in bug 1288572. See this Firefox Site Compatibility post for more details.

The -moz-box and -moz-inline-box values will be removed later in bug 879275. See this Firefox Site Compatibility post for more details.

Formal syntax

[ <display-outside> || <display-inside> ] | <display-listitem> | <display-internal> | <display-box> | <display-legacy>

where
<display-outside> = block | inline | run-in
<display-inside> = flow | flow-root | table | flex | grid | ruby
<display-listitem> = <display-outside>? && [ flow | flow-root ]? && list-item
<display-internal> = table-row-group | table-header-group | table-footer-group | table-row | table-cell | table-column-group | table-column | table-caption | ruby-base | ruby-text | ruby-base-container | ruby-text-container
<display-box> = contents | none
<display-legacy> = inline-block | inline-list-item | inline-table | inline-flex | inline-grid

Accessibility concerns

display: none;

Using a display value of none or content on an element will remove it from the accessibility tree. This will cause the element and all its descendant elements to no longer be announced by screen reading technology.

If you want to visually hide the element, a more accessible alternative is to use a combination of properties to remove it visually from the screen but keep it parseable by assistive technology such as screen readers.

display: contents;

Browsers will remove any element with a display value of contents set on it from the accessibility tree. This will cause the element and all its descendant elements to no longer be announced by screen reading technology.

Tables

Changing the display value of a table element to block, grid, or flex will alter its representation in the accessibility tree . This will cause the table to no longer be announced properly by screen reading technology. 

Specifications

Specification Status Comment
CSS Display Module Level 3
The definition of 'display' in that specification.
Working Draft Added run-in, flow, flow-root, contents, and multi-keyword values.
CSS Ruby Layout Module Level 1
The definition of 'display' in that specification.
Working Draft Added ruby, ruby-base, ruby-text, ruby-base-container, and ruby-text-container.
CSS Grid Layout
The definition of 'display' in that specification.
Candidate Recommendation Added the grid box model values.
CSS Flexible Box Layout Module
The definition of 'display' in that specification.
Candidate Recommendation Added the flexible box model values.
CSS Level 2 (Revision 1)
The definition of 'display' in that specification.
Recommendation Added the table model values and inline-block.
CSS Level 1
The definition of 'display' in that specification.
Recommendation Initial definition. Basic values: none, block, inline, and list-item.

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support1121471
Multi-keyword values ? ? No No ? ?
list-item1121671
inline-block1121

8

61

71
inline-table1123871
table, table-cell, table-column, table-column-group, table-footer-group, table-header-group, table-row, and table-row-group1121871
flex

29

21 -webkit-

12

202

18 — 283

11

84

16

15 -webkit-

12.1 — 15

9

6.1 -webkit-

inline-flex

29

21 -webkit-

12

202

18 —?5

11

86

16

15 -webkit-

9

6.1 -webkit-

grid57

16

12 -ms-

5210 -ms- 744 Yes
inline-grid57

16

12 -ms-

5210 -ms- 744 ?
subgrid No No No No No No
ruby, ruby-base, ruby-base-container, ruby-text, and ruby-text-container ?12

38

34 — 388

? ? ?
run-in1 — 329 No No87 — 151 — 810
flow-root58 ?53 ?45 ?
contents

65

58 — 6511

No

37

36 — 5312

No5211.1
contents: Specific behavior of unusual elements when display: contents is applied to them ? No59 No No No
-moz-box and -moz-inline-box No No Yes13 No No No
-moz-grid, -moz-inline-grid, -moz-grid-group and -moz-grid-line No No Yes — 62 No No No
-moz-stack and -moz-inline-stack No No Yes — 62 No No No
-moz-deck No No Yes — 62 No No No
-moz-popup No No Yes — 62 No No No
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support Yes Yes124 Yes Yes Yes
Multi-keyword values ? ? ? No ? ? ?
list-item Yes Yes124 Yes Yes Yes
inline-block Yes Yes124 Yes Yes Yes
inline-table Yes Yes124 Yes Yes Yes
table, table-cell, table-column, table-column-group, table-footer-group, table-header-group, table-row, and table-row-group Yes Yes124 Yes Yes Yes
flex

29

21 -webkit-

29

25 -webkit-

12

202

18 — 283

16

14 -webkit-

12.1 — 14

9

7.1 -webkit-

Yes
inline-flex

29

21 -webkit-

29

25 -webkit-

12

202

18 —?5

16

14 -webkit-

9

6.1 -webkit-

Yes
grid5757

16

12 -ms-

5244 Yes7.0
inline-grid5757

16

12 -ms-

5244 ?7.0
subgrid No No No No No No No
ruby, ruby-base, ruby-base-container, ruby-text, and ruby-text-container ? ?12

38

34 — 388

? ? ?
run-in Yes — 329 Yes — 329 No No ? Yes — 810 ?
flow-root5858 ?5345 ?7.0
contents6565 No575211.1 No
contents: Specific behavior of unusual elements when display: contents is applied to them ? ? No59 No No ?
-moz-box and -moz-inline-box No No No Yes13 No No No
-moz-grid, -moz-inline-grid, -moz-grid-group and -moz-grid-line No No No Yes — 62 No No No
-moz-stack and -moz-inline-stack No No No Yes — 62 No No No
-moz-deck No No No Yes — 62 No No No
-moz-popup No No No Yes — 62 No No No

1. Until Internet Explorer 8, inline-block is only for natural inline elements.

2. Firefox 28 added multi-line flexbox support.

3. From version 18 until version 28 (exclusive): this feature is behind the layout.css.flexbox.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.

4. Supported as -ms-flexbox.

5. From version 18: this feature is behind the layout.css.flexbox.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.

6. Supported as -ms-inline-flexbox.

7. Internet Explorer implements an older version of the specification.

8. From version 34 until version 38 (exclusive): this feature is behind the layout.css.ruby.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.

9. Before Chrome 4, run-in was not supported before inline elements.

10. Before Safari 5, run-in was not supported before inline elements.

11. From version 58 until version 65 (exclusive): this feature is behind the Enable experimental Web Platform features preference. To change preferences in Chrome, visit chrome://flags.

12. From version 36 until version 53 (exclusive): this feature is behind the layout.css.display-contents.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.

13. Scheduled for removal (See bug 879275).

See also

Document Tags and Contributors

Contributors to this page: fabio.rahamim
Last updated by: fabio.rahamim,