The HTML element encompasses all content between the start tag and the end tag.
<tagname>Content goes here…</tagname> |
Examples of some HTML elements:
<h1>My First Heading</h1> |
<p>My first paragraph.</p> |
Start tag |
Element content |
End tag |
<h1> |
First Heading |
</h1> |
<p> |
first paragraph. |
</p> |
<br> |
none |
none |
Note: Certain HTML elements, such as the <br> element, lack content and are termed empty elements. They do not require an end tag. |
HTML elements can be nested, which implies that elements can contain other elements within them.
Every HTML document comprises nested HTML elements.
The subsequent illustration comprises four HTML elements: <html>, <body>, <h1>, and <p>.
Example
<!DOCTYPE html> <html> <body> <h1>My First Heading</h1> <p>My first paragraph.</p> </body> </html> |
The <html> element serves as the root element, defining the entirety of the HTML document.
It includes both an opening tag <html> and a closing tag </html>.
Within the <html> element, you’ll find the <body> element.
<body> <h1>My First Heading</h1> <p>My first paragraph.</p> </body> |
The <body> element outlines the body of the document.
It consists of both an opening tag <body> and a closing tag </body>.
Within the <body> element, there are two additional elements: <h1> and <p>.
<h1>My First Heading</h1> <p>My first paragraph.</p> |
The <h1> element specifies a heading.
It includes both an opening tag <h1> and a closing tag </h1>.
<h1>My First Heading</h1> |
The <p> element delineates a paragraph.
It comprises an opening tag <p> and a closing tag </p>.
<p>My first paragraph.</p> |
Certain HTML elements will render correctly even if you overlook the closing tag.
Example
<html> <body> <p>This is a paragraph <p>This is a paragraph </body> </html> |
Nevertheless, it’s not advisable to depend on this behavior! Forgetting the closing tag may lead to unexpected outcomes and errors!
Empty elements in HTML have no content.
The <br> tag, which signifies a line break, is an example of an empty element that lacks a closing tag.
Example
<p>This is a <br> paragraph with a line break.</p> |
HTML tags are insensitive to case: <P> is equivalent to <p>.
While the HTML standard doesn’t mandate lowercase tags, C7S suggests using lowercase in HTML and mandates lowercase for more rigorous document types such as XHTML.