Block vs Inline Elements
Master the fundamental difference between block and inline elements - the foundation of HTML layout and CSS styling.
What is the difference between block and inline elements in HTML?
Block elements, like <div>, <p>, <h1>, <ul> and <section>, start on a new line and stretch to the full available width. Inline elements, like <span>, <a>, <strong> and <img>, sit within a line of text and take only as much width as their content. CSS display can change how any element behaves.
<div>Block: full width, new line</div>
<p>Text with <a href="#">an inline link</a> and <strong>bold</strong> words.</p>Try It: Block vs Inline Demo
Explore how block and inline elements behave differently. Hover over elements to see their type!
Code Editor
<div>A div is block: it starts on a new line.</div>
<p>A paragraph with <span>a span</span>, <a href="#">a link</a> and <strong>bold text</strong> flowing inline.</p>
<div>Another block.</div>Preview
Understanding the Difference
Block Elements
Take up the entire width of their container
Always start on a new line
Stack vertically on top of each other
Can have width and height set
Common Block Elements:
<div><p><h1>-<h6><ul>, <ol><li><form><section><article>Inline Elements
Only take up as much width as needed
Stay on the same line as adjacent content
Flow horizontally like text
Width/height properties usually ignored
Common Inline Elements:
<span><a><strong><em><code><img><input><button>CSS Display Property
The CSS display property controls how elements are displayed and can change their behavior from block to inline and vice versa.
display: block
span {
display: block;
}Makes inline elements behave like block elements
display: inline
div {
display: inline;
}Makes block elements behave like inline elements
display: inline-block
div {
display: inline-block;
}Combines benefits of both: flows inline but accepts width/height
Common Display Values:
blockStandard block behaviorinlineStandard inline behaviorinline-blockHybrid approach
flexFlexible box layoutgridGrid layout systemnoneCompletely hidden
Best Practices
Good Practices:
- Use semantic HTML first
Choose elements based on meaning, then style with CSS
- Block for structure
Use block elements for main content areas and layout
- Inline for formatting
Use inline elements for text formatting and small UI elements
- Inline-block for components
Great for buttons, form elements, and small components
Avoid These:
- ✗Block elements inside inline
Don't put <div> or <p> inside <span> or <a>
- ✗Forcing width/height on inline
Use inline-block or block instead
- ✗Changing display unnecessarily
Respect the natural behavior when possible
- ✗Using <br> for spacing
Use CSS margins/padding instead
Your Learning Path
Master HTML element display types and layout behavior
What You've Learned
- ▶Block-level elements and their behavior
- ▶Inline elements and their characteristics
- ▶Inline-block elements for flexible layouts
- ▶CSS display property usage
- ▶Layout implications and best practices
What's Next
- ▶HTML Orientation - Understanding document flow
- ▶HTML Tables - Advanced block layouts
- ▶CSS Layout - Flexbox and Grid
- ▶Responsive Design - Layout adaptation
- ▶CSS Positioning - Advanced placement
Pro Learning Tip
Understanding block vs inline behavior is fundamental to CSS layout. Practice identifying element types and experiment with the display property to see how it affects layout flow.
Block vs Inline — step by step
Understand block-level elements
Block elements (div, p, h1-h6, ul, table) start on a new line and take the full available width. They stack vertically and can contain both block and inline content.
🎯 Quick Check
Which CSS display value makes an element flow inline but still respect width and height?
Block vs Inline Elements: summary
Key points
- Inline elements generally shouldn't contain block elements; for example, a
<span>shouldn't contain a<div>. - An
<a>may wrap block content such as a whole card. That's allowed in modern HTML. - Inline elements ignore
width,heightand vertical margins unless you change theirdisplay.
Frequently asked questions
›Is a button inline or block?
<button> is inline-block: it sits in a line of text but accepts width, height and padding.
›How do I make an inline element behave like a block?
Set display: block (or inline-block) on it in CSS.