Is it necessary to write HEAD, BODY and HTML tags?

后端 未结 6 2147
清酒与你
清酒与你 2020-11-22 05:10

Is it necessary to write , and tags?

For example, I can make such a page:



        
6条回答
  •  不知归路
    2020-11-22 05:45

    It's true that the HTML specs permit certain tags to be omitted in certain cases, but generally doing so is unwise.

    It has two effects - it makes the spec more complex, which in turn makes it harder for browser authors to write correct implementations (as demonstrated by IE getting it wrong).

    This makes the likelihood of browser errors in these parts of the spec high. As a website author you can avoid the issue by including these tags - so while the spec doesn't say you have to, doing so reduces the chance of things going wrong, which is good engineering practice.

    What's more, the latest HTML 5.1 WG spec currently says (bear in mind it's a work in progress and may yet change).

    A body element's start tag may be omitted if the element is empty, or if the first thing inside the body element is not a space character or a comment, except if the first thing inside the body element is a meta, link, script, style, or template element.

    http://www.w3.org/html/wg/drafts/html/master/sections.html#the-body-element

    This is a little subtle. You can omit body and head, and the browser will then infer where those elements should be inserted. This carries the risk of not being explicit, which could cause confusion.

    So this

    
      

    hello

提交回复
热议问题