What is the main difference between
and
in html markup? Can someone explain the main difference of the two because it\'s confus
In practice, </br>
does not exist. Just <br>
or <br />
.
However, the difference is the position, and is universal for all XML tags. <TAG_NAME>
indicates the beginning of a tag, and </TAG_NAME>
indicates the end of a tag. When a tag is used with nothing between it, then a self-closing, or null tag can be used, which combines the beginning and end. It looks like <TAG_NAME />
.
In XML, any tag can be self closing, however, with HTML, only tags which are defined as such should be used that way. So you should never do <div />
, instead you should use <div></div>
, even if it's empty. Some self closing tags in HTML are, as already noted, <br />
, also things like <param />
, <input />
and <track />
. You can view the full list here.
So, basically, elements in the link above are allowed to be self closing. They often have attributes to indicate their data, but no additional elements are allowed inside of them. Other elements, which can have additional elements inside of them require both <TAG>
and </TAG>
to be complete.
Note that under less strict rules, in HTML, self closing tags do not require the ending slash, so <br>
is equivalent to <br />
. However, the latter form is preferred, and much cleaner looking. Also, any tags that aren't self closing, that aren't closed property (i.e. has a </TAG>
) will cause you a nightmare because elements will have a parent who should be a sibling.
Hope that helps.