An HTML element is defined by a starting tag. If the element contains content then it ends with a closing tag and the element name is preceded by a forward slash. The syntax of HTML element is:
<tagname>Content goes here…</tagname>
The HTML element is everything from the start tag to the end tag:
<h1>My First Heading</h1>
<p>My first paragraph. </p>
Nested HTML Elements
HTML elements can be nested which means that elements can contain other elements. All HTML documents consist of nested HTML elements. The HTML tag is the main tag which contains other tags inside its structure. The following example below contains four HTML elements (<html>, <body>, <h1> and <p>).
<!DOCTYPE html> <html> <head> <title>Programming tutorial</title> </head> <body> <h1>Welcome to programming tutorial</h1> <p>A platform of learning basic programming concepts.</p> </body> </html>
The <html> element is the root element and it defines the whole HTML document. It has a start tag <html> and an end tag </html>.
Then, inside the <html> element there is a <body> element. The <body> element defines document’s body and starts with <body> tag and ends with </body> tag. Inside <body> element there are two other tags <h1> and <p>.
<h1> defines heading of document which starts with <h1> and ends with </h1> tag and <p> defines paragraph which starts with <p> and ends with </p>.
Empty HTML Elements
HTML elements with no content are called empty elements. These elements have only starting tag. The examples of empty HTML elements are <br> and <hr>.