For curiosities sake, why is the <img> tag not closed in HTML?
<img src="smiley.gif" alt="Smiley face" height="42" width="42">
I also noticed that <img> tags are explicitly closed in XHTML...
<img src="smiley.gif" alt="Smiley face" height="42" width="42"/>
W3Schools: Image Tag
Create an image tag using the abbreviation img. This is considered a self closing tag, since it doesn't need to wrap text as many other tags do. The / right before the ending > is optional, but helps remind us that this tag doesn't need a closing tag. The src attribute is short for source.
The <img /> Tag This tag is different than other tags, in that it has no closing tag. It is called a self-closing tag, which means that there is just a slash at the end of the opening tag (ex. <img />). There are very few self-closing tags in HTML.
Historically, HTML has been based on SGML which allows tags to be omitted under certain conditions.
Since the <img>
element cannot have any child nodes, it is defined as EMPTY and the end tag is forbidden (as it would serve no purpose).
XHTML is HTML expressed in XML, and XML does not support optional or forbidden tags (although it allows a self-closing tag to substitute for a start+end tag pair), so it has to be explicitly closed there.
HTML 5 is backwards compatible with versions of HTML that were SGML based.
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