Correct understanding of html,xhtml page Header doctype definition

Source: Internet
Author: User
Tags html interpreter

Excerpted from http://www.west263.com/info/html/wangyezhizuo/css/20080225/42390.html
When we make a page, we always see a bunch of announcements in its source dock, like the most common
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
If we remove the code, we will find that the page may have a noticeable change, because it causes some styles to behave differently.
The code we call the DOCTYPE statement. DOCTYPE is a shorthand for document type, which is used to describe what version of XHTML or HTML you are using. The DOCTYPE declaration must be placed at the top of every XHTML document, above all code and identities.
The DTD (for example, XHTML1-TRANSITIONAL.DTD in the previous example) is called the document type definition, which contains the rules of the document, and the browser interprets the identity of your page according to the DTD you define and shows it.
The DOCTYPE statement is an essential part of establishing a standard-compliant web page, and your logo and CSS will not take effect unless your XHTML determines the correct doctype.
XHTML 1.0 provides three types of DTD declarations to choose from:
Transition (Transitional): A very liberal DTD that allows you to continue to use HTML4.01 's identity (but to conform to XHTML notation). The complete code is as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
Strict (Strict): Requires strict DTD, you cannot use any of the presentation layer's identities and attributes, for example
。 The complete code is as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
Framework (Frameset): A DTD used specifically for frame page design, if your page contains frames, you need to use this DTD. The complete code is as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 frameset//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd" >
The ideal scenario is of course a strict DTD, but for most of us who are new to Web standards, the transition DTD (XHTML 1.0 Transitional) is the ideal choice. Because this DTD also allows us to use the identity, elements and attributes of the presentation layer, it is also easier to pass the code validation.


========================== under the original ====================
As we understand, the above-mentioned explanations we see most often.
But today I see a foreign document, its explanation makes everything so simple, it is very clear that the domestic translators are mostly trick, the simple knowledge to complicate. Okay, no more talking. Start sharing.
Why MIME types are important, why do I always think of them?
Three characters: (draconian error handing) strict error handling. Browsers have always been "tolerant of HTML errors". If you forget to create an HTML page
<title> tags, the browser can also display your HTML content. Although any version of the <title> element in HTML is always required to appear on the page. Also, if you use some tags that are not allowed in the page, The browser will interpret it as much as possible and will not report an error.
Maybe that's what you're looking for, in fact these mutilated tags can run on the browser and cause the Web programmer to continue creating the broken code for the garbage. The evaluation found that 99% of web pages on the network had at least one error. Because these errors do not cause the browser to display these errors on the page, So there's no one to fix this bug.
But the organization thinks this is a basic problem. and set about revising it.
XML, released in 1997. Breaking the browser's legacy of allowing HTML code to be wrong, the language required to use XML must treat these problems as errors and report them to the end user.
When the site changes HTML to XML, the MIME type of the corresponding user's code needs to be modified to
Application/xhtml+xml, which is to change the suffix to (XHTML)
This allows for error handling. If there is an error in your XHTML page, the browser stops the process and reports an error to the end user.
This view is not very popular, due to the evaluation of 99% of the site has problems, so frequently problems
The new features of XHTML1.0 and XHTML1.1 are not fully reflected. Web programmers basically ignore
Application/xhtml+xml, in not implying that they also gave up XHTML.
The accompanying XHTML gives the web programmer a backdoor, with some XHTML-like syntax, but still uses
text/html MIME type. That's what we're doing with thousands of websites now.
Even today, many Web pages are declared as XHTML types by declaring XHTML in the first line of the page doctype
Use the lowercase label name to use quotation marks above the attribute. Slash after empty element such as <br/> Only these very small parts trigger error handling through the Application/xhtml+xml MIME type.
Any page if its MIME type is text/html, then regardless of its doctype, syntax, code style is what it looks like. A fault-tolerant HTML interpreter will be used, ignoring tag errors.


Well, I sum up, we now often write the page, in fact, this is the back door embodiment.
So, don't you define the header line?
Now it's OK, but if it's a previous version of the browser, your site may be unrecognizable.
If you want to write a website that is compatible with many browsers, it is recommended that you use


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


It requires a very lenient DTD, which allows you to continue using the HTML4.01 's identity.
It can be said that XHTML 1.0 is a stricter and purer version of HTML 4.01.
Of course you can also use
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"
"Http://www.w3.org/TR/html4/loose.dtd" >
Why does this pure HTML4.01 need a head?
Because in HTML 4.01, <! The doctype> declaration references a DTD because HTML 4.01 is based on SGML. The DTD prescribes the rules of the markup language so that the browser renders the content correctly.


Why are all transitional this type of ... This is the transition version and is better for compatibility.


Then change the MIME type to our text/html. File suffix (HTML) Why is it so superfluous? because most browsers
Follow XHTML1.0 or XHTML 1.1, or use HTML 4.01 they have some new features. We all want to use these new features, but do not want to let their own page error. That's the way it should be.
But for most web programmers, I think they are actually the so-called "trickery".
The new features are useless, and the foggy of their own code by these nonsensical heads.
Fortunately, our HTML5 era has come. All of this will be history.
HTML5 is not SGML-based, so you do not need to reference a DTD.
<! DOCTYPE html>


That's all.
Best Wishes ....







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.