Every HTML element has a default display that shapes how it sits in the page. Most elements behave as either block-level or inline. A third layout mode, inline-block, is mainly applied with CSS when you want a hybrid box.
What is a block-level element?
A block element starts on a new line and expands to the full available width of its container (unless you constrain it with CSS). Browsers typically add vertical spacing before and after. Typical block tags: <div>, <p>, <h1>–<h6>, <ul>, <ol>, <section>, <header>, <article>, and <form>.
What is an inline element?
An inline element stays in the current line of text. It only occupies as much width as its content needs and does not force a line break. Typical inline tags: <a>, <span>, <strong>, <em>, <img>, <code>, and <label>.
What about inline-block?
display: inline-block keeps the element in the text flow (like inline) while letting you set width, height, padding, and margin like a block box. It is not the default for most tags—you apply it with CSS when you need side-by-side boxes that still respect size.
Default vs CSS.
HTML picks a sensible default. CSS display can change how an element paints, but it does not rewrite nesting rules in the HTML content model.
Do not nest blocks inside paragraphs.
Putting <div>, <ul>, or another <p> inside a <p> is invalid. The browser closes the paragraph early and the layout can look broken.
div vs span.
Prefer a meaningful tag when one exists. Use <div> as a generic block wrapper and <span> as a generic inline wrapper when no better semantic element fits.
Syntax
Block and Inline Syntax
Block elements stack; inline elements share a line:
layout.html
block→ new line, full width (e.g. <div>, <p>)
inline→ same line, content width (e.g. <span>, <a>)
inline-block→ same line + box sizing via CSS
HTML
<!-- Block: each starts on its own line -->
<div>First block</div>
<p>Second block (paragraph)</p>
<h2>Third block (heading)</h2>
<!-- Inline: share one paragraph line -->
<p>
Visit <a href="/html">HTML</a> and try
<strong>bold</strong> or a
<span style="color:teal">styled span</span>.
</p>
<!-- Inline-block via CSS -->
<style>
.tile { display: inline-block; width: 120px; padding: 0.5rem; }
</style>
<span class="tile">Tile A</span>
<span class="tile">Tile B</span>
Prefer semantic tags (<section>, <nav>, <strong>) over bare wrappers when the meaning is clear. Reach for <div> / <span> when you only need a hook for layout or styling.
Reference
Core HTML Concepts
How the three display modes compare by default:
Behavior
Block
Inline
Inline-block
Starts on new line?
Yes
No
No
Width
Full available width
Content width
Content or set width
Set width / height?
Yes
Ignored (mostly)
Yes
Vertical margin / padding
Full effect
Limited / uneven
Full effect
Typical tags
div, p, h1–h6, ul, section
a, span, strong, img
Often via CSS
Common block elements
Element
Role
<div>
Generic block container for grouping content
<p>
Paragraph of text
<h1>–<h6>
Headings that introduce sections
<ul> / <ol>
List containers (items are also block-level)
<section>
Thematic grouping with its own heading
Common inline elements
Element
Role
<a>
Hyperlink in the text flow
<span>
Generic inline wrapper for a phrase
<strong> / <em>
Important or emphasized text
<img>
Image that sits in the line (replaced element)
Nesting rules that matter
Pattern
OK?
Block inside block (div > p)
Yes
Inline inside block (p > span)
Yes
Inline inside inline (a > strong)
Often yes (follow each tag’s content model)
Block inside p (p > div / ul)
No — invalid nesting
Block inside span or a
No for classic inline containers
Approach
How to Choose Block vs Inline
Practical habits when structuring markup.
Ask whether the content should start a new section of the page (block) or sit inside a sentence (inline).
Pick a semantic tag first—<p>, <section>, <a>, <strong>—before a generic wrapper.
Use <div> to group related blocks; use <span> to mark a phrase inside text.
Keep paragraphs free of nested blocks; move lists and cards outside the <p>.
When you need side-by-side sized boxes, apply display: inline-block (or modern flex/grid) with CSS.
Remember: changing display does not make invalid nesting valid.
Goal
Pattern
Group a card of content
<div class="card">…</div> or <section>
Highlight a word
<span class="hl">…</span> or <strong>
Link inside a sentence
<p>…<a href="…">…</a>…</p>
List under a heading
<h2>…</h2><ul>…</ul> (not inside a p)
Equal-width chips in a row
display: inline-block or flex on a parent
Try it
Live Preview
Switch the same content between block, inline, and inline-block to see how layout changes.
Background colors show each box. Only the CSS display value changes.
Rendered page
AlphaBetaGamma
display: block — each item on its own row, full width
Code
HTML Examples
Six patterns: block elements, inline elements, side-by-side comparison, inline-block CSS, nesting pitfalls, and a complete page.
Example 1 — Common Block Elements
HTML
<div>This is a div (block)</div>
<p>This is a paragraph (block)</p>
<h2>This is a heading (block)</h2>
<ul>
<li>List item one</li>
<li>List item two</li>
</ul>
<section>
<h3>Section heading</h3>
<p>Section body text.</p>
</section>
Each block begins on a new line and uses the full row width.
div is a neutral grouping box with no built-in meaning.
p / headings / lists / section add structure and default spacing.
Use for page regions, paragraphs, and stacked content.
Example 2 — Common Inline Elements
HTML
<p>
Read the
<a href="/html">HTML tutorial</a>,
note the <strong>important</strong> tip,
and wrap a phrase in a
<span style="background:#fef3c7">highlighted span</span>.
</p>
<p>
Inline image:
<img src="/images/codetofun-logo.png" alt="CodeToFun" width="32" height="32">
sits in the text line.
</p>
Modern layouts often prefer flex or grid for the same job.
Example 5 — Nesting: Wrong vs Right
HTML
<!-- Wrong: block (ul) inside p — browser will fix-up the DOM -->
<!--
<p>Topics:
<ul><li>HTML</li><li>CSS</li></ul>
</p>
-->
<!-- Right: keep the list outside the paragraph -->
<p>Topics:</p>
<ul>
<li>HTML</li>
<li>CSS</li>
</ul>
<!-- Right: only phrasing / inline content inside p -->
<p>Learn <a href="/html">HTML</a> and <strong>practice</strong>.</p>
London is the capital of England. Visit attractions and look for the River Thames.
How It Works
header / section / footer are block regions of the page.
p holds the narrative; a and span stay inline.
class on section styles a block card without changing display type.
Mix semantics with light CSS for polish.
Edge Cases & Pitfalls
Most “mystery” layout bugs come from invalid nesting or confusing display with content models.
p nest
Block inside a paragraph
A div, ul, or nested p inside p is invalid. The parser closes the paragraph first.
display
CSS display ≠ nesting license
Making a spandisplay: block changes layout only. It still should not wrap block structure like a section.
width
Width on pure inline
Setting width/height on a default inline element usually has no effect. Use block, inline-block, flex, or grid.
img
Images are special
img is inline by default but has intrinsic dimensions (replaced element). Vertical alignment and whitespace can surprise you.
a
Links wrapping blocks
HTML5 allows an a to wrap flow content in some cases, but keep structures simple—avoid nesting interactive elements inside links.
whitespace
Gaps between inline-blocks
Newlines between inline-block tags can create small gaps. Flexbox/grid avoid that quirk more cleanly.
Compatibility
Browser Support
Default block and inline layout for HTML elements is part of the web platform and works in all browsers.
✓ Baseline · Widely available
Block & inline defaults
Every modern browser applies default display values and respects CSS display overrides.
100%display defaults
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
Block / inline layoutUniversal
Bottom line: Use semantic HTML first; adjust display with CSS when you need a different layout mode.
Remember
Key Takeaways
Block starts a new line and fills available width; inline stays in the text flow.
div / p / headings / lists / section are common blocks; a / span / strong / img are common inline tags.
inline-block (via CSS) mixes line flow with box sizing.
Never put block elements inside a <p> incorrectly—nesting rules still apply after CSS changes.
One line: Choose block tags for stacked page structure and inline tags for text-level markup—use CSS display only when you need a different box model.
Frequently Asked Questions
A block-level element starts on a new line and stretches to the full width of its parent by default. Common examples are div, p, h1–h6, ul, ol, and section.
An inline element stays in the text flow. It does not force a new line and only takes the width of its content. Common examples are a, span, strong, em, and img.
Block stacks vertically and fills the container width. Inline flows with text and ignores width/height. Inline-block flows like text but accepts width, height, padding, and margin like a box.
No. Do not nest block elements such as div, ul, or another p inside a p. The browser will close the paragraph early and produce unexpected markup. Put inline content (or phrasing content) inside p.
Use div as a generic block container for groups of content. Use span as a generic inline wrapper for a word or phrase you want to style or script without breaking the text line.
No. Setting display: block on a span only changes layout. Nesting rules still follow the HTML content model—an inline element is not allowed to contain block-level structure just because you restyled it.