These three display types control how elements appear and behave on a webpage. Knowing the difference helps you arrange content clearly and nicely.
Block vs inline vs inline-block in CSS
Introduction
Syntax
CSS
selector {
display: block | inline | inline-block;
}block makes the element a block box.
inline makes the element flow inside text.
inline-block makes the element flow inline but behave like a block box.
Examples
CSS
p {
display: block;
}CSS
a {
display: inline;
}CSS
button {
display: inline-block;
width: 8rem;
height: 2.5rem;
}Sample Program
This page shows three types of display:
- Block element takes full width and starts on a new line.
- Inline elements flow inside text on the same line.
- Inline-block elements sit side by side but keep block features like width and height.
CSS
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Block vs Inline vs Inline-block</title> <style> .block { display: block; background-color: #a0d8f0; margin-bottom: 0.5rem; padding: 0.5rem; } .inline { display: inline; background-color: #f0c0a0; padding: 0.5rem; } .inline-block { display: inline-block; background-color: #a0f0c0; width: 8rem; height: 2rem; line-height: 2rem; text-align: center; margin-right: 0.5rem; } </style> </head> <body> <div class="block">I am block - full width, new line</div> <span class="inline">I am inline - flow inside text</span> <span class="inline">I am also inline</span> <br /> <div> <div class="inline-block">Inline-block 1</div> <div class="inline-block">Inline-block 2</div> <div class="inline-block">Inline-block 3</div> </div> </body> </html>
Important Notes
Block elements always start on a new line and take full width by default.
Inline elements do not accept width or height properties.
Inline-block elements combine inline flow with block box features like width and height.
Summary
Block: New line, full width.
Inline: Flows inside text, no width/height.
Inline-block: Side by side, can set size.
Practice
1. Which CSS display property makes an element start on a new line and take the full width available?
easy
Solution
Step 1: Understand block behavior
A block element always starts on a new line and stretches to fill the container's width.Step 2: Compare with other display types
Inline elements flow inside text and don't take full width; inline-block allows size but stays inline.Final Answer:
block -> Option AQuick Check:
New line + full width = block [OK]
Hint: Block = new line and full width [OK]
Common Mistakes:
- Confusing inline with block and expecting new line
- Thinking inline-block takes full width automatically
- Choosing none which hides element
2. Which of the following is the correct CSS syntax to make an element display inline-block?
easy
Solution
Step 1: Recall correct CSS property value
The correct value to make an element inline-block is exactlyinline-blockwith a hyphen.Step 2: Check other options for syntax errors
display: block;sets block, not inline-block.block-inlineandinlineblockare invalid.Final Answer:
display: inline-block; -> Option AQuick Check:
Correct hyphenated syntax = inline-block [OK]
Hint: Use hyphen: inline-block, not inlineblock [OK]
Common Mistakes:
- Missing hyphen in inline-block
- Mixing order like block-inline
- Using block instead of inline-block
3. Given this HTML and CSS, what will be the visual layout of the boxes?
<div class='box'>Box 1</div>
<div class='box'>Box 2</div>
<style>
.box { display: inline-block; width: 100px; height: 50px; background: lightblue; margin: 5px; }
</style>medium
Solution
Step 1: Understand inline-block behavior
Inline-block elements flow side by side horizontally and respect width and height settings.Step 2: Apply CSS properties
Each box has width 100px, height 50px, and margin, so they appear as separate boxes next to each other.Final Answer:
Boxes appear side by side horizontally with set width and height. -> Option CQuick Check:
Inline-block = side by side + size [OK]
Hint: Inline-block respects size and flows horizontally [OK]
Common Mistakes:
- Thinking inline-block stacks vertically like block
- Assuming inline ignores width and height
- Confusing hidden elements with display values
4. You want three buttons side by side with fixed width and height. You wrote:
Why do the buttons ignore width and height and stack oddly?
<button class='btn'>One</button>
<button class='btn'>Two</button>
<button class='btn'>Three</button>
<style>
.btn { display: inline; width: 100px; height: 40px; }
</style>Why do the buttons ignore width and height and stack oddly?
medium
Solution
Step 1: Recall inline element behavior
Inline elements ignore width and height CSS properties; they size to content only.Step 2: Understand why buttons ignore size
Settingdisplay: inlinecauses buttons to ignore width and height, so they don't size as expected.Final Answer:
Becausedisplay: inlineignores width and height properties. -> Option BQuick Check:
Inline ignores size = problem [OK]
Hint: Inline elements ignore width and height [OK]
Common Mistakes:
- Thinking buttons can't have size set
- Confusing block with inline for side by side
- Assuming margin fixes size ignoring
5. You want a navigation menu with links side by side, each with padding and background color. Which display property should you use to allow width, height, and side-by-side layout?
hard
Solution
Step 1: Identify layout needs
Links must be side by side and allow setting width, height, padding, and background color.Step 2: Match display property to needs
Inline-block allows elements to flow horizontally and respects box model properties like padding and background.Step 3: Exclude other options
Block stacks vertically; inline ignores width/height; none hides elements.Final Answer:
display: inline-block; -> Option DQuick Check:
Side by side + size = inline-block [OK]
Hint: Use inline-block for side by side with size [OK]
Common Mistakes:
- Using block which stacks vertically
- Using inline which ignores size
- Using none which hides elements
Recommended
Ready to prove it?
Pass the test and this pattern moves unknown
10 questions ~5 mineasy hard
