What is HTML Tag

HTML tags are like keywords that define how the web browser will format and display the content. With the help of tags, a web browser can differentiate between an HTML content and a simple content. HTML tags have mainly three parts that are: the opening tag, the closing tag, and the contents. But some HTML tags are unclosed (not closed) tags.

When a browser reads an HTML pages, the Web browser reads it from top to bottom and from left to right. HTML tags are used to create HTML documents and render their properties. Each HTML tag has different properties.

An HTML file must contain some required tags so that the web browser can differentiate between a simple text and HTML text. You can use as many tags as you want according to your code requirement.

  • All HTML tags must be enclosed in < > parentheses.
  • Each tag in HTML performs a different function.
  • If user used an open tag <tag>, then must be a close tag </tag> (except for some tags).

Syntax

<tag> content </tag>


Example of Html Tags

<!DOCTYPE html>

<html>

<body>


<h1>My First Heading</h1>


<p>My first paragraph.</p>


</body>

</html>



Rules of html Tags

  • Tags are always surrounded by angle brackets (less than/greater than characters), as in <body> .
  • There should be no space between any tags.
  • Tags are not case sensitive, you can also write it in capital or small letter. But generally it is better to be written in small letter only. don't write with mix small and capital
  • Whenever you open the tags, it is necessary to write its closing tags as well. If you do not write, then the formatting of that tag will be applied till where you will get the closing tags worth it.

Types Of Html Tags

There are Two Types Of Html Tags

  1. Container / Pair tag
  2. Empty / Singular tag

Container / Pair tag:

Container tags are also known as paired or on-off tags. Tags in which both opening and closing tags are available are called container/pair/on-off tags. In another words, the tag used in pair is called container tag/pair tag/on-off tag. opening tag and closing tag both are similar but in opening tag there are no slash before tag name whenever in closing tags, forward slash (/) is placed before tags name.

This tag defines a section, meaning that the container tag tells how far the formatting of this tag is to be applied.

Syntax

<tagname>......</tagname>

Html container tag names

There are some paired tags name

  • <button>…</button>
  • <div>…</div>
  • <nav>…</nav>
  • <p>…</p>
  • <style>…</style>
  • <b>…</b>

Empty / Singular Tag

Empty tag is also called Singular or Stand Alone tag. Those tags which do not have closing tags are called empty tags. The tag in which the content is not available is called empty tag.

Sometimes container tags also fall under the category of empty tags, if there is no content available in them. Like <p> </p> it will be an empty tag because no content is available inside it and if the content is made available inside it then it will come under the category of container tag.

Syntax

<tag_name />

Html empty tag names

There are some singular tags name

  • <br />
  • <img />
  • <input />
  • <hr />
  • <link />
  • <meta />

Example of Html paired tag and empty tags