HTML Grouping: Div & Span
[Classroom Tip] This demo makes block vs inline behavior visible, shows div layout building, and demonstrates semantic HTML5 structure. Click the toggle buttons to watch the differences live!
The key difference: block elements stack vertically, inline elements flow horizontally with text.
<div>)Each div starts on a new line and stretches to full width.
<span>)Words in a sentence: span 1 flows with span 2 text naturally.
Spans sit side by side, flowing like words in a sentence.
This is how developers use <div> to create classic page layouts.
<div class="container">
<div class="header">
<h1>Website</h1>
</div>
<div class="content-area">
<div class="main">Main Area</div>
<div class="sidebar">Sidebar</div>
</div>
<div class="footer">Footer</div>
</div>
Click each button to see how span can highlight parts of text without affecting paragraph flow.
Notice: The paragraph structure doesn't change — only the specific word gets styled via <span>.
Both approaches render identically in the browser, but semantic elements communicate meaning to search engines and screen readers.
<div id="header"> <h1>My Site</h1> </div> <div id="nav">...links</div> <div id="main"> <div class="article">...</div> </div> <div id="footer">...</div>
<header> <h1>My Site</h1> </header> <nav>...links</nav> <main> <article>...</article> </main> <footer>...</footer>
Both render the same in the browser. But <header>, <nav>, <main>, <article>, and <footer> tell Google and screen readers what the content means.
Every div (and every HTML element) has margin, border, padding, and content. Hover the box to see the DevTools-style breakdown.
← Yellow = Margin | Blue border = Border | Red = Padding + Content →