In HTML, elements are categorized into two main types based on their display behavior: block-level elements and inline-level elements.
A block-level element is an element that typically starts on a new line and stretches the full width of its containing element, creating a "block" of content. Block-level elements are often used to structure the layout of a webpage, and they can contain other block-level or inline-level elements.
Examples of block-level elements include:
: A generic container used to group and structure content.
: Represents a paragraph of text.
, , ..., : Heading elements, each indicating a different level of heading.
,
, : Elements for creating unordered and ordered lists.
, , : Elements for creating tables and their components.
Here's a simple example to illustrate block-level elements:
<div>
<h1>Main Heading</h1>
<p>This is a paragraph of text.</p>
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</div>
In this example, , , ,
, and are block-level elements. They create distinct blocks of content within the HTML document.
Understanding the distinction between block-level and inline-level elements is important for structuring the layout of a webpage and applying appropriate styles to different types of content.