Whats the point of DOCTYPE?

后端 未结 8 1045
夕颜
夕颜 2020-12-06 17:56

I know that different doctypes are essentially about how compliant the html is, but what difference does it make what doctype you specify? Do browsers handle the same code d

8条回答
  •  抹茶落季
    2020-12-06 18:32

    Browser Modes

    Back in the past, Browsers implemented CSS to their own rules.
    Only over the years have Browser now adapted the W3C standards.

    To make sure that websites rendered correctly various browsers, web developers had to implement CSS according to the wishes of these browsers. Thus, most websites used CSS in ways that didn’t quite match the specifications.

    Therefore, when standards compliancy became important browser vendors faced a tough choice. Moving closer to the W3C specifications was the way to go, but if they’d just change the CSS implementations to match the standards perfectly, many websites would break to a greater or lesser extent. Existing CSS would start to show odd side effects if it were suddenly interpreted in the correct way.

    So moving closer to standards compliance would cause problems. On the other hand, not moving closer to standards compliance would perpetuate the general confusion of the Browser Wars Era.

    To this end all Browser had to start supporting both modes. Quirks mode for older designs and standard mode for new design.

    Paraphrased from here: Quirks mode and strict mode

    DocTypes

    Choosing which mode to use requires a trigger, and this trigger was found in ’doctype switching’. According to the standards, any (X)HTML document should have a doctype which tells the world at large which flavour of (X)HTML the document is using.

    Taken from here too: Quirks mode and strict mode

    Additonal Resources

    • Document Type Declaration
    • Quirks Mode on Wikipedia
    • Quirks mode and strict mode
    • Internet Explorer box model bug
    • The CSS box model

提交回复
热议问题