Every HTML element has a default display behaviour. Two of them cover most elements: block and inline.
Block elements
A block element starts on a new line and stretches across the full width of its parent. Paragraphs, headings, lists and div are block elements.
<style>
p { background: #fff3ec; }
</style>
<p>First paragraph</p>
<p>Second paragraph</p>
Each paragraph’s background fills the whole row.
Inline elements
An inline element sits within a line of text and takes only as much room as its content. Links, strong, em, span and img are inline.
<style>
a { background: #fff3ec; }
</style>
<p>Read <a href="#">the guide</a> and <a href="#">the FAQ</a> today.</p>
The backgrounds fit the link text only.
Quick reference
| Block | Inline |
|---|---|
div, p, h1 to h6 | span, a, strong, em |
ul, ol, li | img, code, abbr |
section, article, header | button, input (inline-block) |
table, form | label, br |
Nesting rules
- Block elements can usually contain other blocks and inline elements.
- Inline elements should contain only text and other inline elements.
Changing the behaviour
CSS can change it with the display property: display: block, display: inline or display: inline-block. A link can become a block, and a div can become inline.
Putting a block inside an inline element
a can wrap a block in modern HTML, but a span wrapping a div is invalid. If you need a block-level container, use a div.