CSS · Box Model

Display Properties

display decides how an element behaves in the layout: does it start a new line, can it have a width, is it shown at all? It is the switch between all CSS layout modes.

Beginner 5 min Lesson 9 of 26 Runnable examples
Before you start:Box Model
0/26 in CSS
On this page · 5 min · Beginner

Learning objectives#

  • Explain block, inline and inline-block
  • Hide elements with display: none vs visibility: hidden
  • Know that flex and grid are display values
  • Change an element’s default display

Explanation#

block: starts on a new line and takes the full width. Width, height, margin and padding all work. Default for div, p, h1, ul.

inline: flows in a line of text. Width and height are ignored and vertical margins do nothing. Default for span, a, strong.

inline-block: sits in a line like inline, but accepts width, height and vertical padding like block. Great for buttons and badges.

none: removes the element completely — no space is kept. visibility: hidden makes it invisible but keeps its space.

flex and grid turn an element into a layout container for its children — covered in the Flexbox and Grid lessons.

Code example: Comparing display values#

HTMLComparing display values Runnable
<style>
  body { font-family: sans-serif; }
  .box { background: #dbeafe; border: 1px solid #2965f1; margin: 4px; padding: 6px; width: 120px; }
  .block  { display: block; }
  .inline { display: inline; }
  .ib     { display: inline-block; }
  .gone   { display: none; }
  .hidden { visibility: hidden; }
</style>


<p><b>block</b> (new line, width works):</p>
<span class="box block">A</span><span class="box block">B</span>


<p><b>inline</b> (same line, width ignored):</p>
<div class="box inline">A</div><div class="box inline">B</div>


<p><b>inline-block</b> (same line, width works):</p>
<span class="box ib">A</span><span class="box ib">B</span>


<p><b>none vs hidden</b>:</p>
<span class="box ib">1</span><span class="box ib gone">2</span><span class="box ib">3</span><br>
<span class="box ib">1</span><span class="box ib hidden">2</span><span class="box ib">3</span>
Expected output
Block boxes stack vertically at 120px; inline boxes sit on one line ignoring width; inline-block boxes sit side by side at 120px. With none, box 2 vanishes; with hidden, an empty gap remains.
Opens this example in the full playground

Step-by-step explanation#

  1. Spans with display: block stack like divs.
  2. Divs with display: inline lose their width and sit in a line.
  3. inline-block gives you both: side by side and sized.
  4. display: none removes box 2 so 1 and 3 touch.
  5. visibility: hidden keeps box 2’s space.

Real-world use case#

Navigation links (inline <a>) are often made display: block or inline-block so the whole padded area is clickable. Mobile menus are hidden with display: none until opened.

Common mistakes#

Setting width on an inline element

width does nothing on a span or a. Change it to inline-block or block first.

Hiding content from everyone by accident

display: none also hides content from screen readers. For “visually hidden but readable” text, use a .sr-only utility class.

Gaps between inline-block items

Whitespace in the HTML creates small gaps between inline-block elements. Flexbox with gap avoids this.

Best practices#

  • Use flex or grid for laying out groups of items
  • Use inline-block for single badges or buttons in text
  • Use the hidden HTML attribute or display: none to hide content
  • Check the computed display value in DevTools when layout looks wrong

Remember this#

block = brick (stacks). inline = word (flows). inline-block = word you can resize.

none = gone (no space). hidden = invisible (space kept).

flex and grid are display values too — the gateway to layouts.

Practice exercise#

Your task: Turn a row of <a> links into clickable buttons, each 100px wide with 10px padding, sitting side by side.

Need a hint?
Links are inline by default, so width is ignored.
Show solution
CSS Illustrative
nav a {
  display: inline-block;
  width: 100px;
  padding: 10px;
  text-align: center;
}

Mini quiz#

Display Properties quizMultiple choice Question 1 of 3

Which display value keeps elements on one line but allows width and height?

Score so far: 0/0

Want more? Practise all CSS MCQs · CSS interview questions

My notes#

Saved in this browser.

Progress is saved in this browser. Sign in to sync.