Does my HTML5 doctype have to be on the VERY first line?

后端 未结 6 1228
心在旅途
心在旅途 2020-12-18 18:32

I\'ve always wondered whether whitespace before a DOCTYPE matters, but I can\'t seem to find any definitive information on the web. People say not to do it,

6条回答
  •  别那么骄傲
    2020-12-18 18:38

    To maximize the odds of avoiding Quirks Mode, put the doctype declaration at the very start of the HTML document. You won’t find any official statement on this, since Quirks Mode is about violating standards and about actual browser behavior. It is part of the very idea of Quirks Mode that it is largely undocumented; authors are not supposed to trust on it. It’s meant to make legacy pages behave tolerably (as they used to), not something that you should use for new pages.

    Modern browsers generally allow an empty line before the doctype, or a comment, or an XML declaration, without going to Quirks Mode. But just don’t put anything there, unless you have a compelling reason to do so.

提交回复
热议问题