Gary Willoughby
Gary Willoughby

Reputation: 52498

Do HTML doctypes guarantee formal parsing?

Do HTML doctypes guarantee formal parsing?

For example if i use a particular doctype and then produce really bad HTML, will this force the browser to revert to a Quirks mode or guarantee parsing to the doctype?

EDIT: This includes CSS behaviour too.

Upvotes: 2

Views: 101

Answers (2)

Spudley
Spudley

Reputation: 168685

As long as the doctype is a recognised valid doctype, then yes, you should be guaranteed to be in standards mode rather than quirks mode.

Quirks mode isn't about rendering bad quality HTML code; it exists because that was the only rendering mode for older browsers such as IE5, and when newer browsers came along (IE6), they wanted to support the new standards mode, but also needed to be backward compatible.

Those older browsers didn't know about doctypes, and so therefore the browser makers came up with the idea of saying that if you specified a doctype you must be expecting to be in a newer brower, and thus expecting standards mode.

Having said all that, if you've got bad quality HTML code, it won't really matter whether you're in standards mode or quirks mode -- the browser will still have to work out what to do with your tag-soup, and you're likely to get different results in different browsers, regardless of the rendering mode.

Upvotes: 0

Quentin
Quentin

Reputation: 943510

Do HTML doctypes guarantee formal parsing?

No.

You'll be hard pressed to find a browser that will parse using SGML rules under any circumstances.

An XHTML Content-type will trigger some browsers to parse using XML rules.

Most browsers will use their own tag soup parser or the HTML 5 algorithm for any text/html document.

For example if i use a particular doctype and then produce really bad HTML, will this force the browser to revert to a Quirks mode or guarantee parsing to the doctype?

Quirks mode has very little to do with parsing. It is mostly about how CSS is interpreted.

The choice between Quirks / Standards / Almost Standards / etc modes is handled almost entirely by the Doctype though. The exceptions are having an XHTML MIME type (which will force some browsers to standards mode, no matter what the Doctype) and (in the case of MSIE) X-UA-Compatible HTTP headers and <meta> data.

Upvotes: 1

Related Questions