Encodera

Thanks for reading!

Donate to the site — we work hard for you.

HTML & CSS reference

display

Decides how an element behaves in the flow and how it lays out its content.

Syntax

display: value;

Values

ParameterTypeDescription
blockkeywordA block: starts on a new line, takes the full width.
inlinekeywordAn inline element: within the line, without width and height.
inline-blockkeywordWithin the line, but with width and height.
flexkeywordA flexbox container.
gridkeywordA grid container.
nonekeywordThe element is hidden and takes no space.

Examples

Block, inline and inline-block elements:

<style>
  span { background: lavender; padding: 4px; }
  .ib { display: inline-block; width: 100px; }
  .b { display: block; }
</style>
 
<span>inline</span> <span>inline</span>
<span class="ib">inline-block</span>
<span class="b">block</span>

A hidden element:

<p>A visible paragraph.</p>
<p style="display: none;">This paragraph is not on the page.</p>
<p>Another visible one.</p>

Notes

display: none removes the element entirely, including for screen readers. To hide it but keep its space, use visibility: hidden. There are also inline-flex and inline-grid — containers that sit inside a line like text.

See also

  • visibility — Hides an element but keeps the space it occupies.
  • flex — A shorthand for how a flex item grows, shrinks and what size it starts from.
  • grid-template-columns — The number and widths of the columns of a grid.
  • <span> — An inline container without meaning: used to style part of a text.

Related recipes

In the tutorial

  • The display property — Block and inline elements, the values block, inline, inline-block and none, hiding elements.

Thanks for reading!

Donate to the site — we work hard for you.