You know that without it, the browser will use weird mode when rendering the page; you know that each browser renders various elements differently in weird mode. So you would write a doctype like this:
Wow, so simple! The benefits are obvious: 1. You can easily write this doctype without worrying about making mistakes; 2. You save about 105 bytes of characters. For a site with a daily PV of tens of millions, it can save a lot of money. Objective traffic; 3. It is backward compatible. Yes, the doctype of html5 is written like this, and modern browsers recognize it.
If you are like me and have always thought: Not specifying dtd will open the weird mode of the browser , this statement is wrong! The correct statement is that weird mode will be turned on if doctype is not defined, which means that you only need to define to let the browser render the page in strict mode (standard mode) without specifying A certain type of dtd. Let's review that all browsers require two modes: weird mode and strict mode (also called standards mode). IE 6 for Windows/mac, Mozilla, Safari and Opera all implement these two modes, but versions below IE 6 are always in weird mode. Here are a few things you need to know about the two modes:
- Pages written before standardization did not have a doctype, so pages without a doctype were rendered in weird mode.
- On the other hand, if the doctype added by the web developer means that he knows what he has to do, most doctypes will turn on strict mode (standards mode), and the page will be rendered according to standards.
- Any new or unknown doctype will turn on strict mode (standards mode).
- Every browser has its own way of activating weird mode. You can take a look at this list: http://hsivonen.iki.fi/doctype/
Note: You don’t need to validate your page against the doctype you choose at all. As long as the doctype tag exists, it is enough to enable strict mode (standards mode). If you still have doubts about what I said, then please go to http://www.quirksmode.org/css/quirksmode.html#link2 to learn what you want to know. We only need a short piece of JavaScript code to get the answer, it is:
This code can be used to determine whether the current browser is in weird mode or standard mode. There is no doubt about the compatibility of this attribute. If you have doubts, you can check http://www.quirksmode.org/dom /w3c_html.html#t11. You can visit: http://wanz.im/demo/doctype-test.html in the browser you want to test, and you can see the results. As far as I know, this is not activated. Weird mode, even under ie6, if you have any new discoveries, please leave me a message.