I'm a crack person as you see on my profile picture. If we don't use HTML5 DOCTYPE statement, all modern browsers goes heuristic or inherit mode?
Modern browsers seem our page as HTML5 and old ones suddenly get mad about
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
What happens?
CodePudding user response:
Once you inspect, you see H1's margin is 21.44px 0px
which means we're expecting to see the top and bottom margins are 21.44px
but that top margin is not applied correctly without DOCTYPE!
With DOCTYPE <!DOCTYPE html>
Yeah! Now we can see H1's margin is correct for top and bottom as expected.
I think it's good enough for the explanation. Feel free to reach out to me if you are still concerned about it.
CodePudding user response:
In short, without DOCTYPE the browser will try its best to render the HTML document.
Just to give more context, according to this thread, Firefox has
"reduced support for Quirks mode sites over the years".
This tells me that browsers are changing their backward compatibility over time, and it all depends on the browser and how they decide the rendering should happen. I found this article with the following quote, supporting that same idea, but this time referring to Internet Explorer:
Previously, different browsers implemented different quirks. In particular, in Internet Explorer 6, 7, 8 and 9, the Quirks mode is effectively frozen IE 5.5, while in other browsers the Quirks mode has been a handful of deviations from the Almost Standards mode. Recently, browsers have been converging on common behavior in their Quirks modes. Most notably, the primary Quirks mode of IE10 and IE11 is no longer an imitation of IE 5.5 but seeks to be interoperable with Quirks modes of other browsers.
Finally, here is a very interesting article about what has been observed to happen during Quirks Mode: What happens in Quirks Mode?
Basically the DOCTYPE activates the standard mode on browsers, and if it is not specified, then Quirks Mode is triggered. Another quote this time from the MDN web docs:
Anything before the DOCTYPE, like a comment or an XML declaration will trigger quirks mode in Internet Explorer 9 and older.
Quirks mode: browser behaves as an old browser before web standards were made at W3C and widespread adoption of the web.
Standard mode: browser follows modern HTML and CSS specifications.
There is also almost-standard mode, which is a combination of the previous two but standard implementation is prevalent