Block vs Inline Elements
Every HTML element has a default display type — block or inline. Understanding this is fundamental to understanding why elements behave the way they do on screen and how layouts work.
Block Elements
Block elements always start on a new line and take full available width:
<!-- Each block element gets its own line --> <div style="background:blue;color:white">I am a div</div> <p style="background:green;color:white">I am a paragraph</p> <div style="background:purple;color:white">Another div</div>
Inline Elements
Inline elements flow within text — only as wide as their content:
<p>This has a <span style="background:orange;color:black">span</span>, an <a href="#" style="color:cyan">link</a>, and a <strong style="color:red">bold word</strong> — all inline! </p>
This has a span, an link, and a bold word — all inline!
display Property in CSS
<!-- Make spans sit side by side with spacing --> <style> .nav-link { display: inline-block; padding: 6px 14px; background: #333; } </style> <a class="nav-link" href="#">Home</a> <a class="nav-link" href="#">About</a> <a class="nav-link" href="#">Contact</a>
Never put a block element inside an inline element. A div inside a span, or a p inside an a tag, violates the HTML spec and causes unpredictable rendering across different browsers.
The img tag is inline by default which is why images sit on the text baseline and have a small gap at the bottom. Add display:block to images in CSS to eliminate this gap.
The block vs inline distinction comes from typesetting. Block elements correspond to paragraphs that occupy their own space. Inline elements correspond to words within a paragraph that flow with surrounding text.