DevAcademy
LearnCSSThe display Property
BeginnerCSS

The display Property

Learn how the display property controls whether an element behaves as block, inline, inline-block, or is removed from the layout entirely.

Reading Time

14 min

Lesson

Lesson 12 of 30

Controlling Display Behavior

Every element has a default display value, but CSS can override it with the display property — one of the most powerful tools for controlling layout.

Common display Values

ValueBehavior
blockStarts on a new line, takes full available width
inlineFlows with text, only as wide as its content
inline-blockFlows like inline, but accepts width/height like block
noneRemoved from the layout entirely, as if it doesn’t exist
flexTurns the element into a flex container
gridTurns the element into a grid container

inline-block in Action

<style>
  .pill {
    display: inline-block;
    width: 100px;
    padding: 6px 0;
    text-align: center;
    background: steelblue;
    color: white;
    border-radius: 999px;
    margin-right: 6px;
  }
</style>

<span class="pill">One</span>
<span class="pill">Two</span>
<span class="pill">Three</span>
Output

display: none vs visibility: hidden

display: none removes the element completely — it takes up no space and is not rendered. visibility: hidden hides the element visually but still reserves its space in the layout.

none vs hidden

<style>
  .gone { display: none; }
  .invisible { visibility: hidden; }
</style>

<p>Visible paragraph</p>
<p class="gone">You will never see this, and it takes no space.</p>
<p class="invisible">This is invisible, but its space is still reserved.</p>
<p>Another visible paragraph</p>
Output

flex and grid are Also display Values

display: flex and display: grid turn an element into a layout container, changing how its direct children are positioned. These power modern CSS layout, covered in the Flexbox and Grid lessons.

Best Practice

Use display: none for elements that should be conditionally hidden and removed from the page flow entirely (like a closed modal or an inactive tab), and visibility: hidden only when you need to preserve layout space.

Interview Questions

Quick Quiz

1. What does display: none do to an element?

2. Which display value flows inline but accepts width and height?

3. What is the difference between display: none and visibility: hidden?