HTML Elements
The start tag, certain contents, and the end tag define an HTML element.
HTML Elements
Everything from the start tag to the end tag is considered an HTML element:
Your first paragraph.Your First Heading
Start tag | Element content | End tag |
---|---|---|
<h1> | My First Heading | </h1> |
<p> | My first paragraph. | </p> |
<br> | none | none |
Note: Some HTML items contain no content (such as br). These elements are known as vacuum elements. There is no end tag for empty items!
Nested HTML Elements
HTML components may be nested, which means they may be stacked on top of each other (this means that elements can contain other elements).
Nested HTML elements may be found in any HTML document.
Four HTML elements (<html>
, <body>
, <h1>
and <p>
) are used in the example below:
Example
Your First Heading
Your first paragraph.
Result of the above query
Your First Heading
Your first paragraph.Example Explained
The root element is the html
tag, which defines the whole HTML page.
There is a html
start tag and a /html
end tag.
Then, there is an element body
within the html
element:
Your First Heading
Your first paragraph.
The element body
specifies the body of the document.
It has a body
tag at the beginning and a /body
tag at the conclusion.
Then there are two more components inside the body
element: h1
and p
:
My First Heading
My first paragraph.
A heading is defined using the h1
element.
It has a h1
beginning tag and /h1
ending tag:
Your First Heading
A paragraph is indicated with thep
element.
It has a p
start tag and a/p
end tag:
Your first paragraph.
Related Links
Never Skip the End Tag
Even if you forget the end tag, certain HTML components will show correctly:
Example
This text is a paragraph
This text is a paragraph
In the example above, we did not close the end tag </b>
.
Result of the above query
This text is a paragraph
This text is a paragraphHowever, you should never rely on this! If you neglect to include the end tag, you may receive unexpected results and problems!
Empty HTML Elements
HTML elements that have no content are referred to as empty elements.
The tag br
denotes a line break and is a blank element that has no closing tag:
Example
It is a
paragraph with a line break.
Result of the above query
paragraph with a line break.
Related Links
HTML is Not Case Sensitive
The case of HTML tags is unimportant: P
is the same as p
.
Although lowercase tags are not required by the HTML standard, the recommends them in HTML and requires them in stricter document types like XHTML.