Why use <! DOCTYPE html>

Source: Internet
Author: User

Transferred from:http://i.wanz.im/2010/05/28/why_doctype_html/

Whether you're just touching the front end, or you're already "proficient" in web front-end development, you should know that you need to define the document type when you write HTML, and you know that if you do not have it, the browser will use the odd mode when rendering the page, and you know that each browser has different rendering for each element in weird mode. So you'll write a doctype like this:

<! DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd ">

Fortunately, the various web development tools are powerful enough to support inserting template code, so you don't have to knock out the long, smelly doctype letters. But if you're fed up with it, you might be able to try the following:

<! DOCTYPE HTML >

Wow, very concise Oh! The benefits are obvious: one, you can easily write down this doctype, without worrying about the wrong, second, it is backward compatible, yes, HTML5 doctype is written like this, and modern browsers know it.

If you're like me, you always think that it's wrong to not specify a DTD that will open the browser's weird mode ! the right thing to say is that you don't have to define doctype to turn on weird mode, which means you just need to define <!doctype html> to let the browser render the page in strict mode (standard mode) without having to specify a type DTD. Let's review that all browsers require two modes: weird mode and strict mode (also called standard mode). IE 6 for Windows/mac, Mozilla, Safari and Opera both are implemented in these two modes, but the following versions of IE 6 will always be in the weird mode. For the two modes, you need to know the following points:

  1. Pages written before normalization are not doctype, so pages without doctype are rendered in weird mode.
  2. Conversely, if the web developer joins the DOCTYPE, stating that he knows what he wants to do, most of the DOCTYPE will turn on strict mode (standard mode) and the page will be rendered according to the standard.
  3. Any new or unknown DOCTYPE will turn on strict mode (standard mode).
  4. Each browser has its own way to activate the quirks mode. You can take a look at this checklist: http://hsivonen.iki.fi/doctype/

Note: You may not need to verify your page based on the doctype you choose, as long as the DOCTYPE tag exists enough to turn on strict mode (standard mode). If you're still skeptical about what I'm saying, go to http://www.quirksmode.org/css/quirksmode.html#link2 and learn what you want to know. We only need a small piece of JavaScript code to get the answer, it is:

Mode=document.compatmode;

This code can be used to determine whether the current browser is in weird mode or Standard mode, the compatibility of this property is beyond doubt, if you are doubtful, you can view http://www.quirksmode.org/dom/w3c_html.html#t11. You can access it in the browser you want to test: http://wanz.im/demo/doctype-test.html, you can see the results, as far as I know, this does not activate the weird mode, even if you have any new discoveries, please leave me a message.

Why use <! DOCTYPE html>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.