Why is the

后端 未结 5 1030
太阳男子
太阳男子 2020-11-27 19:04

For curiosities sake, why is the <img> tag not closed in HTML?

\"Smiley

        
5条回答
  •  半阙折子戏
    2020-11-27 19:14

    Historically, HTML has been based on SGML which allows tags to be omitted under certain conditions.

    Since the 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.

提交回复
热议问题