The display property

display sets an element's box type: whether it starts on a new line, sits inside a line of text, lays out its children as a flex or grid container — or is not shown at all.

Syntax

display: block | inline | inline-block | flex | inline-flex | grid | inline-grid | none | …
Initial value
inline
Inherited
no
Applies to
all elements

Values

ValueWhat it does
blockstarts on a new line and takes the full available width; width, height and vertical margins apply
inlinesits inside a line of text; width and height have no effect, vertical margins do not push neighbouring lines
inline-blocksits in a line like text, but width, height, margin and padding work as for a block
flexa block-level flex container: direct children become flex items
inline-flexthe same as flex, but the container itself sits inline
grida block-level grid container: children are placed in grid rows and columns
inline-gridthe same as grid, but the container itself sits inline
nonethe element is not rendered and takes no space; screen readers skip it too

Example

span {
  background: #e0f2fe;
  border: 1px solid #0284c7;
  padding: 4px 8px;
}
.inline { width: 200px; }
.inline-block { display: inline-block; width: 200px; }
.block { display: block; margin-top: 12px; }
<p>Text with <span class="inline">inline</span> and <span class="inline-block">inline-block</span> on one line.</p>
<span class="block">block — on a new line, full width</span>

Result

▶ Open in HTML Editor

Good to know

  • The initial value in the spec is inline, but browsers set display: block for div, p, h1–h6, ul, section and other block tags themselves. That is why span and a sit in a line and div does not.
  • display: none removes the element entirely. To hide it but keep its space, use visibility: hidden.
  • The hidden attribute hides an element through display: none in the browser's styles, so a rule such as display: flex on the same element overrides hidden. Add [hidden] { display: none !important; } or don't set display on hidden elements.

Sources and specification

See also