I have found several doubts about the difference when working with these types of elements in CSS.
So what are the differences between these elements?
I have found several doubts about the difference when working with these types of elements in CSS.
So what are the differences between these elements?
Summary
To put it simply, certain HTML tags are not affected by the flow of other elements, just limited to their natural usage.
Inline or inline elements
An example of these tags could be
<a>
,<em>
and perhaps the most useful of all<span>
, all these elements are called "inline", because by default they carry theirdisplay: inline
, without the need to specify it in a CSS document.Imagine that we have the following scenario:
As we can see, all the X Boxes have the inline property (despite not being defined in the CSS) and they align with each other but widths, heights, and much less vertical margins are not respected.
Block or block elements
On the contrary, there are block elements, which are not mixed with the rest of the elements, being shown in independent "lines".
Going back to the same scenario but changing the inline elements to block elements, we will have the following result:
As I mentioned, now the block elements are displayed in independent "lines" but above all, they already respect widths, heights and vertical margins.
Inline block or inline-block element
We have just seen the block elements and the inline elements, now it is time to continue with the inline-block element.
This element is a mixture of both, being able to align but also respects height, width and vertical margins.