Introduction
Block-level elements help organize content by creating separate sections that stack vertically on a webpage.
Block-level elements help organize content by creating separate sections that stack vertically on a webpage.
<tagname>Content goes here</tagname>
,
<p>This is a paragraph.</p>
<div>This is a division or section.</div>
<header>This is the page header.</header>
<section><h2>Title</h2><p>Some text here.</p></section>
This example shows several block-level elements: <header>, <section>, <p>, and <footer>. Each creates a separate block that stacks vertically with spacing and borders for clarity.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Block-level Elements Example</title> <style> body { font-family: Arial, sans-serif; margin: 1rem; } header, section, footer { border: 2px solid #4a90e2; padding: 1rem; margin-bottom: 1rem; border-radius: 0.5rem; background-color: #e6f0fa; } p { margin-top: 0; } </style> </head> <body> <header> <h1>Welcome to My Website</h1> </header> <section> <h2>About Me</h2> <p>This paragraph is inside a section block. It stands alone and starts on a new line.</p> </section> <section> <h2>My Hobbies</h2> <p>I enjoy painting, hiking, and reading books.</p> </section> <footer> <p>Contact info: email@example.com</p> </footer> </body> </html>
<div>, <p>, <header>, and <section>.<div> is a block-level element, while <span>, <img>, and <a> are inline elements.<header> are block-level and create sections.<img>, <button>, and <label> are inline or replaced elements, not block-level.<div>First</div> <span>Second</span> <div>Third</div>
<div> is block-level (new line), <span> is inline (same line).<span>Line 1</span> <span>Line 2</span> <span>Line 3</span>
<span> is inline, so all text appears on the same line.<span> with <div> makes each text block-level, forcing new lines.<section>, <header>, <p>, and <footer> are all block-level and semantically correct for sections.<div><span>Title</span><span>Para 1</span><span>Para 2</span><span>End</span></div> uses inline <span> incorrectly; <section><div>Title</div><div>Para 1</div><div>Para 2</div><div>End</div></section> uses <div> but misses semantic tags; <article><header>Title</header><span>Para 1</span><span>Para 2</span><footer>End</footer></article> mixes block and inline incorrectly.Pass the test and this pattern moves unknown