HTML Layout Fundamentals

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

Full width:

Take up the entire width of their container

New line:

Always start on a new line

Stackable:

Stack vertically on top of each other

Sizing:

Can have width and height set

Common Block Elements:

<div><p><h1>-<h6><ul>, <ol><li><form><section><article>

Inline Elements

Content width:

Only take up as much width as needed

Same line:

Stay on the same line as adjacent content

Flow together:

Flow horizontally like text

Limited sizing:

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 behavior
  • inlineStandard inline behavior
  • inline-blockHybrid approach
  • flexFlexible box layout
  • gridGrid layout system
  • noneCompletely 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

1 / 4
1

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.

1 of 4
🔍Nesting Rules Matter
Block elements cannot be nested inside inline elements. Placing a div inside a span, for example, is invalid HTML. Browsers will try to fix it but the result is unpredictable. Always nest block content inside other block elements.

🎯 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, height and vertical margins unless you change their display.

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.