Bird
Raised Fist0
CSSmarkup~20 mins

Block vs inline vs inline-block in CSS - Practice Questions

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Display Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the main difference between block and inline elements?
Which statement best describes how block and inline elements behave in a browser?
ABlock elements only take as much width as needed and flow within a line; inline elements take the full width available and start on a new line.
BBlock elements take the full width available and start on a new line; inline elements only take as much width as needed and flow within a line.
CBoth block and inline elements take the full width available but block elements can have padding and margin, inline elements cannot.
DInline elements always start on a new line, block elements flow within a line.
Attempts:
2 left
💡 Hint
Think about how paragraphs and links behave differently in a text.
📝 Syntax
intermediate
1:30remaining
Which CSS rule correctly makes an element behave like inline-block?
Select the CSS declaration that makes an element behave like inline-block.
Adisplay: inline-block;
Bdisplay: block-inline;
Cdisplay: inline_block;
Ddisplay: block-inline-block;
Attempts:
2 left
💡 Hint
Check the exact spelling and hyphenation of the display property value.
rendering
advanced
2:30remaining
What will be the visual layout of these elements?
Given this HTML and CSS, what will you see in the browser?

<style>
.box { width: 5rem; height: 5rem; background: coral; margin: 0.5rem; }
.block { display: block; }
.inline { display: inline; }
.inline-block { display: inline-block; }
</style>
<div class="block box">Block</div>
<div class="inline box">Inline</div>
<div class="inline-block box">Inline-block</div>
AThe block box is on its own line, the inline and inline-block boxes appear side by side on the same line.
BAll three boxes appear stacked vertically, each on its own line.
CThe inline box is on its own line, block and inline-block boxes appear side by side.
DThe inline-block box is hidden, block and inline boxes appear side by side.
Attempts:
2 left
💡 Hint
Remember how block elements start on new lines and inline elements flow inside lines.
selector
advanced
2:00remaining
Which CSS selector targets only inline-block elements?
Given multiple elements with different display values, which selector matches only elements with display: inline-block?
A*:inline-block
B.inline-block
C:display(inline-block)
D[style*='inline-block']
Attempts:
2 left
💡 Hint
Think about how CSS attribute selectors work and what is valid syntax.
accessibility
expert
3:00remaining
How does using inline-block affect keyboard navigation and screen readers?
Which statement about accessibility is true when using display: inline-block on interactive elements?
AInline-block elements automatically become focusable and are always announced as buttons by screen readers.
BInline-block elements are ignored by screen readers and cannot be focused by keyboard navigation.
CInline-block elements behave exactly like inline elements for accessibility, so they cannot receive keyboard focus unless explicitly made focusable.
DInline-block elements behave like inline elements visually but keep block-level accessibility features, so keyboard navigation and screen readers treat them as blocks.
Attempts:
2 left
💡 Hint
Consider how display affects focus and screen reader behavior by default.

Practice

(1/5)
1. Which CSS display property makes an element start on a new line and take the full width available?
easy
A. block
B. inline
C. inline-block
D. none

Solution

  1. Step 1: Understand block behavior

    A block element always starts on a new line and stretches to fill the container's width.
  2. 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.
  3. Final Answer:

    block -> Option A
  4. Quick 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
A. display: inline-block;
B. display: block-inline;
C. display: inlineblock;
D. display: block;

Solution

  1. Step 1: Recall correct CSS property value

    The correct value to make an element inline-block is exactly inline-block with a hyphen.
  2. Step 2: Check other options for syntax errors

    display: block; sets block, not inline-block. block-inline and inlineblock are invalid.
  3. Final Answer:

    display: inline-block; -> Option A
  4. Quick 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
A. Boxes appear inline but ignore width and height.
B. Boxes appear stacked vertically, each on a new line.
C. Boxes appear side by side horizontally with set width and height.
D. Boxes are hidden and not visible.

Solution

  1. Step 1: Understand inline-block behavior

    Inline-block elements flow side by side horizontally and respect width and height settings.
  2. Step 2: Apply CSS properties

    Each box has width 100px, height 50px, and margin, so they appear as separate boxes next to each other.
  3. Final Answer:

    Boxes appear side by side horizontally with set width and height. -> Option C
  4. Quick 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:
<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
A. Because buttons cannot have width or height set.
B. Because display: inline ignores width and height properties.
C. Because display: block is needed for inline layout.
D. Because margin is missing to separate buttons.

Solution

  1. Step 1: Recall inline element behavior

    Inline elements ignore width and height CSS properties; they size to content only.
  2. Step 2: Understand why buttons ignore size

    Setting display: inline causes buttons to ignore width and height, so they don't size as expected.
  3. Final Answer:

    Because display: inline ignores width and height properties. -> Option B
  4. Quick 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
A. display: block;
B. display: none;
C. display: inline;
D. display: inline-block;

Solution

  1. Step 1: Identify layout needs

    Links must be side by side and allow setting width, height, padding, and background color.
  2. Step 2: Match display property to needs

    Inline-block allows elements to flow horizontally and respects box model properties like padding and background.
  3. Step 3: Exclude other options

    Block stacks vertically; inline ignores width/height; none hides elements.
  4. Final Answer:

    display: inline-block; -> Option D
  5. Quick 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