Types of HTML Tags : How Elements Behave on the Web Page

In HTML, elements are categorized into two main types: inline elements and block elements. These categories determine how elements behave in relation to other elements on the page and how they affect the flow of content.

html elements behave on the page

Inline Elements

Inline elements do not start on a new line and only take up as much width as necessary. They do not force a new line to begin after the element. Inline elements allow other elements to sit to their left and right on the same line. They only take up as much width as necessary, allowing content to flow around them.

Examples of Inline Elements

   <span>

   <a> (anchor)

   <strong> (strong)

   <em> (emphasis)

   <img> (image)

   <br> (line break)

Code Example

<p>This is an <strong>inline</strong> element.</p>


Block Elements

Block elements typically start on a new line and take up the full width available. They create a "block" or "box" of content. Block elements create a new "block" or "box" of content, pushing elements above and below them onto new lines. They typically take up the full width of their container, stretching from the left edge to the right edge.

Examples of Block Elements

   <div>

   <p> (paragraph)

   <h1> to <h6> (headings)

   <ul>, <ol>, <li> (lists)

   <table> (table)

   <form> (form)

Code Example

<div>This is a block element.</div>


Inline-Block Elements

Inline-block elements combine features of both inline and block elements. They do not start on a new line, and they only take up as much width as necessary, but you can apply block-level styling to them. Inline-block elements allow other elements to sit to their left and right on the same line. They can be styled with block-level properties like width and height.

Examples of Inline-Block Elements

   <span> with "display: inline-block;"

   <img> with "display: inline-block;"

Code Example

<span style="display: inline-block;">This is an inline-block element.</span>


Understanding the distinction between inline and block elements is essential for structuring HTML documents and applying appropriate styling. Inline elements are useful for small, inline-level content, while block elements are more suitable for larger, block-level sections of content.

Post a Comment

0 Comments