Skip to content
Justice Tech School

Display and Visibility

Block elements (div, p) start on a new line and fill the width. Inline elements (span, a) flow within text and ignore width and height. inline-block flows inline but accepts width, height, margin and padding.

display: none removes an element completely, so it takes no space. visibility: hidden hides it but keeps its space. Both are hidden from most users, so use them deliberately.

Example
<style>
  .ib { display: inline-block; width: 90px; height: 50px; background: #fbbf24; margin: 4px; text-align: center; }
  .gone { display: none; }
  .ghost { visibility: hidden; }
  span.mark { background: #bfdbfe; }
</style>
<div class="ib">A</div><div class="ib">B</div><div class="ib">C</div>
<p>Before <span class="mark">inline span</span> after</p>
<p>One<span class="gone"> (display none)</span> Two<span class="ghost"> (invisible)</span> Three</p>

Exercise

Hide the element and remove its space.

.hidden {
  display: ;
}

Quiz Test

Which hides an element but keeps its space?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.