<display-box> CSS type

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

* Some parts of this feature may have varying levels of support.

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.

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

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

CSS

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

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

CSS

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
Chrome – Full support
Chrome 65 (Release date: 2018-03-06)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 37 (Release date: 2015-03-31)
footnote Full support
Opera – Full support
Opera 52 (Release date: 2018-03-22)
footnote Full support
Safari – Full support
Safari 11.1 (Release date: 2018-04-12)
footnote Full support
Chrome Android – Full support
Chrome Android 65 (Release date: 2018-03-06)
footnote Full support
Firefox for Android – Full support
Firefox for Android 37 (Release date: 2015-03-31)
footnote Full support
Opera Android – Full support
Opera Android 47 (Release date: 2018-07-23)
footnote Full support
Safari on iOS – Full support
Safari on iOS 11.3 (Release date: 2018-03-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 9 (Release date: 2018-09-15)
footnote Full support
WebView Android – Full support
WebView Android 65 (Release date: 2018-03-06)
footnote Full support
WebView on iOS – Full support
WebView on iOS 11.3 (Release date: 2018-03-29)
footnote Full support
Specific behavior of unusual elements when display: contents is applied to them
Chrome – Full support
Chrome 65 (Release date: 2018-03-06)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 59 (Release date: 2018-03-13)
footnote Full support
Opera – Full support
Opera 52 (Release date: 2018-03-22)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 65 (Release date: 2018-03-06)
footnote Full support
Firefox for Android – Full support
Firefox for Android 59 (Release date: 2018-03-13)
footnote Full support
Opera Android – Full support
Opera Android 47 (Release date: 2018-07-23)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 9 (Release date: 2018-09-15)
footnote Full support
WebView Android – Full support
WebView Android 65 (Release date: 2018-03-06)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
Elements with display: contents are focusable
Experimental
Chrome – No support
Chrome
footnote
footnote See bug 40866683
Edge – No support
Edge
footnote
footnote See bug 40866683
Firefox – No support
Firefox
footnote
footnote See bug 1791648
footnote See bug 1553549
Opera – No support
Opera
footnote
footnote See bug 40866683
Safari – No support
Safari
footnote
footnote See bug 255149
Chrome Android – No support
Chrome Android
footnote
footnote See bug 40866683
Firefox for Android – No support
Firefox for Android
footnote
footnote See bug 1791648
footnote See bug 1553549
Opera Android – No support
Opera Android
footnote
footnote See bug 40866683
Safari on iOS – No support
Safari on iOS
footnote
footnote See bug 255149
Samsung Internet – No support
Samsung Internet
footnote
footnote See bug 40866683
WebView Android – No support
WebView Android
footnote
footnote See bug 40866683
WebView on iOS – No support
WebView on iOS
footnote
footnote See bug 255149

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.

See also