Full answer
display controls how a box takes part in the flow of the page.
A block box starts on a new line and stretches across the full width of its parent. You can set width, height, margin and padding on all four sides. Examples: div, p, h1, section.
An inline box sits inside a line of text, like a word. It is only as wide as its content. width and height are ignored, and vertical margin does not push other lines away. Vertical padding paints but does not change the line height. Examples: span, a, em.
An inline-block box sits in a line like an inline box, but inside it behaves like a block. It accepts width, height and all margins.
In Chrome the inline span is not 200px wide (its width is only the text), the inline-block span is exactly 200px by 100px, and the block span is 200px by 100px and sits on its own line.
Two inline-block boxes written on separate lines in HTML have a small gap between them. That gap is the whitespace between the tags, treated as a space character. Flexbox does not have this problem, which is one reason it replaced inline-block for rows of boxes.
<style>
body { margin: 0; font: 16px/1.4 sans-serif; }
.tag { width: 200px; height: 100px; margin-top: 20px; background: #cde; }
#i { display: inline; }
#ib { display: inline-block; }
#b { display: block; }
</style>
<p>
<span class="tag" id="i">inline</span>
<span class="tag" id="ib">inline-block</span>
<span class="tag" id="b">block</span>
</p>Run in Chrome 156 (headless) as a page; the snippet is wrapped in a minimal HTML document with doctype, charset and viewport meta tag. Two full runs gave identical results, and the measured values in the answer come from them.
Key points
- block: new line, full width, all box properties apply.
- inline: sits in the text flow and ignores width, height and vertical margin.
- inline-block: inline placement with block sizing.
- Whitespace between inline-blocks becomes a visible gap.
- Flexbox and grid replaced inline-block for rows of boxes.
Common mistakes
- setting width and height on a span or a and wondering why nothing happens. Change display or use a flex or grid parent.
- treating the gap between inline-block elements as a margin bug. It is whitespace, and font-size: 0 on the parent or flex is the clean fix.
Follow-ups
- what does display: contents do?
- What does display: contents do?
- Why does setting width on an anchor not work until you change display?
Tips
- Use inline-block for small things that sit in a line of text, such as a badge with fixed padding. For whole rows of cards, use flexbox or grid.
- Name two example elements for each type: span, div, and a small badge for inline-block.
- Mention the whitespace gap; it is the detail that proves hands-on experience.