Block-Level vs Inline Elements in HTML

In HTML, elements are commonly categorized as block-level elements and inline elements. This classification describes how elements normally behave in the webpage layout and how they interact with surrounding content.

Understanding the difference between block-level and inline elements is important when creating HTML pages and working with CSS. Block-level elements normally begin on a new line, while inline elements normally remain on the same line as surrounding content.

For example, <p> is normally a block-level element, while <a> and <span> are normally inline elements.

If you are new to HTML, first understand HTML Elements and HTML Tags.

What Are Block-Level Elements?

A block-level element normally starts on a new line and takes up the available width of its parent container.

For example:

<p>This is the first paragraph.</p>
<p>This is the second paragraph.</p>

The paragraphs normally appear one below another:

This is the first paragraph.

This is the second paragraph.

Block-level elements are commonly used to create the structure and sections of a webpage.

Examples of Block-Level Elements

Some commonly used block-level elements include:

  • <div>
  • <p>
  • <h1> to <h6>
  • <section>
  • <article>
  • <header>
  • <footer>
  • <main>
  • <nav>
  • <ul>
  • <ol>
  • <li>
  • <form>
  • <table>

For example:

<h1>HTML Tutorial</h1>

<p>Learn HTML step by step.</p>

<section>
    <h2>HTML Basics</h2>
    <p>Learn the fundamentals of HTML.</p>
</section>

These elements normally appear as separate blocks in the document.

Note: CSS can change the default display behavior of an HTML element.

What Are Inline Elements?

An inline element normally does not start on a new line. It occupies only the amount of space required by its content.

For example:

<p>
    Learn <strong>HTML</strong> with
    <a href="#">Web4Learners</a>.
</p>

The <strong> and <a> elements remain within the paragraph’s line.

The browser displays the content approximately like this:

Learn HTML with Web4Learners.

Inline elements are commonly used for text-level content, links, emphasis, and small portions of content.

Examples of Inline Elements

Common inline elements include:

  • <a>
  • <span>
  • <strong>
  • <em>
  • <b>
  • <i>
  • <mark>
  • <small>
  • <sub>
  • <sup>
  • <code>
  • <label>

Example:

<p>
    This is <strong>important</strong> information.
</p>

Here, <strong> is used inside the paragraph instead of creating a separate block.

Block-Level vs Inline Elements

The main difference is how the elements normally participate in the document flow.

FeatureBlock-Level ElementsInline Elements
Starts on a new lineNormally yesNormally no
Available widthNormally takes available widthNormally takes required width
Main purposeStructure and sectionsText-level content
Examples<div>, <p>, <section><span>, <a>, <strong>
Can contain inline contentYesYes, depending on the element
Common CSS displayblockinline

Block-Level Element Example

Consider this example:

<h1>HTML Tutorial</h1>

<p>Learn HTML from beginner to advanced.</p>

<div>Practice HTML examples.</div>

The elements normally appear one below another:

HTML Tutorial
Learn HTML from beginner to advanced.
Practice HTML examples.

Each element creates its own block in the normal document flow.

Inline Element Example

Now consider:

<p>
    Learn
    <strong>HTML</strong>
    and
    <a href="#">CSS</a>.
</p>

The inline elements remain within the surrounding text:

Learn HTML and CSS.

They do not normally force the content onto a new line.

Using <div> and <span>

The <div> and <span> elements are particularly useful when learning about block and inline behavior.

By default:

  • <div> behaves as a block-level element.
  • <span> behaves as an inline element.

Example:

<div>
    <h2>Web4Learners</h2>

    <p>
        Learn
        <span>HTML fundamentals</span>
        step by step.
    </p>
</div>

Here, <div> provides a block-level container, while <span> identifies a small portion of text.

Block-Level Elements Can Contain Inline Elements

A block-level element can commonly contain inline elements.

For example:

<p>
    Learn
    <strong>HTML</strong>
    with
    <a href="#">Web4Learners</a>.
</p>

Here:

  • <p> is the block-level element.
  • <strong> is an inline element.
  • <a> is an inline element.

This type of structure is very common in HTML.

For more information about parent and child relationships, see Nested HTML Elements.

Inline Elements Can Be Nested

Inline elements can also be nested when the HTML content model allows it.

Example:

<p>
    This is
    <strong>very <em>important</em></strong>
    information.
</p>

Here, <em> is nested inside <strong>.

Proper nesting is important when working with HTML elements. Learn more about correct opening and closing tag relationships in Opening and Closing Tags.

Block-Level Elements and CSS

CSS can change the default display behavior of an element.

For example:

<span class="box">Hello</span>
<span class="box">World</span>

Normally, <span> behaves as an inline element.

You can change it to block using CSS:

.box {
    display: block;
}

Now each <span> behaves like a block-level box.

Inline Elements and CSS

You can also change the display behavior of a block-level element.

For example:

<div class="item">HTML</div>
<div class="item">CSS</div>

CSS:

.item {
    display: inline;
}

The <div> elements will now participate in the inline flow.

Important: CSS changes how an element is displayed. It does not change the HTML element itself.

The CSS display Property

The CSS display property controls how an element participates in layout.

Common values include:

display: block;
display: inline;
display: inline-block;
display: flex;
display: grid;
display: none;

For example:

<span class="button">Click Me</span>
.button {
    display: inline-block;
    padding: 10px 20px;
}

The inline-block value is especially useful when you want an element to remain alongside other content while still allowing properties such as width, height, and padding to be controlled.

Block vs Inline vs Inline-Block

These three CSS display values are important to understand.

Display ValueNew LineWidth and Height
blockYesCan be controlled
inlineNoLimited in the normal inline formatting model
inline-blockNoCan be controlled

Example:

.block {
    display: block;
}

.inline {
    display: inline;
}

.inline-box {
    display: inline-block;
}

Common Block-Level Elements

Here are some frequently used block-level elements:

<div>Container</div>

<p>Paragraph</p>

<h1>Main Heading</h1>

<section>Section</section>

<article>Article</article>

<header>Header</header>

<footer>Footer</footer>

These elements are commonly used to organize webpage content.

Common Inline Elements

Here are some frequently used inline elements:

<a href="#">Link</a>

<strong>Important</strong>

<em>Emphasized</em>

<span>Text</span>

<code>console.log()</code>

These elements are commonly used within surrounding content.

Block-Level and Inline Elements with Attributes

Both types of elements can use attributes when the specific HTML element supports them.

Example:

<div id="content" class="container">
    <p class="text">Learn HTML.</p>
</div>

Here, id and class are attributes.

Learn more about attributes in HTML Attributes.

Attributes can be used with many different HTML elements for styling, identification, links, accessibility, scripting, and other purposes.

Block-Level and Inline Elements in a Complete HTML Page

Here is a practical example:

<!DOCTYPE html>
<html lang="en">

<head>
    <title>Block and Inline Elements</title>
</head>

<body>

    <header>
        <h1>Web4Learners</h1>
    </header>

    <main>

        <section>
            <h2>HTML Tutorial</h2>

            <p>
                Learn <strong>HTML</strong>
                with
                <a href="#">Web4Learners</a>.
            </p>

            <div>
                This is a block-level container.
            </div>
        </section>

    </main>

</body>

</html>

In this example:

  • <header> is a structural block.
  • <h1> is a block-level heading.
  • <main> provides the main page content.
  • <section> creates a content section.
  • <p> creates a paragraph.
  • <strong> is an inline element.
  • <a> is an inline element.
  • <div> creates a block-level container.

If you want to understand how <html>, <head>, and <body> organize a page, see HTML Document Structure.

Semantic HTML and Block Elements

Many modern HTML elements are semantic elements.

For example:

<header>
    Website Header
</header>

<nav>
    Navigation Links
</nav>

<main>
    Main Content
</main>

<section>
    Article Section
</section>

<footer>
    Website Footer
</footer>

These elements describe the purpose of their content.

Using semantic elements is generally preferable to using <div> for every section when a suitable semantic element exists.

Common Mistakes

Assuming Every Block Element Must Always Be Block

The default behavior of an element can be changed using CSS.

div {
    display: inline;
}

Therefore, HTML’s default display behavior and CSS display behavior should be considered separately.

Using <div> for Everything

The <div> element is useful, but it should not automatically replace semantic HTML.

Instead of:

<div>
    Website Header
</div>

you can use:

<header>
    Website Header
</header>

when the content represents a page header.

Using <span> for Major Page Sections

<span> is generally intended for small inline pieces of content.

For example:

<p>
    Learn <span>HTML</span> today.
</p>

It is not normally appropriate as the main container for an entire page section.

Forgetting CSS During Layout Debugging

If an element is not behaving as expected, check its CSS display property.

For example:

.example {
    display: block;
}

or:

.example {
    display: inline;
}

CSS can significantly change the normal layout behavior.

Best Practices

  • Use semantic HTML elements whenever they accurately describe your content.
  • Use block-level elements for logical content sections and containers.
  • Use inline elements for text-level content.
  • Use <div> when a generic block container is actually needed.
  • Use <span> when a generic inline container is needed.
  • Use CSS for layout rather than adding unnecessary HTML elements.
  • Keep elements properly nested.
  • Understand the difference between HTML structure and CSS presentation.
  • Use the display property when you need to intentionally change an element’s layout behavior.

Understanding HTML Syntax can also help you write correctly structured HTML before applying CSS layouts.

FAQs

What is a block-level element in HTML?

A block-level element normally starts on a new line and occupies the available width of its parent container. Examples include <div>, <p>, <section>, and headings.

What is an inline element in HTML?

An inline element normally stays on the same line as surrounding content and takes up only the space required by its content. Examples include <span>, <a>, <strong>, and <em>.

Is <div> a block-level element?

Yes. <div> normally behaves as a block-level element, although CSS can change its display behavior.

Is <span> an inline element?

Yes. <span> normally behaves as an inline element and is commonly used to identify or style a small portion of content.

Can CSS change a block element into an inline element?

Yes. CSS can change its display behavior.

div {
    display: inline;
}

Can CSS change an inline element into a block element?

Yes.

span {
    display: block;
}

What is the difference between block and inline elements?

Block-level elements normally start on a new line and occupy the available width, while inline elements normally remain on the same line and occupy only the space required by their content.

What is inline-block?

inline-block allows an element to remain in the inline flow while allowing properties such as width, height, padding, and margins to be controlled more like a block.

Should I use <div> or <span>?

Use <div> when you need a generic block container and <span> when you need a generic inline container. When a semantic element is appropriate, use the semantic element instead.

Do block-level and inline elements still matter in modern HTML?

Yes. They are useful for understanding the normal document flow, although CSS can change an element’s default display behavior.