Multiple Doctypes in a single HTML Document

前端 未结 3 464
日久生厌
日久生厌 2021-01-18 05:29

If a HTML document has two doctypes, how will the doctypes affect the rendering of the page and which doctype would the browser pick? Is having two (or more) doctypes in a s

3条回答
  •  深忆病人
    2021-01-18 05:37

    I believe the very first DOCTYPE is used by the browser and it's against the specification to have more than one in a document.

    I think (not sure) that the only situation when multiple DOCTYPE-s may be valid is when using IE conditional comments. Browsers other than IE won't see those, of course.

    I remember reading a blog entry (can't find it now, so I may be wrong in this) but some (most?) browsers even ignore the DOCTYPE if it's not the first thing they encounter. (This may have been a bug that got fixed since.)

    Here's W3School's reference page about DOCTYPE:

    http://www.w3schools.com/tags/tag_doctype.asp

提交回复
热议问题