In this section, we will learn what the block and inline elements are and what their key differences are in HTML.
What is Block and Inline Level Elements in HTML?
Elements in HTML are divided into two categories:
- Block-level elements
- Inline level elements
Their main differences are on the way they are rendered on a page! In short, a block-level element will appear on a new line below the last element that was rendered on the page! Basically, block-level elements take their own new line and space. But when it comes to inline level elements, they appear on the right side of the last element that was rendered on the page (If enough space is available for that inline element to appear on the right side of the last element! Otherwise, it will appear on a new line).
Alright, now let’s go into the details of each category and learn more about them.
HTML Block Level Elements
As mentioned before, a block-level element needs its own new line and space! For example, the HTML <p> element is a block-level element! It needs its own new line and space! This means if you create two paragraphs using the <p> element, they appear below each other. This means each will take its own block.
Example: using block level elements in HTML
As you can see, in this example because the <h1> and <p> elements are block level type of elements, each got its own block and so they appeared below each other and not next to each other!
List of Block Level Elements in HTML
In the list below, you can see the block-level elements in HTML:
Long (“block”) quotation.
Describes a term in a description list.
Description list term.
Field set label.
Groups media content with a caption (see <figcaption>).
Section or page footer.
<h1>, <h2>, <h3>, <h4>, <h5>, <h6>
Heading levels 1-6.
Section or page header.
Groups header information.
Horizontal rule (dividing line).
Contains the central content unique to this document.
Contains navigation links.
Section of a web page.
HTML Inline Level Elements
On the other hand, we have the inline level elements. These elements, when their content are rendered on a page; they appear next to the last element (on the right side) of the document.
Basically, these types of elements don’t need a new block of the page! They can appear according to the document’s flow! So it might end up next to another element (if there’s enough space) or in a new line if there wasn’t enough space available after the last rendered element.
Example: using inline level elements in HTML
Here, the `<span>` element is an example of inline level type of element and as you can see, we used this element two times and they appeared next to each other.
List of Inline Level Elements in HTML
Here’s the list of inline level elements in HTML:
HTML display Property:
The display property is a CSS property and is used to change the level of an HTML element.
For example, one of the values that this property takes is called “block”. Now if you invoke this property on an inline level element and set the value “block” for it, then that inline level element changes its behavior and acts like a block-level element!
Note: this property takes other values as well. For example, one of the values is called “inline” and it is used to turn an element into an inline level type of element. You can learn more about this property in the CSS display property section.
Example: display block in HTML
As you can see, the <span> element was an inline level type of element. But, after applying the `display` property on it and set the value `block` for this property, the behavior of the element changed and acted like a block-level element thus.