CSS display

Quick reference for CSS display: outer and inner display roles, common keywords, and how display: none differs from visibility.

display chooses how an element generates boxes. The CSS Display module splits that into an outer role (how the box participates in the parent formatting context) and an inner role (how the element lays out its children). Short keywords such as flex set both: display: flex means outer block and inner flex.

The CSS tutorial uses display: grid and display: flex in the layout and responsive chapters. This page does not repeat those walkthroughs. It covers the display model, the usual keywords, and the difference between display: none and visibility.

Examples were parsed for syntax and structure. They were not rendered in a browser here.

Official sources: MDN and the CSS specification. Fragments were checked with PostCSS 8 for syntax and structure. That is not a CSS conformance suite, and this is not a browser render or visual test.

CSS reference catalog → · CSS tutorial overview →

Outer and inner display

Two-value syntax makes the split explicit: display: block flex is the long form of display: flex, and display: inline flex is the long form of display: inline-flex. The first value is the outer role; the second is the inner layout type.

A block-level box starts on a new line in normal flow. An inline-level box participates in a line. The inner type decides what happens inside: flow (ordinary block and inline layout), flex, or grid. flow-root creates a block formatting context for the contents (display: flow-root is outer block and inner flow-root).

Syntax or propertyInitial / defaultNotes
display: blockvaries by elementShort for block flow. Block-level box, ordinary flow layout inside. Many headings and sections use this as their user-agent default.
display: inlinevaries by elementShort for inline flow. Inline-level box. width and height do not apply to non-replaced inline boxes in the usual way.
display: inline-block—Inline-level box with a block-like inner box, so width, height, and padding apply while the box still sits in a line.
display: flex—Short for block flex. Block-level flex container. See the Flexbox page for axis, gap, and min-width: auto.
display: inline-flex—Short for inline flex. Flex container that is inline-level in the parent.
display: grid—Short for block grid. Block-level grid container. See the Grid page for minmax(0, 1fr) and auto-fit versus auto-fill.
display: inline-grid—Short for inline grid. Grid container that is inline-level in the parent.
display: flow-root—Block-level box that always establishes a block formatting context. Useful when you need a root for margin and float containment without using a flex or grid container.
display: contents—The element does not generate a box; its children appear as if they were children of the parent. Accessibility and some browser quirks make this a careful choice, and it was not visually tested here.

block flex versus inline flex

display: flex;
display: inline-flex;

flex is block-level in the parent. inline-flex is a flex container that can sit on a line with surrounding text.

  • The two-value forms display: block flex and display: inline flex are equivalent to these short keywords.
html
<p>
  Text
  <span class="cluster">
    <button type="button">One</button>
    <button type="button">Two</button>
  </span>
  more text.
</p>
<style>
.cluster { display: inline-flex; gap: 8px; align-items: center; }
.cluster button { font: inherit; }
</style>

What this markup means

The cluster is a flex container, so the buttons share a main axis and a gap. It is inline-flex, so it stays in the paragraph line rather than breaking onto its own block. This page does not measure that line wrap in a browser.

Related: Flexbox, CSS tutorial: layout

MDN documentation → · CSS specification →

display: none versus visibility

display: none prevents the element and its descendants from generating boxes. The element is not laid out, it does not occupy space, and people cannot interact with it as a rendered box. Descendant display values cannot override a none ancestor.

visibility: hidden makes the element invisible, but it still generates boxes and still occupies space. A descendant can set visibility: visible and become visible inside a hidden ancestor. visibility: collapse is mainly for table rows and flex/grid items; do not treat it as a tested synonym for hidden on ordinary blocks here.

Hiding something from the screen is not the same as removing it from the accessibility tree. Neither value is a security or authorization control.

Syntax or propertyInitial / defaultNotes
display: none—No box is generated. The layout treats the element as absent. Descendants are not displayed.
visibility: visiblevisibleThe box is visible. This is the initial value.
visibility: hidden—The box is invisible but still takes up space. Descendants may set visibility: visible.

none removes the box; hidden keeps the space

display: none;
visibility: hidden;
visibility: visible;

A none box is not laid out. A hidden box is laid out but not painted, and a child may become visible again.

  • This contrast is from the CSS Display and CSS Visibility models. No screenshot or click test was run here.
html
<ul class="list">
  <li>First item</li>
  <li class="removed">Removed with display none</li>
  <li class="reserved">Hidden, space reserved <span class="show">but this child is visible</span></li>
  <li>Last item</li>
</ul>
<style>
.list { margin: 0; padding-left: 1.25rem; }
.removed { display: none; }
.reserved { visibility: hidden; }
.reserved .show { visibility: visible; }
</style>

What this markup means

The second item uses display: none, so the list should lay out as if that item were not there. The third item uses visibility: hidden, so its box remains in the list, while the span sets visibility: visible and is allowed to show inside that hidden ancestor.

Related: Box model

MDN documentation → · CSS specification →