files/en-us/web/css/reference/properties/display/index.md
The display CSS property sets whether an element is treated as a block or inline box and the layout used for its children, such as flow layout, grid or flex.
Formally, the display property sets an element's inner and outer display types. The outer type sets an element's participation in flow layout; the inner type sets the layout of children. Some values of display are fully defined in their own individual specifications; for example the detail of what happens when display: flex is declared is defined in the CSS Flexible Box Model specification.
{{InteractiveExample("CSS Demo: display")}}
display: block;
display: inline flow-root;
display: none;
display: flex;
display: grid;
<p>
Apply different <code>display</code> values on the dashed orange-bordered
<code>div</code>, which contains three child elements.
</p>
<section class="default-example" id="default-example">
<div class="example-container">
Some text A.
<div id="example-element">
<div class="child">Child 1</div>
<div class="child">Child 2</div>
<div class="child">Child 3</div>
</div>
Some text B.
</div>
</section>
.example-container {
width: 100%;
height: 100%;
}
code {
background: #88888888;
}
#example-element {
border: 3px dashed orange;
}
.child {
display: inline-block;
padding: 0.5em 1em;
background-color: #ccccff;
border: 1px solid #ababab;
color: black;
}
/* short display */
display: none;
display: contents;
display: block;
display: flow-root;
display: inline;
display: inline-block;
display: list-item;
display: inline list-item;
display: flex;
display: inline-flex;
display: grid;
display: inline-grid;
display: table;
display: inline-table;
/* full display */
display: block flow;
display: block flow-root;
display: inline flow;
display: inline flow-root;
display: block flow list-item;
display: inline flow list-item;
display: block flex;
display: inline flex;
display: block grid;
display: inline grid;
display: block table;
display: inline table;
/* global values */
display: inherit;
display: initial;
display: revert;
display: revert-layer;
display: unset;
The CSS display property is specified using keyword values.
The keyword values can be grouped into six value categories.
block
inline
[!NOTE] When a display property is specified with only an outer value (e.g.,
display: blockordisplay: inline), the inner value defaults toflow(e.g.,display: block flowanddisplay: inline flow).
[!NOTE] You may use the single-value syntax as a fallback for multi-keyword syntax, for example
display: inline flexcould have the following fallbackcss.container { display: inline-flex; display: inline flex; }See Using the multi-keyword syntax with CSS display for more information.
block (with the exception of ruby, which defaults to inline).
flow
: The element lays out its contents using flow layout (block-and-inline layout).
If its outer display type is inline, and it is participating in a block or inline formatting context, then it generates an inline box. Otherwise it generates a block box.
Depending on the value of other properties (such as {{CSSxRef("position")}}, {{CSSxRef("float")}}, or {{CSSxRef("overflow")}}) and whether it is itself participating in a block or inline formatting context, it either establishes a new block formatting context (BFC) for its contents or integrates its contents into its parent formatting context.
flow-root
table
flex
grid
ruby
[!NOTE] When a display property is specified with only an inner value (e.g.,
display: flexordisplay: grid), the outer value defaults toblock(e.g.,display: block flexanddisplay: block grid).
A single value of list-item will cause the element to behave like a list item.
This can be used together with {{CSSxRef("list-style-type")}} and {{CSSxRef("list-style-position")}}.
list-item can also be combined with any {{CSSxRef("<display-outside>")}} keyword and the flow or flow-root {{CSSxRef("<display-inside>")}} keyword.
[!NOTE] If no inner value is specified, it will default to
flow. If no outer value is specified, the principal box will have an outer display type ofblock.
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.
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
contents
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.none
display property, requiring separate keywords for block-level and inline-level variants of the same layout mode.
inline-block
: The element generates a block 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 an HTML {{HTMLElement("table")}} 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-level 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-level element and lays out its content according to the grid model.
It is equivalent to inline grid.
The CSS display module describes a multi-keyword syntax for values you can use with the display property to explicitly define outer and inner display.
The single keyword values (precomposed <display-legacy> values) are supported for backward-compatibility.
For example, using two values you can specify an inline flex container as follows:
.container {
display: inline flex;
}
This can also be specified using the legacy single value:
.container {
display: inline-flex;
}
For more information on these changes, see the Using the multi-keyword syntax with CSS display guide.
The individual pages for the different types of value that display can have set on it feature multiple examples of those values in action — see the Syntax section. In addition, see the following material, which covers the various values of display in depth.
Supporting browsers animate display with a discrete animation type. This generally means that the property will flip between two values 50% through animating between the two.
There is one exception, which is when animating to or from display: none. In this case, the browser will flip between the two values so that the animated content is shown for the entire animation duration. So for example:
display from none to block (or another visible display value), the value will flip to block at 0% of the animation duration so it is visible throughout.display from block (or another visible display value) to none, the value will flip to none at 100% of the animation duration so it is visible throughout.This behavior is useful for creating entry/exit animations where you want to for example remove a container from the DOM with display: none, but have it fade out with {{cssxref("opacity")}} rather than disappearing immediately.
When animating display with CSS animations, you need to provide the starting display value in an explicit keyframe (for example using 0% or from). See Using CSS animations for an example.
When animating display with CSS transitions, two additional features are needed:
display type changes from none to another type.transition-behavior: allow-discrete needs to be set on the {{cssxref("transition-property")}} declaration (or the {{cssxref("transition")}} shorthand) to enable display transitions.For examples of transitioning the display property, see the @starting-style and transition-behavior pages.
Using a display value of none 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 still make it available to assistive technology such as screen readers.
While display: none hides content from the accessibility tree, elements that are hidden but are referenced from visible elements' aria-describedby or aria-labelledby attributes are exposed to assistive technologies.
Current implementations in some browsers will remove from the accessibility tree any element with a display value of contents (but descendants will remain). This will cause the element itself to no longer be announced by screen reading technology. This is incorrect behavior according to the CSS specification.
In some browsers, changing the display value of a {{HTMLElement("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.
{{cssinfo}}
{{csssyntax}}
In this example we have two block-level container elements, each one with three inline children. Below that, we have a select menu that allows you to apply different display values to the containers, allowing you to compare and contrast how the different values affect the element's layout, and that of their children.
We have included {{cssxref("padding")}} and {{cssxref("background-color")}} on the containers and their children, so that it is easier to see the effect the display values are having.
<article class="container">
<span>First</span>
<span>Second</span>
<span>Third</span>
</article>
<article class="container">
<span>First</span>
<span>Second</span>
<span>Third</span>
</article>
<div>
<label for="display">Choose a display value:</label>
<select id="display">
<option selected>block</option>
<option>block flow</option>
<option>inline</option>
<option>inline flow</option>
<option>flow</option>
<option>flow-root</option>
<option>block flow-root</option>
<option>table</option>
<option>block table</option>
<option>flex</option>
<option>block flex</option>
<option>grid</option>
<option>block grid</option>
<option>list-item</option>
<option>block flow list-item</option>
<option>inline flow list-item</option>
<option>block flow-root list-item</option>
<option>inline flow-root list-item</option>
<option>contents</option>
<option>none</option>
<option>inline-block</option>
<option>inline flow-root</option>
<option>inline-table</option>
<option>inline table</option>
<option>inline-flex</option>
<option>inline flex</option>
<option>inline-grid</option>
<option>inline grid</option>
</select>
</div>
html {
font-family: "Helvetica", "Arial", sans-serif;
letter-spacing: 1px;
padding-top: 10px;
}
article {
background-color: red;
}
article span {
background-color: black;
color: white;
margin: 1px;
}
article,
span {
padding: 10px;
border-radius: 7px;
}
article,
div {
margin: 20px;
}
const articles = document.querySelectorAll(".container");
const select = document.querySelector("select");
function updateDisplay() {
articles.forEach((article) => {
article.style.display = select.value;
});
}
select.addEventListener("change", updateDisplay);
updateDisplay();
{{EmbedLiveSample('display_value_comparison','100%', 440)}}
Note that some multi-keyword values are added for illustration which have the following equivalents:
block = block flowinline = inline flowflow = block flowflow-root = block flow-roottable = block tableflex = block flexgrid = block gridlist-item = block flow list-iteminline-block = inline flow-rootinline-table = inline tableinline-flex = inline flexinline-grid = inline gridYou can find more examples in the pages for each separate display type under Grouped values.
{{Specifications}}
{{Compat}}