SA-21/06, C-11, Asapur, Varanasi, UP support@kamaldnp.com +91 8318013442
Lesson 19 of 30

HTML Block and Inline Elements

2 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.

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.

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 and Inline Elements
Try it yourself: copy the code above into a file named test.html, open it in your browser, and change the text to see what happens. That is how you learn — by changing things and watching the result.
Get certified — just ₹10

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

Take the test
Go further with a full course

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

Master Python + AI Skills in 30 Days
₹499
View
AI Power Skills in 2 Days | Learn AI Text, Image, Video and Voice Tools
View
AI & ML with Azure AI, AWS AI & Generative AI
₹10,000
View
Browse all courses
HTML — Lessons
1. HTML Introduction 2. HTML Editors 3. HTML Basic 4. HTML Elements 5. HTML Attributes 6. HTML Headings 7. HTML Paragraphs 8. HTML Styles 9. HTML Formatting 10. HTML Comments 11. HTML Colors 12. HTML CSS 13. HTML Links 14. HTML Images 15. HTML Favicon 16. HTML Page Title 17. HTML Tables 18. HTML Lists 19. HTML Block and Inline Elements 20. HTML Div 21. HTML Classes 22. HTML Id 23. HTML Iframes 24. HTML JavaScript 25. HTML File Paths 26. HTML Head 27. HTML Layout 28. HTML Responsive 29. HTML Semantics 30. HTML Forms
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...
🛡️ 7-Day Money-Back Guarantee
🤖 KAMALDNP Assistant ✕

Request human callback:

🔐 Login Required
✕

Download karne ke liye login karo. Login ke baad yahi page pe rahoge!

Naya ho? Register karo →