Is it safe to omit and tags?

后端 未结 10 2084
广开言路
广开言路 2020-12-05 22:41

According to w3c and tags are optional, so the following table is perfectly valid.



        
      
      
      
10条回答
  •  悲&欢浪女
    2020-12-05 23:07

    There have been optional tags in HTML since the very beginning — they are a feature inherited from SGML, and so the early browsers must have been able to deal with them. While XHTML moved away from this and required a much more uniform syntax, this doesn’t affect you unless you explicitly tell the browser to parse in XML mode. I’ve never seen a problem when using the standard parsers of HTML 4/5.

    Since HTML5 so carefully describes when certain tags are optional, I would read that to imply that someone did lots of testing to make sure that in these cases, most browsers produce the same document tree.

    And while the space savings are negligible, I find that leaving off the closing tags of

    ,

  • ,
simply makes my life easier when I’m working in the markup, and makes me less likely to make an error.

提交回复
热议问题
, and