Display & PositioningCore· 35 min read

The display Property

The property that controls how elements lay out — block, inline, inline-block, or hidden.

What you will learn

  • Switch between block, inline and inline-block
  • Hide elements with display: none
  • Understand display vs visibility

The main values

ValueBehaviour
blockFull width, starts a new line (div, p, h1)
inlineFlows in a line, ignores width/height (span, a)
inline-blockFlows in a line BUT accepts width/height/padding
noneRemoved completely (takes no space)
flex / gridPowerful layout modes (next units)
inline-block tags + display: none
<style>
  .tag {
    display: inline-block;     /* sits in a row but takes box sizing */
    background:#4338ca; color:#fff; padding:8px 14px; border-radius:8px; margin:4px;
  }
  .gone { display: none; }     /* not shown, no space */
</style>
<span class="tag">HTML</span>
<span class="tag">CSS</span>
<span class="tag">JS</span>
<p class="gone">You cannot see me.</p>
<p>The hidden paragraph above leaves no gap.</p>
Live preview

The three .tag spans normally would sit awkwardly (a plain <span> ignores width and padding). Giving them display: inline-block lets them stay in a row like text but also accept padding, border-radius and margin — so they become neat pill-shaped tags. The .gone paragraph has display: none, which removes it completely: you cannot see it and it leaves no empty space — that is why the final sentence sits right where the hidden paragraph would have been.

Note: display: none removes the element and its space entirely. visibility: hidden hides it but keeps its space (leaves a gap). Choose based on whether you want the gap.

Q. Which display value flows inline but still accepts width, height and padding?

Answer: inline-block sits in a line like inline but respects box dimensions like block — great for buttons and tags.

✍️ Practice

  1. Turn three inline links into inline-block buttons with padding.
  2. Hide an element with display: none and another with visibility: hidden; compare the gaps.

🏠 Homework

  1. Make a row of “skill tag” pills using inline-block.
Want to learn this with a mentor?

CodingClave runs guided, project-based training (28-day, 45-day & 6-month batches).

Explore Training →