Before we start learning what is a tag? I prefer you just go through an article on: Basics of HTML

There are mainly two type of tags:

  • First type of tags are those in which nesting of other or same tag is possible. It can be written as

    <tag> Data here </tag>
    These tags are also called as paired tags whereby we have an opening tag written as <tag> and we have a closing tag written as </tag>

  • Second type of tags are those in which such nesting is not possible. It can be written as
    <tag />
    These tags are also called as unpaired tags.

Generalized format/syntax to write a tag.

<tag_name attribute_name1=”value1” attribute_name2=”value2”>
Data here

Eg. : <hr> tag will create a horizontal line but as we cannot write anything inside a line, this tag is an unpaired tag and written as <hr/>.

Now what if want to display a line in red color? Do we have any other tag for it? Answer to it is NO, we can achieve this using the same <hr/> tag. For that we have arguments in <hr/> tag which are known as attributes. Each attribute will have value assigned to it.
<hr color=”red” / >
This will display the line in red color.
By default line generated by using <hr/> tag will occupy the 100% width of the browser. To change the width of line we have another attribute known as width.
<hr color=”red” width=”400px” />

Ordering in nesting of tags

When tags are nested at that time the sequence of starting and ending tag must be in LSFC (last start first close) order.
Eg. <b><i> Data  </i></b>
This is not the correct order. Rather the code must be written as follows:
<b><i> Data  </i></b>