WikiGalaxy

Personalize

HTML Block & Inline Elements

HTML(Hyper Text MarkUp Language)

elements are the building blocks of web pages. These elements define the structure and content of a web page, and they can be broadly classified into Block Elements and Inline Elements. Understanding their differences and uses is crucial for creating well-structures and visually appealing web content.

Block Elements

Block elements create a block-level box that starts on a new line and takes up the full width of its parent container by default. They are typically used to define large sections of content, such as headings, paragraphs, and divisions.

Common Block Elements

<div>:Generic container for grouping content.

<p>: Represents a paragraph.

<h1> to <h6>:  Define headings.

<ul> and <ol>Unordered and ordered lists.

<table>:Defines tabular data.

Example 1: Basic Block Elements


<!DOCTYPE html>
<html>
<head>
  <title>Block Elements Example</title>
</head>
<body>
  <h1>This is a Heading</h1>
  <p>This is a paragraph, demonstrating block-level behavior.</p>
  <div>
    <p>This is inside a <div> container.</p>
  </div>
</body>
</html>

Output:

  • A large heading.

  • A paragraph below the heading.

  • Another paragraph nested inside a <div>.

Example 2: Nested Block Elements


<!DOCTYPE html>
<html>
<head>
  <title>Nested Block Elements</title>
</head>
<body>
  <div>
    <h2>Nested Content</h2>
    <p>This is a paragraph within a <div> element.</p>
    <div>
      <p>This is a nested <div> with another paragraph.</p>
    </div>
  </div>
</body>
</html>

Output:

  • A structured layout with nested sections.

Inline Elements

Inline elements do not start on a new line and only take up as much width as necessary. They are typically used to style a portion of text or insert small elements within a block-level container.

Common Inline Elements

<span>:  Generic container for inline content.

<a>:   This is the description of the point with a yellow heading. The description text is styled with a light gray for clarity.

<strong> & <em>:  Add semantic emphasis.

<img>:  Insert images here.

<code>:  Represents inline code snippets.

Example 1: Basic Inline Elements


<!DOCTYPE html>
<html>
<head>
  <title>Inline Elements Example</title>
</head>
<body>
  <p>
    This is a <strong>bold</strong> word and this is <em>italicized</em>.
    Click <a href="#">here</a> to learn more.
  </p>
</body>
</html>

Output:

A paragraph with bold, italicized text and a hyperlink.

Example 2: Inline with Images


<!DOCTYPE html>
<html>
<head>
  <title>Inline Images</title>
</head>
<body>
  <p>
    This is an inline image: <img src="example.jpg" alt="Example" width="100">.
  </p>
</body>
</html>

Output:

A paragraph with an inline image.

Feature

Block Elements

Inline Elements

Start on New line

Yes

No

Width

Takes full width of container

Only as wide as content

Width

<div>, <p>, <h1>

<span>, <a>, <img>

Helps structure HTML Elements.
Effective Layout Design.

Understanding the behavior and use cases of block and inline elements is essential for structuring web pages effectively.

Block & Inline Elements.
Block Elements.

Block elements are suitable for creating sections, while inline elements are perfect for emphasizing or embedding content within these sections. 

Mastering Both

Mastering both types of elements ensures well-organized and semantically rich HTML documents.

logo of wikigalaxy

Newsletter

Subscribe to our newsletter for weekly updates and promotions.

Privacy Policy

 • 

Terms of Service

Copyright © WikiGalaxy 2025