Spec-Zone.ru › CSS

`<display-box>` CSS type

Baseline Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

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

Syntax

Valid <display-box> values:

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

Accessibility

Current implementations in most browsers will remove from the accessibility tree any element with a display value of contents. This will cause the element — and in some browser versions, its descendant elements — to no longer be announced by screen reading technology. This is incorrect behavior according to the CSSWG specification.

  • [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)

Formal syntax

<display-box> = 
  contents |
  none

Examples

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.

display: none

HTML

<p>Visible text</p>
<p class="secret">Invisible text</p>

CSS

p.secret {
  display: none;
}

Result

display: contents

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, and the child element will be displayed as if the parent had never existed.

HTML

<div class="outer">
  <div>Inner div.</div>
</div>

CSS

.outer {
  border: 2px solid red;
  width: 300px;
  display: contents;
}

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

Result

Specifications

Specification
CSS Display Module Level 3
# valdef-display-contents

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Opera Safari Chrome Android Firefox for Android Opera Android Safari on iOS Samsung Internet WebView Android WebView on iOS
contents
65
79
37
52
11.1
65
37
47
11.3
9.0
65
11.3
contents_unusual
65
79
59
52
No
65
59
47
No
9.0
65
No
focusable_elements
No
No
No
No
No
No
No
No
No
No
No
No

See also

  • display
    • <display-outside>
    • <display-inside>
    • <display-listitem>
    • <display-internal>
    • <display-legacy>
  • [Display: Contents Is Not a CSS Reset Adrian Roselli](https://adrianroselli.com/2018/05/display-contents-is-not-a-css-reset.html)
  • More accessible markup with display: contents by Hidde de Vries (2018)

© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/display-box

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API