Block vs Inline Elements
Every HTML element is either block-level or inline. This is one of the most fundamental concepts in HTML and CSS. Understanding display behaviour is the key to controlling layout.
Block Elements
<!-- Block elements: each starts on a new line --> <h1>This is h1 (block)</h1> <p>This is a paragraph (block). Takes full width.</p> <div>This is a div (block). New line every time.</div> <ul><li>List item (block)</li></ul>
Inline Elements
<!-- Inline: stay in the text flow, no new line --> <p> Normal text, <strong>bold text</strong>, <em>italic text</em>, <a href="#">a link</a>, <code>some code</code>, <span style="color:red">red text</span> — all on one line! </p>
Normal text, bold text, italic text, a link, some code, red text — all on one line!
Inline-Block — The Best of Both
<!-- img is inline by default, but respects width/height --> <p> This is text with an <img src="icon.png" alt="icon" width="20" height="20"/> inline image. </p> <!-- button is also inline-block --> <p> Click <button>this button</button> inside text. </p>
This is text with an inline image.
Click inside text.
CSS display property can turn any block into inline or vice versa. display:flex, display:grid, display:inline-block — these override the default HTML behaviour. HTML sets the default; CSS overrides it.
Understanding block vs inline explains why p tags cannot go inside span, why you cannot put a div inside a p, and why buttons sit side by side in a nav bar. Most CSS bugs come from not understanding this fundamental difference.