CSS Inline vs Block
Understand the fundamental display types that control how elements flow and interact. Master inline, block, and inline-block for perfect layouts.
What is the difference between inline, block and inline-block?
Block elements start on a new line and take the full available width. Inline elements flow inside text and ignore width, height and vertical margins. Inline-block elements flow inside text like inline ones but accept width, height, padding and margins like block ones.
div { display: block; } /* new line, full width */
span { display: inline; } /* flows in text */
.btn {
display: inline-block; /* in text, but sizeable */
padding: 8px 16px;
width: 120px;
}Interactive Display Demo
Code Editor
<p>Inline <span class="inline">span</span> ignores width and height.</p>
<p>Inline-block <span class="inline-block">span</span> respects them.</p>
<div class="block">Block takes the full width</div>Preview
Display Property Fundamentals
The display property is one of the most important CSS properties, controlling how elements generate boxes and interact with other elements in the document flow.
Inline Elements
- • Flow with text content
- • Only take needed space
- • Ignore width/height
- • Examples: span, a, strong
Block Elements
- • Take full available width
- • Start on new line
- • Respect width/height
- • Examples: div, p, h1-h6
Inline-Block
- • Flow inline with content
- • Respect width/height
- • Can sit side by side
- • Best of both worlds
Box Model Behavior
Width & Height Rules
Inline
- ❌ Width ignored
- ❌ Height ignored
- ⚠️ Horizontal padding/margin only
Block
- ✅ Width respected
- ✅ Height respected
- ✅ All padding/margin
Inline-Block
- ✅ Width respected
- ✅ Height respected
- ✅ All padding/margin
Common Use Cases
Inline Elements For
- • Text styling (strong, em, code)
- • Links within paragraphs
- • Breadcrumb navigation
- • Status indicators and badges
- • Icon + text combinations
Block Elements For
- • Page structure (header, main, footer)
- • Content sections and articles
- • Form groups and containers
- • Cards and panels (full-width)
- • Layout wrappers
Inline-Block Elements For
- • Navigation menu items
- • Button groups
- • Tag lists and chips
- • Card grids (legacy approach)
- • Form control groups
- • Statistics displays
- • Image galleries
- • Toolbar items
Best Practices & Modern Alternatives
Best Practices
- • Use semantic HTML first
- • Change display only when needed
- • Consider accessibility implications
- • Test responsive behavior
- • Remove whitespace for inline-block grids
Modern Alternatives
- • Flexbox: For most inline-block layouts
- • Grid: For complex card grids
- • CSS Subgrid: For nested grids
- • Container Queries: For responsive components
While display properties are fundamental and still relevant, consider migrating inline-block layouts to Flexbox for better control and fewer quirks. Use CSS feature detection with @supports for progressive enhancement.
CSS inline-block — step by step
How inline-block Works
inline-block elements flow inline like text but accept width, height, margin, and padding on all sides — combining the best of block and inline.
🎯 Quick Check
Which display value flows inline but also respects width and height?
CSS Basics Complete!
You've mastered all fundamental CSS concepts. Ready to explore advanced CSS layouts?
Inline vs Block Elements: summary
Key points
- Common block elements:
div,p,h1–h6,ul,section,form. - Common inline elements:
span,a,strong,em,code,label. - Vertical padding on an inline element is painted but doesn't push the surrounding lines away.
- The whitespace between
inline-blockelements in HTML shows up as a small gap. Flexbox withgapavoids it.
Frequently asked questions
›Why can't I set the width of a span?
span is inline by default, and inline boxes ignore width and height. Set display: inline-block or block on it.
›Is an image inline or block?
img is inline by default but is a replaced element, so it does respect width and height. It also sits on the text baseline, which leaves a small gap below it; display: block removes the gap.
›How do I remove the gap between inline-block elements?
The gap comes from the whitespace in your HTML. The cleanest fix is to put the items in a flex container (display: flex; gap: …).