In HTML, elements are broadly classified as block-level or inline. This classification affects how elements stack, how much width they occupy, and how they interact with surrounding content. Mastering this concept is essential for controlling layout and building clean, readable web pages.
<div>, <h1> to <h6>, <p>, <section>.<span>, <a>, <strong>, <em>.<div> or <section> to group related content into sections.<span> or <strong> to style or highlight part of a sentence.In HTML, the default display behavior of an element is defined by the browser:
display: block; by default.display: inline; by default.You can change this behavior using CSS. For example, setting display: inline; on a block element makes it behave like inline, and vice versa. There is also display: inline-block;, which combines features of both: it respects width/height like a block but sits in line with text.
<!-- This is a block-level container -->
<div style="border: 2px solid #0b3d91; padding: 15px; margin-bottom: 20px;">
<p>This paragraph is inside a <div> block.</p>
<p>Multiple elements can be grouped here.</p>
</div>
<!-- This is inline text inside a paragraph -->
<p>This sentence contains a
<span style="background-color: #cce5ff; color: #0b3d91; font-weight: bold;
padding: 3px 6px; border-radius: 4px;">highlighted text</span>
using the <span> tag.</p>
This paragraph is inside a <div> block.
Multiple elements can be grouped here.
This sentence contains a highlighted text using the <span> tag.
The bordered box above is a block-level <div>, so it starts on a new line and stretches across the width of its container. Inside it, paragraphs are also block elements, stacking vertically.
The highlighted word is inside an inline <span>. It does not break the line; instead, it flows with the text while applying custom styling.
display property to switch behavior when needed (e.g., inline-block for inline layout with block-like sizing).<header>, <main>, <article>) over generic <div> for better structure and accessibility.<div>) and add multiple paragraphs inside it.<span> with your own CSS styles.<span> to display: block; in CSS and observe how the layout changes.<em> and <strong>.Block and inline elements are the foundation of HTML layout. Block-level elements create the main structure of the page and stack vertically, while inline elements format content within a line of text. Knowing which type you are working with—and how to change it using the CSS display property—gives you precise control over how your content appears in the browser.