Basically HTML elements are consist of start tag, end tag and content inserted between them.
HTML document is made up of html elements.
Note: Some elements does not have content and end tag, those elements are called self closing or empty elements.(For e.g: <img>, <hr>, <br> ).
HTML documents consist of a tree of these HTML elements and they describe how HTML documents should be built, and what kind of content should be placed in what part of an HTML document.
Difference between HTML tags and HTML elements:
A tag is a part of an HTML element and an HTML element is the combination of a start-tag, content and end-tag.
For E.g: <p> This is a short paragraph </p>
In above example <p> and </p> are HTML tags and <p> is called opening tag while </p>is called closing tag. And the complete line <p>This is a short paragraph </p> is called HTML element.
Nested HTML Elements:
HTML tags are the block around the content. Sometimes, you need to place one element inside another element. Those “inner” elements are nested inside of others. Every HTML document consist of nested HTML elements.
Explanation of the above code:
The <html> element defines the whole document. The html element has start tag and end tag.
<body> element is inside the <html> element and inside the <body> element is two other elements i.e <h2> and <p>, which means body element is nested inside the html element and and <p> and <h2> elements are nested inside the <body> element.
Block level elements and inline elements:
HTML element has a default display value depending on the type of element.
The display values are: Block-level and inline
Block Level HTML Elements:
Inline HTML Elements:
Never forget the End Tag
Even if you forgot the end tag, some HTML elements will display correctly.
The following example works in all browsers because the closing tag is considered optional.
Never depend on this , because it might produce unexpected results and errors if you forget the end tag.