How to tell if a browser is in "quirks" mode?

HtmlBrowserQuirks Mode

Html Problem Overview


Let's suppose you have a page with a relatively strict doctype and HTML markup that's pretty close to compliant, but perhaps misses in a few silly ways, perhaps because of user content that's out of your control... say you're working on a content management system or a theme for a content management system where you control some basic structure and need some javascript, but you're not responsible for everything else that goes into pages.

How can you tell (or: what will determine) when the browser decides to go into "quirks" mode rather than use it's more standards compliant engine?

I'm looking for answers for each of the major browsers, since IE, Chrome, Safari, and Firefox will of course all handle that differently. Is one single error enough to force it or do you have some leeway?

Html Solutions


Solution 1 - Html

In Firefox and Opera you can determine if your browser is in "quirks mode" by checking page info.

Using document.compatMode, will tell you the mode you are in with most browsers.

In Chrome, Safari, and IE, run this javascript in the address bar:

 javascript:window.alert('You are in ' + (document.compatMode==='CSS1Compat'?'Standards':'Quirks') + ' mode.')

(note that you'll need to re-type the javascript: portion after pasting into your address bar, due to recent security changes)

Solution 2 - Html

As you can query the render mode in JavaScript you can have a [Bookmarklet][bookmarklet] which will tell you which render mode a page is using.

I found [this render mode bookmarklet][dorward] which works well for me:

javascript:m=(document.compatMode=='CSS1Compat')?'Standards':'Quirks';window.alert('You%20are%20in%20'%20+%20m%20+%20'%20mode.');

[bookmarklet]: http://en.wikipedia.org/wiki/Bookmarklet "Wikipedia article about Bookmarklets" [dorward]: http://dorward.me.uk/www/bookmarklets/qors/ "dorward.me.uk"

Solution 3 - Html

The full answer to your actual specific question of 'Is one single error enough to force it or do you have some leeway?' is that it totally depends on the error. For example,

<!-- Comment -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

will force quirks mode in IE 6 & 7 despite not really being an error (they just throw a total wobbly when the very first line of the file is not a declaration). A quick list of types/quirks can be found here

Try sticking the following line in your HTML for testing (very bad javascript behavious I'm passing on here - sorry...make sure this never goes live :)

<a href="javascript:alert(document.compatMode);">What mode am I?</a>

Solution 4 - Html

According to <http://www.quirksmode.org/css/quirksmode.html> : "The problem was that some pages written in quirks mode did have doctypes. Therefore each browser has its own list with doctypes that trigger quirks mode. See this browser comparison chart for an overview of these lists : <http://hsivonen.iki.fi/doctype/>"

Hope this helps

Solution 5 - Html

If you tell IE that it should be strict (via doctype) it will not change its mind halfway through the page.

Solution 6 - Html

If I understand quirks mode correctly, a page that does not validate against its declared doctype is not enough to trigger quirks mode. It just won't display correctly.

The best resource I've found for determining how different browsers handle each doctype is here.

Solution 7 - Html

For Firefox with Web Developer Toolbar add on, you can look at the trio of icons on the right of the bar. The leftmost one tells you what mode you are in.

Solution 8 - Html

In IE you will see it in the developer tools (pressing F12), it says it in the menu: Document Mode:... And you can also force a different mode there.

Solution 9 - Html

in html5 page, write "<!DOCTYPE html>" start with page can change to document.compatMode='CSS1Compat'

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJoel CoehoornView Question on Stackoverflow
Solution 1 - HtmlChris BallanceView Answer on Stackoverflow
Solution 2 - HtmlDave WebbView Answer on Stackoverflow
Solution 3 - HtmlSteerpikeView Answer on Stackoverflow
Solution 4 - HtmlSébastien NussbaumerView Answer on Stackoverflow
Solution 5 - Htmli_am_jorfView Answer on Stackoverflow
Solution 6 - HtmlBill the LizardView Answer on Stackoverflow
Solution 7 - HtmlArieleoView Answer on Stackoverflow
Solution 8 - HtmlRonen FestingerView Answer on Stackoverflow
Solution 9 - HtmlMiroView Answer on Stackoverflow