CodeOath
← All posts
HTML & CSS70 min total · 18 parts

CSS Fundamentals: The Box Model, Specificity, Positioning, and Layout

Contents — Part 5 of 18: Normal Flow: Block, Inline, and Inline-Block
Part 5 of 18 · ~1 min

Normal Flow: Block, Inline, and Inline-Block

Before reaching for Flexbox or Grid, every element already has a default layout behavior determined by its display value.

displayTakes full width available?Respects width/height?Sits next to siblings?
blockYes — starts on its own lineYesNo — stacks vertically
inlineNo — only as wide as its contentNo — width/height/vertical margin are ignoredYes — flows with surrounding text
inline-blockNo — only as wide as its contentYesYes
span { display: inline; }      /* the default for <span>, <a>, <strong>, ... */
div  { display: block; }       /* the default for <div>, <p>, <section>, ... */
img  { display: inline-block; } /* the default for replaced elements like <img> */

Setting width/height on an inline element (without changing display) silently does nothing — a common source of "I set a width on my <span> and nothing happened" confusion. inline-block exists exactly for this case: elements that should flow like text but also respect a set size, like a row of badge-style tags.