SA-21/06, C-11, Asapur, Varanasi, UP support@kamaldnp.com +91 8318013442
HTML
1. HTML Introduction: What is HTML? Learn with Examples 2. Best Free HTML Editors: Notepad to VS Code for Beginners 3. HTML Basic Structure: Doctype, Head, Body Explained 4. HTML Elements Explained: Tags, Content & Empty Elements 5. HTML Attributes List: href, src, alt, width, title & More 6. HTML Headings h1 to h6: Which Heading Tag to Use When 7. HTML Paragraphs: p Tag, br Line Breaks & pre Text 8. HTML Style Attribute: Colour, Font Size & Alignment 9. HTML Text Formatting Tags: bold, italic, mark & More 10. HTML Comments: How to Add Notes & Hide Code in HTML 11. HTML Colors: Names, HEX, RGB & HSL Colour Codes 12. HTML CSS: Inline, Internal & External Stylesheets 13. HTML Links: a Tag, href, New Tab & Email Links 14. HTML Images: img Tag, src, alt, Width & Formats 15. HTML Favicon: Create & Add a Browser Tab Icon 16. HTML Title Tag: How to Write a Good Page Title 17. HTML Tables: table, tr, th, td, colspan & rowspan 18. HTML Lists: ul, ol, dl & Nested Lists Explained 19. HTML Block vs Inline Elements: div, p, span Explained 20. HTML Div Tag: Group Content & Build Page Layouts 21. HTML Class Attribute: Style Many Elements at Once 22. HTML id Attribute: Unique IDs, Links, CSS & JavaScript 23. HTML Iframes: Embed YouTube, Maps & Pages in HTML 24. HTML JavaScript: script Tag, Clicks & First Example 25. HTML File Paths: Relative vs Absolute Paths Explained 26. HTML Head Element: title, meta, charset & viewport 27. HTML Layout: header, nav, main, footer Page Structure 28. HTML Responsive Design: Viewport, Images & Media Queries 29. Semantic HTML Tags: header, nav, main, article & footer 30. HTML Forms: input, label, select, checkbox & Submit 31. HTML Entities: & < > © with Examples 32. HTML Audio & Video Tags: controls, source & Fallback 33. HTML Accessibility: alt Text, Labels, Landmarks & ARIA 34. HTML Meta Tags & SEO: charset, viewport, OG Tags 35. HTML Quotations: blockquote, q, cite, abbr & address
Final Test — Certificate ₹10
Try this code live
Lesson 19 of 35

HTML Block vs Inline Elements: div, p, span Explained

4 min read · Free · No login needed

Every HTML element is either block-level or inline. The difference is simple but fundamental: a block element always starts on a new line and takes up the full width available. An inline element only takes up as much width as it needs, and it sits in the same line as its neighbours.

Diagram — see how it fits together
Diagram: block vs inline elements

Block-level elements

Common block elements: <div>, <p>, <h1>–<h6>, <ul>, <li>, <table>, <form>, <section>. A block element stacks vertically — one below the other — unless you change that with CSS.

Inline elements

Common inline elements: <span>, <a>, <strong>, <em>, <img>, <input>, <button>. Inline elements flow inside a line of text, like words in a sentence. You can put five links in a row and they will sit side by side.

Why it matters

Two rules follow from this: a block element can contain inline elements and other block elements, but an inline element should only contain other inline elements (and text). And you cannot set a width or height on an inline element directly — CSS ignores it unless you change the element's display to block or inline-block.

Tip: The <div> is the generic block container and <span> is the generic inline container. They have no meaning of their own — they exist so you can group things for styling. Use them when no more specific tag fits.

What "block" and "inline" mean

Every HTML element is either block-level or inline. A block-level element starts on a new line and takes up the full width of its parent — like a brick that fills the whole row. A paragraph, a heading, and a <div> are block-level. An inline element sits inside a line of text and takes only as much width as it needs — like a word in a sentence. A link, a <span>, and a <strong> are inline.

Block vs inline

Block-levelValueDescription
<div>, <p>, <h1>–<h6>—Start on a new line, full width.
<ul>, <ol>, <table>—Start on a new line, full width.
<span>, <a>, <strong>—Inline: stay inside the line, only as wide as their content.
<img>, <input>—Inline, but with a set width and height — a special case.

Watch what happens here. The paragraph is block-level, so it starts a new line. The span is inline, so it stays inside the sentence:

<p>This is a paragraph.</p>
<p>This has a <span style="color: red;">red word</span> inside it.</p>
Note: CSS can change an element's display. display: inline; makes a div behave like a word, and display: block; makes a span start a new line. The block/inline split is the default behaviour, not a fixed rule.
Tip: When a layout looks wrong, ask one question: is this element block or inline? Most "why is this on a new line?" and "why won't this sit next to that?" problems are answered by that one question.

Common mistakes

  • Putting a block element (like a <div>) inside a <p> — the browser closes the paragraph early and the layout breaks.
  • Putting a block element inside an <a> — in old HTML this was wrong; in HTML5 it is allowed, but keep it simple while learning.
  • Setting a width on an inline element and wondering why nothing happens — width only works on block elements (and inline-block).
  • Using a <div> for a single word — that is the job of a <span>.

Example explained

  • <div style="background: #ffe0cc;"> — a block element, so it starts on a new line and takes the full width. The background colour makes the full width easy to see.
  • The second <div> — also a block element, so it starts on a new line below the first one, instead of sitting next to it.
  • <p>This is a paragraph with…</p> — a paragraph is block-level too, so it starts its own line as well.
  • <span style="color: red;">a red span inside it</span> — inline, so it stays inside the sentence and only the words inside it turn red. The rest of the paragraph is untouched.

Example

Example
<!DOCTYPE html>
<html>
<head>
<title>Block and Inline</title>
</head>
<body>

<div style="background: #ffe0cc;">This div is a block — it takes the full width.</div>
<div style="background: #cce5ff;">This div starts on a new line.</div>
<p>This is a paragraph with <span style="color: red;">a red span inside it</span> — the span stays in the same line.</p>

</body>
</html>

Output

Output — how it looks in the browser
Output of HTML Block vs Inline Elements: div, p, span Explained

Try it yourself — live editor

Change the code below and press Run to see the result instantly. No file to save, no login needed.

Result

Frequently asked questions

The questions learners ask most about this lesson — read the question, then open it to see the answer.

1. What is the difference between block and inline elements?

A block element starts on a new line and takes full width, while an inline element takes only as much width as it needs and stays in the same line.

2. Can you set width on an inline element?

No, CSS ignores width on an inline element unless you change its display to block or inline-block.

3. What are div and span used for?

div is the generic block container and span is the generic inline container, used to group things for styling when no more specific tag fits.

Why learn this yourself — and not just ask AI?

AI can write code for you, but it cannot think for you. When you learn HTML yourself, your brain builds the real skill: you understand why a page looks the way it does, you can fix it when it breaks, and you can answer it in an exam or an interview without help. That is the skill that gets you a job — not a copied answer.

Get certified — just ₹10

Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.

Take the test

Prefer watching? Video courses teach the same topics step by step.

Go further with a full course

Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.

Summer Industrial Training in MERN Stack 2026
₹3,000
View
CapCut Mobile Video Editing Course Beginner to Advance
₹99
View
AI Power Skills in 2 Days | Learn AI Text, Image, Video and Voice Tools
View
Browse all courses
HTML — Lessons
1. HTML Introduction: What is HTML? Learn with Examples 2. Best Free HTML Editors: Notepad to VS Code for Beginners 3. HTML Basic Structure: Doctype, Head, Body Explained 4. HTML Elements Explained: Tags, Content & Empty Elements 5. HTML Attributes List: href, src, alt, width, title & More 6. HTML Headings h1 to h6: Which Heading Tag to Use When 7. HTML Paragraphs: p Tag, br Line Breaks & pre Text 8. HTML Style Attribute: Colour, Font Size & Alignment 9. HTML Text Formatting Tags: bold, italic, mark & More 10. HTML Comments: How to Add Notes & Hide Code in HTML 11. HTML Colors: Names, HEX, RGB & HSL Colour Codes 12. HTML CSS: Inline, Internal & External Stylesheets 13. HTML Links: a Tag, href, New Tab & Email Links 14. HTML Images: img Tag, src, alt, Width & Formats 15. HTML Favicon: Create & Add a Browser Tab Icon 16. HTML Title Tag: How to Write a Good Page Title 17. HTML Tables: table, tr, th, td, colspan & rowspan 18. HTML Lists: ul, ol, dl & Nested Lists Explained 19. HTML Block vs Inline Elements: div, p, span Explained 20. HTML Div Tag: Group Content & Build Page Layouts 21. HTML Class Attribute: Style Many Elements at Once 22. HTML id Attribute: Unique IDs, Links, CSS & JavaScript 23. HTML Iframes: Embed YouTube, Maps & Pages in HTML 24. HTML JavaScript: script Tag, Clicks & First Example 25. HTML File Paths: Relative vs Absolute Paths Explained 26. HTML Head Element: title, meta, charset & viewport 27. HTML Layout: header, nav, main, footer Page Structure 28. HTML Responsive Design: Viewport, Images & Media Queries 29. Semantic HTML Tags: header, nav, main, article & footer 30. HTML Forms: input, label, select, checkbox & Submit 31. HTML Entities: & < > © with Examples 32. HTML Audio & Video Tags: controls, source & Fallback 33. HTML Accessibility: alt Text, Labels, Landmarks & ARIA 34. HTML Meta Tags & SEO: charset, viewport, OG Tags 35. HTML Quotations: blockquote, q, cite, abbr & address
Final Test — Certificate ₹10

🤖 KAMALDNP AI Assistant

Ask about courses, website & more

Hi! I'm KAMALDNP AI Assistant. Ask me about our courses, website features, or anything else! 😊
Please wait 5s...
🤖 KAMALDNP Assistant ✕

Request human callback:

🔐 Login Required
✕

Please log in to download. You will stay on this page after logging in!

New here? Register now →