In HTML, a block element is a type of HTML element that occupies the entire width of its parent element by default, creating a block-level box. It starts on a new line and typically stretches from the left edge to the right edge of its containing element. Block elements are commonly used to structure the layout and organization of content on a web page.
HTML Blocks
Here's an example of a block-level element, specifically the <div> element :
<div>
This is a block-level element.
</div>
Block elements can be used for various purposes such as grouping elements, creating sections, defining layout structures, and applying styles. Some commonly used block-level elements include <div>, <p>, <h1> to <h6> (heading elements), <ul> (unordered list), <ol> (ordered list), and <section>.
Here are a few more examples of commonly used block-level elements in HTML:
<p> - Represents a paragraph of text.
<div>
<p>This is a paragraph.</p>
</div>
This is a paragraph.
<h1> to <h6> - Heading elements
where <h1> represents the highest level of heading and <h6> represents the lowest level.
<div>
<h1>This is a heading</h1>
<h2>This is a subheading</h2>
</div>
<ul> - Unordered list
typically used to create bullet point lists.
<div>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>
- Item 1
- Item 2
- Item 3
<ol> - Ordered list
used to create numbered lists.
<div>
<ol>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ol>
</div>
- First item
- Second item
- Third item
<div> - A generic block-level container
Can be used to group and organize other elements.
<div>
<div>
<h3>Section Title</h3>
<p>Content goes here.</p>
</div>
</div>
Section Title
Content goes here.
<section>
Represents a standalone section of content on a web page.
<div>
<section>
<h2>About Us</h2>
<p>Some information about our company.</p>
</section>
</div>
<header>
Typically used to define the header section of a document or a section within it.
<header>
<h1>Welcome to our website</h1>
<nav>
<!-- Navigation links here -->
</nav>
</header>
These are just a few examples, and there are many other block-level elements available in HTML. Remember that the choice of which element to use depends on the specific purpose and structure of your web page.