In this article, we will know the HTML Elements, along with understanding the various available elements & their syntax through the examples. An HTML element is the collection of start and end tags with the content inserted in between them.
<tagname > Contents... </tagname>
Supported Tags: HTML Elements supports almost all HTML Tags.
HTML Element: The HTML element consist of 3 parts.
i) Opening tag: It is used to tell the browser where the content material starts.
ii)Closing tag: It is used to tell the browser where the content material ends.
iii)Content: It is the actual content material inside the opening and closing tag.
Combining all these 3 parts results in an overall HTML Element.
Example 1: In this example <p> is a starting tag, </p> is an ending tag and it contains some content between the tags, which form an element
Example 2: This example illustrates the use of the HTML paragraph element.
Welcome to GeeksforGeeks!
Nested HTML Elements: The HTML element is use inside the another HTML Element is called nested HTML elements.
Example 3: This example describes the use of the Nested HTML elements. Here, <html> tag contains the <head> and <body>. The <head> and <body> tag contains another elements so it is called nested element.
Necessary to add end tag: It is necessary to add the end tag of an element. Otherwise, the displayed content may or may not be displayed correctly. It is a good practice if you add closing tags to the non-void HTML Elements but nowadays browsers are getting more and more advanced and forgiving in nature and that’s why if you somehow forget to apply the closing tag in the non-void Element, the browser will not throw any error but the problem will arise as you insert more and more HTML elements after that.
This Image is showing the Browser’s Developer Tools and you can see that the missing closing tag of the paragraph element in the above-written code is automatically added by the browser without showing any error.
The Final Output is:
A web browser is forgiving but it doesn’t mean that you start ignoring the ending/closing tag of the HTML elements. It might show some unexpected behaviour or error in some cases. Like if you have more than one HTML element on your webpage then omitting the closing tag might result in clashing of the boundaries of different HTML elements. The browser won’t know where it ends. It will take the next tag and think it belongs to the previous tag without the closing tag.
Final Summary of the above text segment: Always put the closing tag to a non-void HTML element.
Example 4: This example describes the HTML element by specifying the end tag.
Empty HTML Elements: HTML Elements without any content i.e, that do not print anything are called Empty elements. Empty HTML elements do not have an ending tag. For instance. <br>, <hr>, <link>, <input> etc are HTML elements.
Example 5: In this example <br> tag doesn’t print anything. It is used as a line break that breaks the line between <h2> and <p> tag.