DevAcademy
LearnHTMLBlock vs Inline Elements
IntermediateHTML

Block vs Inline Elements

Understand the difference between block-level and inline elements, and how it affects page layout.

Reading Time

10 min

Lesson

Lesson 18 of 27

Two Display Behaviors

Every HTML element has a default display behavior: block-level or inline. This determines whether it starts on a new line and how much space it takes up.

Block vs Inline

Block-LevelInline
Starts on new lineYesNo
Takes full width by defaultYesNo, only as wide as content
Can set width/heightYesNo (without changing display)
Examples<div>, <p>, <h1>–<h6>, <ul>, <section><span>, <a>, <strong>, <em>, <img>

Block-Level Example

<div>First block</div>
<div>Second block</div>
<!-- Each div appears on its own line -->
Output

Inline Example

<span>First</span><span>Second</span>
<!-- Both spans appear on the same line, side by side -->
Output

img is a Special Case

<img> is inline-level by default but, unlike text-based inline elements, it does accept width and height because it is treated as a replaced element.

CSS Can Change display

The default block/inline behavior is just a starting point — CSS’s display property (block, inline, inline-block, flex, grid, none) can override it for any element.

Invalid Nesting

Block-level elements generally should not be placed inside inline elements — for example, putting a <div> inside a <span> is invalid and can cause unpredictable rendering.

Best Practice

Choose elements based on their semantic meaning first; use CSS display properties afterward if you need different visual behavior than the default.

Interview Questions

Quick Quiz

1. Does a block-level element start on a new line by default?

2. Which of these is an inline element by default?

3. What CSS property can override an element’s default block/inline behavior?