HTML Elements

HTML Elements represent semantics, or meaning. The title element, for example, represents the document's title. Most HTML elements are written with a beginning tag (or opening tag) and an end tag (or closing tag) with the content between them.

<tagname>Content goes here...</tagname>

The HTML element is everything from the start tag to the end tag:

<p>My first paragraph.</p>

Table: Few HTML Tags
Start tag Element content End tag
<h1> Our First Heading </h1>
<p> My first paragraph </p>


Note: HTML - free elements are referred to as empty elements. Empty elements, like the < br > element (which indicates a line break), do not have an end tag.

 

 

Nested HTML Elements

It is possible to nest HTML elements (elements may contain elements).
All HTML documents consist of nested HTML elements.

This example contains four HTML elements:

<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>

Output:

My First Heading

My first paragraph.

 

Example Explained

The <html> element defines the whole document.
It has a start tag <html> and an end tag </html>.
Another HTML element (the < body > element) is the content of the element.

<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>

The <body> element defines the document body.
It has a start tag <body> and an end tag </body>.
The element content is two other HTML elements (<h1> and <p>).

<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>

The <h1> element defines a heading.
It has a start tag <h1> and an end tag </h1>.
The element content is: My First Heading.

<h1>My First Heading</h1>

The <p> element defines a paragraph.
It has a start tag <p> and an end tag </p>.
The element content is: My first paragraph.

<p>My first paragraph.</p> 

Do Not Forget the End Tag
Some HTML elements will display correctly, even if we forget the end tag:

Example

<html>
<body>
<p>This is a paragraph<p>
This is a paragraph
</body>
</html>

 

The example above works in all browsers, because the closing tag is considered optional.
Never rely on this. If we forget the end tag, it may produce unexpected results and/or errors.

 

 

Empty HTML Elements

HTML - free elements are referred to as empty elements.
<br> is an empty element without a closing tag (the <br> tag defines a line break).
Empty elements can be \"closed\" in the opening tag like this: <br />.
HTML5 does not require the closing of empty elements. But if we want more stringent validation, or if we need XML parsers to make your document readable, we need to close all HTML elements properly.

Use Lowercase Tags

HTML tags are not case sensitive:
<P> means the same as <p>.
The standard HTML5 does not require lowercase tags, but W3C recommends lowercase in HTML, and requires lowercase for more stringent types of documents such as XHTML.

HTML Tag vs. Element

A start tag defines an HTML element. If the element contains other content, a closing tag will end.
For example, <p> is starting tag of a paragraph and </p> is closing tag of the same paragraph but <p> this is paragraph </p> is a paragraph element.