MyInternships.in

HTML Basics

HTML Block and Inline Elements

Every HTML element is either block-level or inline by default, and that determines how it sits on the page. Understanding this difference is key to controlling layout.


What are Block and Inline Elements?

A block-level element starts on a new line and stretches to fill the full width available. Headings, paragraphs, and <div> are block elements — they stack vertically like boxes.

An inline element only takes up as much width as its content and sits within a line of text without breaking it. Links, <strong>, and <span> are inline elements — they flow alongside the surrounding words.

Basic Usage

Block stacks, inline flows
Example
<div>Block element (new line, full width)</div>
<span>Inline element</span> <span>stays on the same line</span>

Example: See the Difference

Coloured backgrounds reveal the width
Example
<!DOCTYPE html>
<html>
<body>
  <div style="background:#cfe2ff;">Block 1 fills the whole width.</div>
  <div style="background:#d1e7dd;">Block 2 starts on a new line.</div>

  <p>
    Inline elements like
    <span style="background:#f8d7da;">this span</span> and
    <span style="background:#fff3cd;">this one</span>
    sit inside the text.
  </p>
</body>
</html>

More Examples

div is a generic block container
Example
<div style="border:2px solid #0d6efd; padding:12px;">
  <h3>A card</h3>
  <p>The div groups these elements into one block.</p>
</div>
span targets a piece of text
Example
<p>Your balance is
  <span style="color:green; font-weight:bold;">₹1,200</span>
  as of today.</p>

Block vs Inline at a Glance

FeatureBlockInline
Starts on new lineYesNo
Takes full widthYesNo
Width / height settableYesNot by default
Examplesdiv, p, h1, ul, lispan, a, strong, em, img
💡

Use <div> as a generic block container and <span> as a generic inline container. Neither adds meaning — reach for semantic tags first, and use these only when no better tag fits.

ℹ️

You can change an element's behaviour with CSS: display:inline, display:block, or display:inline-block override the default.

Key Takeaways

  • Block elements start on a new line and fill the width.
  • Inline elements flow within text and hug their content.
  • <div> is a block container; <span> is an inline container.
  • CSS display can switch an element between block and inline.

Related HTML Topics

Keep learning with these closely related tutorials.

Ready to use your HTML skills?

Find web development internships and fresher jobs across India.

Browse Web Dev Internships