- Home
- /
- Tutorials
- /
- HTML Tutorial
- /
- HTML Block vs Inline Elements
HTML Layout
HTML Block vs Inline Elements
Every HTML element starts as either block or inline. A block, like a paragraph, starts on a new line and takes the full width. An inline element, like a link, sits inside a line of text. Most layout confusion for beginners comes down to this difference.
What Are Block-Level Elements?
A block-level element starts on a new line and stretches across the full width of its parent, even if its content is short. Many blocks, such as paragraphs and headings, also get space above and below from the browser.
Examples of block-level elements:
<div>, <p>, <h1>ā<h6>, <ul>, <ol>, <li>, <section>, <article>, <header>, <footer>, <form>, <table>
Block Level Elements Example
html
<h2>This is a block element</h2>
<p>Block elements always start on a new line and take full width.</p>
<div>This is inside a div container.</div>The heading, paragraph and div each appear on their own line, stacked one below the other.
What Are Inline Elements?
An inline element does not start a new line. It is only as wide as its content and flows along with the text around it.
Examples of inline elements:
<span>, <a>, <strong>, <em>, <img>, <label>, <input>, <b>, <i>
Inline Elements Example
html
<p>This is a <strong>bold</strong> word and this is an <em>italic</em> word.</p>
<p>Click <a href="#">here</a> to learn more.</p>The bold word, the italic word and the link stay inside their sentences.
The difference in one table
| Question | Block elements | Inline elements |
|---|---|---|
| Starts on a new line? | Yes | No |
| How wide? | The full width of the parent | As wide as the content |
| Do width and height work? | Yes | No, they are ignored |
| Do top and bottom margins push other lines away? | Yes | No |
| Examples | <div>, <p>, <h1>, <ul>, <section> | <span>, <a>, <strong>, <em>, <code> |
The third and fourth rows explain a common surprise: you give a <span> or <a> a width or a top margin, and nothing happens. That is inline behavior.
Mixing them
Combined Example
html
<div style="border: 1px solid #ccc; padding: 10px;">
<h3>HTML Elements Example</h3>
<p>This is a <strong>paragraph</strong> that contains an <a href="#">inline link</a> and a <span style="color: blue;">colored word</span>.</p>
</div>The div and the paragraph are blocks; the bold text, the link and the blue word are inline elements inside the paragraph.
Changing it with CSS
Converting Example
html
<span style="display: block; background: lightgray;">Converted to Block</span>
<div style="display: inline; background: yellow;">Converted to Inline</div>The span now takes its own full line, and the div sits in the line like text. The HTML element stays the same; only its display changes. For something that sits in a line but accepts width and height, like a button, use display: inline-block. All the options are in CSS Display.
Good to know
- Do not put blocks inside a
<p>. The browser closes the paragraph early and your structure breaks. - Links are the exception to "inline cannot contain blocks". In HTML5, an
<a>may wrap a whole card made of blocks. - Semantic elements such as
<header>,<main>,<article>and<footer>are all blocks.
Browser Support
Chrome | Edge | Firefox | Safari | Opera | IE9+ |
|---|---|---|---|---|---|
| Yes | Yes | Yes | Yes | Yes | Yes |
HTML Block vs Inline Elements exercises
A block in a block
Make a div and in it a paragraph that says A block takes the full width.
Result
