e01.org

`display` CSS property

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.

The **`display`** [CSS](/docs/Web/CSS) property sets whether an element is treated as a [block or inline box](/docs/Web/CSS/Guides/Display/Flow_layout) and the layout used for its children, such as [flow layout](/docs/Web/CSS/Guides/Display/Flow_layout), [grid](/docs/Web/CSS/Guides/Grid_layout) or [flex](/docs/Web/CSS/Guides/Flexible_box_layout).

Formally, the **`display`** property sets an element's inner and outer _display types_. The outer type sets an element's participation in [flow layout](/docs/Web/CSS/Guides/Display/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.

CSS Demo: display

```css interactive-example-choice
display: block;
```

```css interactive-example-choice
display: inline flow-root;
```

```css interactive-example-choice
display: none;
```

```css interactive-example-choice
display: flex;
```

```css interactive-example-choice
display: grid;
```

```css interactive-example-choice
display: grid-lanes;
```

```html interactive-example
<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>
```

```css interactive-example
.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;
}
```

## Syntax

```css
/* 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: grid-lanes;
display: inline-grid-lanes;
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 grid-lanes;
display: inline grid-lanes;
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.

## Grouped values

The keyword values can be grouped into six value categories.

### Outside

- &lt;display-outside&gt;
- : These keywords specify the element's outer display type, which is essentially its role in flow layout:
- `block`
- : The element generates a block box, generating line breaks both before and after the element when in the normal flow.
- `inline`
- : The element generates one or more inline 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.

> [!NOTE]
> When a display property is specified with only an **outer** value (e.g., `display: block` or `display: inline`), the inner value defaults to `flow` (e.g., `display: block flow` and `display: inline flow`).

> [!NOTE]
> You may use the single-value syntax as a fallback for multi-keyword syntax, for example `display: inline flex` could have the following fallback
>
> ```css
> .container {
> display: inline-flex;
> display: inline flex;
> }
> ```
>
> See [Using the multi-keyword syntax with CSS display](/docs/Web/CSS/Guides/Display/Multi-keyword_syntax) for more information.

### Inside

- &lt;display-inside&gt;
- : These keywords specify the element's inner display type, which defines the type of formatting context that its contents are laid out in (assuming it is a non-replaced element). When one of these keywords is used by itself as a single value, the element's outer display type defaults to `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 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](/docs/Web/CSS/Guides/Display/Block_formatting_context) (BFC) for its contents or integrates its contents into its parent formatting context.

- `flow-root`
- : The element generates a block box that establishes a new [block formatting context](/docs/Web/CSS/Guides/Display/Block_formatting_context), defining where the formatting root lies.
- `table`
- : These elements behave like HTML table elements. It defines a block-level box.
- `flex`
- : The element behaves like a block-level element and lays out its content according to the [flexbox model](/docs/Web/CSS/Guides/Flexible_box_layout).
- `grid`
- : The element behaves like a block-level element and lays out its content according to the [grid model](/docs/Web/CSS/Guides/Grid_layout/Basic_concepts).
- `grid-lanes`
- : The element behaves like a block-level element and lays out its content using grid lanes layout. Columns are defined by grid-template-columns and behave like a strict grid, while items are packed in the block direction to fill gaps between items of different sizes. See [Grid lanes layout](/docs/Web/CSS/Guides/Grid_layout/Grid_lanes) for details.
- `ruby`
- : The element behaves like an inline-level element and lays out its content according to the ruby formatting model. It behaves like the corresponding HTML ruby elements.

> [!NOTE]
> When a display property is specified with only an **inner** value (e.g., `display: flex` or `display: grid`), the outer value defaults to `block` (e.g., `display: block flex` and `display: block grid`).

### List Item

- &lt;display-listitem&gt;
- : The element generates a block box for the content and a separate list-item inline box.

A single value of `list-item` will cause the element to behave like a list item.
This can be used together with list-style-type and list-style-position.

`list-item` can also be combined with any &lt;display-outside&gt; keyword and the `flow` or `flow-root` &lt;display-inside&gt; 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 of `block`.

### Internal

- &lt;display-internal&gt;
- : 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.
- `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 HTML elements.
- `ruby-text`
- : These elements behave like rt HTML elements.
- `ruby-base-container`
- : These elements are generated as anonymous boxes.
- `ruby-text-container`
- : These elements behave like rtc HTML elements.

### Box

- &lt;display-box&gt;
- : These values define whether an element generates display boxes at all.
- `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 the 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](https://drafts.csswg.org/css-display/#unbox) 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.

### Precomposed

- &lt;display-legacy&gt;
- : CSS 2 used a single-keyword, precomposed syntax for the `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 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`.

- `inline-grid-lanes`
- : The element behaves like an inline-level element and lays out its content using grid lanes layout. Rows are defined by grid-template-rows and behave like a strict grid, while items are packed in the inline direction to fill gaps between items of different sizes. See [Grid lanes layout](/docs/Web/CSS/Guides/Grid_layout/Grid_lanes) for details.

It is equivalent to `inline grid-lanes`.

### Which syntax should you use?

The [CSS display module](/docs/Web/CSS/Guides/Display) 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:

```css
.container {
display: inline flex;
}
```

This can also be specified using the legacy single value:

```css
.container {
display: inline-flex;
}
```

For more information on these changes, see the [Using the multi-keyword syntax with CSS display](/docs/Web/CSS/Guides/Display/Multi-keyword_syntax) guide.

## Description

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](#syntax) section. In addition, see the following material, which covers the various values of display in depth.

### Multi-keyword values

- [Using the multi-keyword syntax with CSS display](/docs/Web/CSS/Guides/Display/Multi-keyword_syntax)

### CSS Flow Layout (display: block, display: inline)

- [Block and inline layout in normal flow](/docs/Web/CSS/Guides/Display/Block_and_inline_layout)
- [Flow layout and overflow](/docs/Web/CSS/Guides/Display/Flow_layout_and_overflow)
- [Flow layout and writing modes](/docs/Web/CSS/Guides/Display/Flow_layout_and_writing_modes)
- [Introduction to formatting contexts](/docs/Web/CSS/Guides/Display/Formatting_contexts)
- [In flow and out of flow](/docs/Web/CSS/Guides/Display/In_flow_and_out_of_flow)

### display: flex

- [Basic concepts of flexbox](/docs/Web/CSS/Guides/Flexible_box_layout/Basic_concepts)
- [Aligning items in a flex container](/docs/Web/CSS/Guides/Flexible_box_layout/Aligning_items)
- [Controlling ratios of flex items along the main axis](/docs/Web/CSS/Guides/Flexible_box_layout/Controlling_flex_item_ratios)
- [Mastering wrapping of flex items](/docs/Web/CSS/Guides/Flexible_box_layout/Wrapping_items)
- [Ordering flex items](/docs/Web/CSS/Guides/Flexible_box_layout/Ordering_items)
- [Relationship of flexbox to other layout methods](/docs/Web/CSS/Guides/Flexible_box_layout/Relationship_with_other_layout_methods)
- [Typical use cases of flexbox](/docs/Web/CSS/Guides/Flexible_box_layout/Use_cases)

### display: grid

- [Basic concepts of grid layout](/docs/Web/CSS/Guides/Grid_layout/Basic_concepts)
- [Relationship to other layout methods](/docs/Web/CSS/Guides/Grid_layout/Relationship_with_other_layout_methods)
- [Line-based placement](/docs/Web/CSS/Guides/Grid_layout/Line-based_placement)
- [Grid template areas](/docs/Web/CSS/Guides/Grid_layout/Grid_template_areas)
- [Layout using named grid lines](/docs/Web/CSS/Guides/Grid_layout/Named_grid_lines)
- [Auto-placement in grid layout](/docs/Web/CSS/Guides/Grid_layout/Auto-placement)
- [Aligning items in CSS grid layout](/docs/Web/CSS/Guides/Grid_layout/Box_alignment)
- [Grids, logical values and writing modes](/docs/Web/CSS/Guides/Grid_layout/Logical_values_and_writing_modes)
- [CSS grid layout and accessibility](/docs/Web/CSS/Guides/Grid_layout/Accessibility)
- [Realizing common layouts using grids](/docs/Web/CSS/Guides/Grid_layout/Common_grid_layouts)
- [Grid lanes layout](/docs/Web/CSS/Guides/Grid_layout/Grid_lanes)

### Animating display

[Supporting browsers](#browser_compatibility) animate `display` with a [discrete animation type](/docs/Web/CSS/Guides/Animations/Animatable_properties#discrete). 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:

- When animating `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.
- When animating `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 opacity rather than disappearing immediately.

When animating `display` with [CSS animations](/docs/Web/CSS/Guides/Animations), you need to provide the starting `display` value in an explicit keyframe (for example using `0%` or `from`). See [Using CSS animations](/docs/Web/CSS/Guides/Animations/Using) for an example.

When animating `display` with [CSS transitions](/docs/Web/CSS/Guides/Transitions), two additional features are needed:

- @starting-style provides starting values for properties you want to transition from when the animated element is first shown. This is needed to avoid unexpected behavior. By default, CSS transitions are not triggered on an element's first style update or when the `display` type changes from `none` to another type.
- [`transition-behavior: allow-discrete`](/docs/Web/CSS/Reference/Properties/transition-behavior) needs to be set on the transition-property declaration (or the transition shorthand) to enable `display` transitions.

For examples of transitioning the `display` property, see the [`@starting-style`](/docs/Web/CSS/Reference/At-rules/@starting-style#examples) and [`transition-behavior`](/docs/Web/CSS/Reference/Properties/transition-behavior#examples) pages.

## Accessibility

### display: none

Using a `display` value of `none` on an element will remove it from the [accessibility tree](/docs/Learn_web_development/Core/Accessibility/What_is_accessibility#accessibility_apis). 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](https://webaim.org/techniques/css/invisiblecontent/) 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.

### display: contents

Current implementations in some browsers will remove from the [accessibility tree](/docs/Learn_web_development/Core/Accessibility/What_is_accessibility#accessibility_apis) 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](https://drafts.csswg.org/css-display/#valdef-display-contents).

- [More accessible markup with display: contents | Hidde de Vries](https://hidde.blog/more-accessible-markup-with-display-contents/)
- [Display: Contents Is Not a CSS Reset | Adrian Roselli](https://adrianroselli.com/2018/05/display-contents-is-not-a-css-reset.html)

### Tables

In some browsers, changing the `display` value of a table element to `block`, `grid`, or `flex` will alter its representation in the [accessibility tree](/docs/Learn_web_development/Core/Accessibility/What_is_accessibility#accessibility_apis). This will cause the table to no longer be announced properly by screen reading technology.

- [Hidden content for better a11y | Go Make Things](https://gomakethings.com/articles/hidden-content-for-better-a11y/)
- [MDN Understanding WCAG, Guideline 1.3 explanations](/docs/Web/Accessibility/Guides/Understanding_WCAG/Perceivable#guideline_1.3_%e2%80%94_create_content_that_can_be_presented_in_different_ways)
- [Understanding Success Criterion 1.3.1 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/content-structure-separation-programmatic.html)

## Formal definition

## Formal syntax

## Examples

### display value comparison

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 padding and background-color on the containers and their children, so that it is easier to see the effect the display values are having.

#### HTML

```html
<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>grid-lanes</option>
<option>block grid-lanes</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>
<option>inline-grid-lanes</option>
<option>inline grid-lanes</option>
</select>
</div>
```

#### CSS

```css
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;
}
```

#### JavaScript

```js
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();
```

#### Result

100%

Note that some multi-keyword values are added for illustration which have the following equivalents:

- `block` = `block flow`
- `inline` = `inline flow`
- `flow` = `block flow`
- `flow-root` = `block flow-root`
- `table` = `block table`
- `flex` = `block flex`
- `grid` = `block grid`
- `list-item` = `block flow list-item`
- `inline-block` = `inline flow-root`
- `inline-table` = `inline table`
- `inline-flex` = `inline flex`
- `inline-grid` = `inline grid`

You can find more examples in the pages for each separate display type under [Grouped values](#grouped_values).

## Specifications

## Browser compatibility

## See also

- visibility, float, position
- grid, flex
- [CSS ruby layout](/docs/Web/CSS/Guides/Ruby_layout) module
- SVG display attribute
- [Block and inline layout in normal flow](/docs/Web/CSS/Guides/Display/Block_and_inline_layout)
- [Introduction to formatting contexts](/docs/Web/CSS/Guides/Display/Formatting_contexts)
- [Grid lanes layout](/docs/Web/CSS/Guides/Grid_layout/Grid_lanes)

source: MDN Web Docs mirror · page

Cite this

"`display` CSS property". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/display

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·