← Learning Hub
Intermediate

Block vs Inline, div, span and Entities

Every element is either block or inline.

  • Block elements start on a new line and take the full width: <div>, <p>, <h1>, <ul>, <section>.
  • Inline elements sit inside a line of text and take only the space they need: <span>, <a>, <strong>, <img>.

Knowing whether an element is block or inline explains many layout surprises: why two divs stack on top of each other, why a link sits inside a sentence, or why setting a width on a span does nothing. CSS can change this behaviour with the display property, which you'll learn in the CSS course.

Example
<!DOCTYPE html>
<html>
  <head>
    <style>
      div  { background: #dbeafe; margin: 4px 0; }
      span { background: #fde68a; }
    </style>
  </head>
  <body>
    <div>I am a block. I take the whole width.</div>
    <div>Me too.</div>
    <p>This sentence has an <span>inline span</span> in the middle.</p>
  </body>
</html>
▶ Try it yourself

div and span

<div> and <span> have no meaning of their own. They are boxes you use to group things for CSS or JavaScript: div for blocks, span for words inside a line. When a meaningful tag exists (<nav>, <article>, <button>), prefer it.

HTML entities

Some characters have a special job in HTML, so you write them as entities:

Entities exist because < and > are how the browser recognises tags. If you want to show the symbol itself (for example in a tutorial about HTML, like this one!), you must write it as an entity so the browser doesn't think a tag is starting.

  • &lt; shows < and &gt; shows >
  • &amp; shows &
  • &quot; shows " inside an attribute
  • &nbsp; is a space that never breaks the line ("₹&nbsp;500" keeps ₹ and 500 together)
  • &copy; shows ©, &rarr; shows →
Example
<p>In HTML, write &lt;p&gt; to start a paragraph.</p>
<p>Tom &amp; Jerry</p>
<p>Price: ₹&nbsp;500</p>
<p>&copy; 2026 My Shop</p>
▶ Try it yourself
With <meta charset="UTF-8"> you can type most symbols directly (₹, ©, emojis). You still need entities for <, > and &.
Key points
  • Block elements start on a new line; inline elements sit inside text.
  • div and span are meaning-less boxes for grouping.
  • Write &lt; &gt; &amp; to show < > &.

📝 Test yourself

1. Which of these is an inline element?
2. How do you show a < sign as text?
3. Fill in the entity for a space that never breaks the line:
₹&;500