Every HTML element defaults to a specific layout behavior, most commonly block or inline. Knowing whether an element starts on a new line or sits inside text flow explains why some tags stack vertically while others sit side by side.
A block-level element always begins on a new line and stretches across the full available width of its parent container. You can set explicit width, height, top/bottom margin, and padding on block elements freely.
Common block elements include div, p, h1 through h6, section, article, header, footer, ul, ol, and table. The div element serves as a generic block container when no semantic landmark tag fits.
An inline element stays inside the current line of text and takes up only as much width as its content needs. Vertical margin-top and margin-bottom, as well as width and height, have no effect on pure inline elements.
Common inline elements include span, a, strong, em, code, label, and img (which behaves as replaced inline content). The span element acts as a generic inline hook for styling a single phrase inside a paragraph.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Block vs Inline Demo</title>
<style>
.block-box { background: #e2e8f0; padding: 12px; margin-bottom: 12px; }
.badge { background: #dbeafe; color: #1e40af; padding: 2px 8px; border-radius: 4px; }
</style>
</head>
<body>
<div class="block-box">This div is a block element occupying 100% width.</div>
<p>
This paragraph contains an inline
<span class="badge">HTML5</span>
span badge that stays on the same line.
</p>
</body>
</html>
div or p inside a span. Note that HTML5 permits a tags to wrap block cards, though span and strong must only hold inline content.height on a span: Switch the element to display: inline-block or display: block in CSS if you need explicit width or height.div everywhere ("div soup"): Pick semantic block tags like main, nav, and article before reaching for div.Yes. CSS display: block; or display: inline-block; overrides any element's default layout behavior.
div is a block-level container for grouping sections and layout blocks, while span is an inline wrapper for styling small pieces of text inside a line.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Experiment with the code from this lesson in our interactive playground.