nanosoft
nanosoft

Reputation: 3091

How to determine which version of HTML is used?

If a page starts with the <html> tag and no doctype, how is it interpreted? Which version of HTML is used? Can it be interpreted by browser as HTML5 or some other version? And how do I determine that?

for example, see below html file.

<html>
<head>
</head>

<body>
<p> This is a paragraph </p>
</body></html>

Upvotes: 0

Views: 2303

Answers (3)

ajp15243
ajp15243

Reputation: 7950

According to the W3C specification about DOCTYPE here:

A doctype (sometimes capitalized as “DOCTYPE”) is an special instruction which, for legacy reasons that have to do with processing modes in browsers, is a required part of any document in the HTML syntax;

and an older HTML4.01 spec about DOCTYPE here:

A valid HTML document declares what version of HTML is used in the document.

the DOCTYPE is a required piece of any HTML page in order to be valid HTML. Not having it will cause browsers to have a browser-specific interpretation of your page, commonly referred to as Quirks Mode. This will be different in every browser, and should never be relied on. The moral of the story is to always include a DOCTYPE at the very top of your page.

Upvotes: 0

smdrager
smdrager

Reputation: 7417

Please read this article about how browsers determine rendering modes (and the modes that they have):

https://hsivonen.fi/doctype/

Most browsers use the DTD (DocType Declaration) to determine rendering mode. IE since IE8 also interpret the X-UA-Compatible meta tag to help determine.

Appendix: IE8’s Mode Selection

Start: Go to “X-UA-Compatible meta?”.

X-UA-Compatible meta?

IE=7: Use IE7 Standards. 
IE=EmulateIE7: Go to “Quirky or No Doctype? (Compatibility Mode)”. 
IE=IE8 or IE=IE7 or IE=a or IE=EmulateIE8 or absent or has script first: Go to “X-UA-Compatible HTTP Header?”. 
IE=8 or IE=Edge or IE=99 or IE=9.9: Go to “Almost Standards Doctype?”. 
IE=5: Use Quirks (IE 5.5).  

X-UA-Compatible HTTP Header?

IE=7: Use IE7 Standards. 
IE=EmulateIE7: Go to “Quirky or No Doctype? (Compatibility Mode)”. 
IE=IE8 or IE=IE7 or IE=a or IE=EmulateIE8 or absent: Go to “Display All Web Sites… Pref Set?”. 
IE=8 or IE=Edge or IE=99 or IE=9.9: Go to “Almost Standards Doctype?”. 
IE=5: Use Quirks (IE 5.5).  

Quirky or No Doctype? (Compatibility Mode)

Yes: Use Quirks (IE 5.5). 
No: Use IE7 Standards.  

Display All Web Sites… Pref Set?

Yes: Go to “Quirky or No Doctype? (Compatibility Mode)”. 
No: Go to “Display Intranet Sites… Pref Set?”.  

Display Intranet Sites… Pref Set?

Yes: Go to “Is the site in the Intranet Zone?”. 
No: Go to “Domain on MS-Maintained List?”.  

Is the Site in Intranet Zone?

Yes: Go to “Quirky or No Doctype? (Compatibility Mode)”. 
No: Go to “Domain on MS-Maintained List?”.  

Domain on MS-Maintained List?

Yes: Go to “Quirky or No Doctype? (Compatibility Mode)”. 
No: Go to “Framed by Compatibility Mode page?”.  

Framed by Compatibility Mode page?

Yes: Go to “Quirky or No Doctype? (Compatibility Mode)”. 
No: Go to “Compatibility Mode Button Pressed?”.  

Compatibility Mode Button Pressed?

Yes: Go to “Quirky or No Doctype? (Compatibility Mode)”. 
No: Go to “Quirky or No Doctype? (IE8)”.  

Quirky or No Doctype? (IE8)

Yes: Use Quirks (IE 5.5). 
No: Go to “Almost Standards Doctype?”.  

Almost Standards Doctype?

Yes: Use IE8 Almost Standards. 
No: Use IE8 Standards.

Upvotes: 0

Quentin
Quentin

Reputation: 943635

If a page starts with the <html> tag and no doctype, how is it interpreted?

With the Quirks mode parser.

Which version of HTML is used?

Browsers don't care about versions of HTML, only elements and attributes that they recognise.

Upvotes: 3

Related Questions