Skip to main content

Beginner-Friendly Topic

Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!

Lesson 7 of 10

Block-Level vs Inline Elements

Every HTML element falls into one of two display categories: block-level or inline. Understanding this distinction is absolutely fundamental because it determines how elements behave on the page - how much space they take up, whether they start on a new line, and what other elements can go inside them. Block-level elements take up the full width and start on a new line (like paragraphs and divs). Inline elements only take up as much width as their content and flow within the text (like links and bold text). This concept directly connects to CSS layout and is essential for building well-structured pages.

15 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

Block-Level vs Inline - The Core Difference

Think of HTML elements as boxes on a page. There are two fundamental types:

BLOCK-LEVEL elements:
• Always start on a NEW line
• Take up the FULL WIDTH available (even if their content is short)
• Can contain other block-level AND inline elements
• Think of them as 'stackable boxes' - each one stacks on top of the next
• Examples: <div>, <p>, <h1>-<h6>, <ul>, <ol>, <li>, <table>, <form>, <section>, <article>, <header>, <footer>, <main>, <aside>, <nav>, <blockquote>, <pre>, <hr>, <figure>, <fieldset>

INLINE elements:
• Do NOT start on a new line - they flow within the text
• Only take up as much width as their CONTENT needs
• CANNOT contain block-level elements (with some exceptions like <a>)
• Think of them as 'words in a sentence' - they flow side by side
• Examples: <span>, <a>, <strong>, <em>, <b>, <i>, <u>, <small>, <mark>, <del>, <ins>, <sub>, <sup>, <code>, <kbd>, <samp>, <var>, <abbr>, <cite>, <q>, <time>, <br>, <img>, <input>, <select>, <textarea>, <button>, <label>

This distinction is critical for CSS: block elements default to display: block, and inline elements default to display: inline. CSS can override this behavior (e.g., making a block element inline or vice versa).

Diagram
Loading diagram…

Visual Comparison

Visual Comparison
<!DOCTYPE html>
<html>
<head>
  <style>
    .block-demo { background: #e8f5e9; border: 2px solid #4CAF50; margin: 5px 0; padding: 8px; }
    .inline-demo { background: #fff3e0; border: 2px solid #FF9800; padding: 4px; }
  </style>
</head>
<body>
  <h2>Block-Level Elements (full width, new line)</h2>
  
  <!-- Each block element takes FULL width and starts on a NEW line -->
  <div class="block-demo">&lt;div&gt; - I take the FULL width</div>
  <p class="block-demo">&lt;p&gt; - I also take FULL width</p>
  <h3 class="block-demo">&lt;h3&gt; - Me too, full width!</h3>
  
  <h2>Inline Elements (content width, same line)</h2>
  
  <!-- Inline elements flow side by side, only as wide as their content -->
  <p>
    This is text with 
    <span class="inline-demo">&lt;span&gt;</span> and 
    <strong class="inline-demo">&lt;strong&gt;</strong> and 
    <a href="#" class="inline-demo">&lt;a&gt; link</a> - 
    all on the same line!
  </p>
</body>
</html>

Nesting Rules

  • ✅ Inline inside Block - <p><strong>Bold text</strong></p> is CORRECT. Block elements can contain inline elements.
  • ❌ Block inside Inline - <span><div>Content</div></span> is INVALID. Inline elements should NOT contain block elements.
  • ✅ Block inside Block - <div><p>Paragraph</p></div> is CORRECT. Block elements can contain other block elements.
  • ⚠️ Special case: <p> cannot contain block elements - <p><div>Text</div></p> is INVALID. The browser will auto-close the <p> before the <div>.
  • ✅ Exception: <a> can contain block elements in HTML5 - <a href='#'><div>Clickable block</div></a> is VALID in HTML5 (not in HTML4).
  • ✅ Inline inside Inline - <em><strong>Bold italic</strong></em> is CORRECT. Inline elements can nest inside other inline elements.

Try It Yourself: Block vs Inline

Try It Yourself: Block vs InlineHTML
HTML
✓ Valid
HTML|31 lines|✓ Valid syntax
UTF-8

HTML5 Content Categories

In HTML5, the simple block/inline distinction was replaced by a more detailed system of 'content categories'. While block/inline still describes the visual behavior, HTML5 defines 7 content categories that determine which elements can contain which:

  • Metadata content: <title>, <meta>, <link>, <style>, <script>, <base>
  • Flow content: Nearly everything in <body> (most elements)
  • Sectioning content: <article>, <aside>, <nav>, <section>
  • Heading content: <h1> through <h6>
  • Phrasing content: Inline text-level elements
  • Embedded content: <img>, <video>, <audio>, <canvas>, <iframe>
  • Interactive content: <a>, <button>, <input>, <select>, <details>

For practical purposes, you can still think in terms of block vs inline for layout behavior, but know that the nesting rules are actually determined by these content categories. The key rule remains: check if the parent element's content model allows the child element you want to put inside it.

Quick Quiz

Key Takeaways

  • Every HTML element falls into one of two display categories: block-level or inline.
  • ✅ Inline inside Block - <p><strong>Bold text</strong></p> is CORRECT. Block elements can contain inline elements.
  • ❌ Block inside Inline - <span><div>Content</div></span> is INVALID. Inline elements should NOT contain block elements.
  • ✅ Block inside Block - <div><p>Paragraph</p></div> is CORRECT. Block elements can contain other block elements.

Hands-on Practice Tools for this Course

Test what you learn using these free in-browser developer utilities (no signup required).

All 40+ Tools

Topics in This Module

0/10 done