What are the actual problems of not closing tags and attributes in HTML

后端 未结 6 1055
走了就别回头了
走了就别回头了 2021-01-11 15:44

Recently a friend decided not to close his tags or attributes in HTML because it\'s not required and he\'ll save some bandwidth and download time. I told him it\'s a bad ide

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-11 16:23

    Most HTML tags are containers. Consider:

    
    
    Stuff inside a section
    Stuff outside a section

    Other text

    In this example, "Stuff inside a section" would be red text, "Stuff outside a section" is not red. In this example:

    
    
    Stuff inside a section Stuff outside a section

    Other text

    ... in this example, "Stuff inside a section", " Stuff outside a section", and "Other text" would ALL be red - that is, the section never ended. The browser may try to assume where the section could have ended, but in my above example the only assumption possible is that the section continues to the end of the document, which is not what was intended.

    In short, not closing HTML tags just makes things more confusing for you, will cause pages to render inconsistently from expectations and between browsers, and is just generally a bad idea. So bad, in fact, that it shouldn't even be taken as a serious suggestion at all. Your friend has clearly never developed an actual web site.

提交回复
热议问题