HTML Elements and Tags

A Website page is made up of multiple HTML elements and HTML element is made of HTML tags.

HTML Tags

HTML tags are like labels or keywords to define web page. These tags tells the browser about the format or structure of the content.

Most of the tags comes in pair. One is called opening tag and other is closing tag. Tags begin with a less-than sign “<" and end with a greater-than sign ">“. For example: <p></p> tags is used to create paragraph content. While <h1></h1> tags are used to create headings.


HTML Element

An element in HTML generally consists of an opening tag, content, and a closing tag. We can see the HTML element as an individual component of web-page.

Start/Opening Tag
HTML elements starts with opening tags. For example: <p><b><h1> etc.

End/Closing Tag
HTML elements ends with closing tags. For example: </p></b></h1> etc.

Content
We place content between the opening and closing tags. For example: <p>This is sample content.</p>


Nested HTML Elements

HTML elements can be nested. This means that the HTML element can contain many other elements inside.

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

Example Description: You can see that the above HTML page is made up of various HTML elements and tags. Some tags have nested tags inside as well.


HTML Empty Elements

HTML elements with no content are called empty elements. There are many empty elements that do not have closing tag.

For example: <br> is an empty element without a closing tag. It is used to create line break.

It is good to close every tags. Empty elements can be “closed” in the same Opening tag. For example: <br />

HTML5 does not require empty elements to be closed. But if you want strict validation, or if you need to make your document readable by XML parser, you must close all HTML elements properly.

HTML5 does not require empty elements to be closed. But if you want strict validation, or if you need to make your document readable by XML parser, you must close all HTML elements properly.


Tips while using HTML Tags:

  • Always close HTML tags to validate your webpage against W3C Validation Standard.
  • HTML5 standard does not require lowercase tags but W3C recommends to use lowercase in HTML

Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
Write a program to create a webpage to print values 1 to 5
Write a program to create a webpage to print your city name in red color.
Write a program to print a paragraph with different font and color.
Interview Questions & Answers
Do all HTML tags require both a begin and end tag?