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.
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.
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.
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.
<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.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-level | Value | Description |
|---|---|---|
<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>
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.<div>) inside a <p> — the browser closes the paragraph early and the layout breaks.<a> — in old HTML this was wrong; in HTML5 it is allowed, but keep it simple while learning.<div> for a single word — that is the job of a <span>.<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.<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.<!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>
Change the code below and press Run to see the result instantly. No file to save, no login needed.
The questions learners ask most about this lesson — read the question, then open it to see the answer.
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.
No, CSS ignores width on an inline element unless you change its display to block or inline-block.
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.
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.
Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.
Take the testPrefer watching? Video courses teach the same topics step by step.
Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.
Browse all coursesAsk about courses, website & more
Request human callback:
Please log in to download. You will stay on this page after logging in!
New here? Register now →