HTML 文件的 Doctype 或 Comment 中哪个必须排在第一位?

Which has to be first on a HTML document Doctype or Comment?

在适当的html文档中,应该先写哪一个。文档类型或注释。

喜欢

<!--
    Copyright (C) 2014 so and so pvt ltd.
    @file index.html
-->
<!DOCTYPE html>

或者

<!DOCTYPE html>
<!--
    Copyright (C) 2014 so and so pvt ltd.
    @file index.html
-->

8.1 Writing HTML documents

Documents must consist of the following parts, in the given order:

  1. Optionally, a single "BOM" (U+FEFF) character.
  2. Any number of comments and space characters.
  3. A DOCTYPE.
  4. [...]

因此,无论您是先写文档类型再写注释,反之亦然。

但是,HTML 验证程序警告说,如果您在文档类型之前使用注释,IE 将进入怪癖模式。所以最好先使用文档类型。