In HTML5 there are tags that must have a starting and an ending tag even when their content is empty:
<script></script> <!-- Right way. -->
<div></div> <!-- Right way. -->
<content></content> <!-- Right way. -->
<script/> <!-- Wrong way. -->
<div/> <!-- Wrong way. -->
<content/> <!-- Wrong way. -->
In XML this difference doesn't exist:
<node/>
and <node></node>
are the same entity.
Why tags like script
, div
and content
can't be defined simply as:
<script/>
, <div/>
and <content/>
?
The void elements or singleton tags in HTML don't require a closing tag to be valid. These elements are usually ones that either stand alone on the page or where the end of their contents is obvious from the context of the page itself.
An opening tag begins a section of page content, and a closing tag ends it. For example, to markup a section of text as a paragraph, you would open the paragraph with an opening paragraph tag <p> and close it with a closing paragraph tag </p> (closing tags always proceed the element with a /).
No, all HTML tags don't have end tag. Example- <br> tag is used to break the line. It doesn't have an end tag. However most of the tags have end tags.
↑ The full list of valid self-closing tags in HTML5 is: area, base, br, col, embed, hr, img, input, keygen, link, meta, param, source, track, and wbr.
From the w3c:
A Self-closing tag is a special form of start tag with a slash immediately before the closing right angle bracket. These indicate that the element is to be closed immediately, and has no content. Where this syntax is permitted and used, the end tag must be omitted. In HTML, the use of this syntax is restricted to void elements and foreign elements. If it is used for other elements, it is treated as a start tag. In XHTML, it is possible for any element to use this syntax. But note that it is only conforming for elements with content models that permit them to be empty.
The examples you listed would generally contain content, JavaScript, or other elements, so having a proper start and end tag would delimit the scope of those elements/tags.
Simply because they are basically some "container" for other elements.
There are elements which are didn't used as parent elements for others, like img or base for example, this one can be closed without an closing tag with a trailing />, but it is not necessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With