<display-box>
Quick Summary for <display-box>
These keywords define whether an element generates display boxes at all.
Code Usage for <display-box>
<p>Visible text</p> <p class="secret">Invisible text</p> 
More Details for <display-box>

<display-box>

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

Accessibility concerns

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 Display: Contents Is Not a CSS Reset | Adrian Roselli

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 # typedef-display-box

Support of contents

See also

display <display-outside> <display-inside> <display-listitem> <display-internal> <display-legacy> Display: Contents Is Not a CSS Reset | Adrian Roselli More accessible markup with display: contents — hiddedevries.nl

Last modified: Feb 22, 2022, by MDN contributors

Select your preferred language English (US)Français日本語Português (do Brasil)中文 (简体) Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote


Bajo
Random CSS Property

<length>

The <length> CSS data type represents a distance value. Lengths can be used in numerous CSS properties, such as width, height, margin, padding, border-width, font-size, and text-shadow.
length#mm css reference