What are Inline and block elements in HTML? Difference between them? Name a few inline and block elements.
Block level Elements
-> Block-level elements take up as much space as possible by default.
-> Each block-level element will start a new line on the page, stacking down the page.
-> In addition to stacking vertically, block-level elements will also take up as much horizontal space as possible.
Ex:
<p> --> Paragraph tag
<ol> --> Ordered List
<ul> --> Unordered List
<dl> --> Description List
All heading(h1 to h6)
<article>
<section>
Inline Elements
-> Inline elements display in a line. They do not force the text after them to a new line.
-> An anchor(or link) is an example of an inline element. You can put several links in a row, and they will display in a line.
Ex: <a> , <strong> , <em> , <b> , <i> , <q> , <mark> , <span>.
Block Elements vs Inline Elements
-> Every HTML element has a default method of displaying on the page. This default setting is determined by whether elements are considered block-level or inline.
Block Level Elements(difference)
Block-level elements have the following properties.
Always start on a new line.
Take up as much horizontal space as possible(the full width of the container or browser window if there is no container).
This will respect the width and height CSS properties.
Horizontal and vertical margins both work.
Inline Elements(Difference)
Inline elements have the following properties.
Do not start on a new line.
Only use as much horizontal space as required by the content.
Do not accept width and height CSS properties.
Margins will work horizontally, but not vertically.
Padding works on all sides, but the top and bottom may overlap with other elements.
Subscribe to my newsletter
Read articles from Biswojit Bal directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Biswojit Bal
Biswojit Bal
I am learning on Fullstack Web Development.