9

If you use deprecated attributes or tags <center>, <font color="red">, or <td valign="top"> etc. in XHTML 1.0 Strict (no depr. attributes), modern browsers (I will use Chrome as an example) still take notice of and use them.

If you use HTML5 <video> on an XHTML 1.0 Strict DOCTYPE Chrome will still recognize it - it's not as if they'd program it to not. I tested the worst deprecated, capitalized, and unquoted attribute code I could write, along with HTML5 audio, with the XHTML 1.0 Strict DOCTYPE in Chrome and it rendered flawlessly.

Here's the code I tested, working flawlessly in Chrome (red bg, centered table, audio playing):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Do browsers care about the DOCTYPE?</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
</head>
<body bgcolor=#ff0000>
 <CENTER>
  <table cellpadding="0" cellspacing=0>
   <tr><td valign=top>test</td></tr>
  </table>
 </CENTER>
 and some HTML5 audio..
 <audio autoplay>
  <source src="http://www.duncannz.com/resources/sound/alarm.mp3" type="audio/mp3">fallback text</audio>
</body>
</html>


So my question: Do modern browsers (translation: browsers other than IE) pay any attention at all, or do anything differently, because of the DOCTYPE? Do they even bother to read and interpret it?

6 Answers 6

9

Browsers do care about the DOCTYPE - otherwise there wouldn't be any point in having it!

You are right in saying that many browsers interpret old/deprecated commands in the correct way, but this is largely a matter of backwards compatibility. There is such a huge amount of content on the web that it is next to impossible to keep everything up-to-date and standards-complient. The web browsers continue to support these outdated pages because if they didn't, much of the content on the web would look slightly off. Most users don't know the difference between HTML4 and 5, so the blame could fall on the browser, which could be devastating - especially if a page looks bad on Firefox and nice on IE!

The DOCTYPE is mainly used in validation and to determine whether a browser runs in this "quirks mode" (where many of these older rules still work) or "standards mode" . Many professional web designers use the W3C validation tools to make sure their web pages are valid HTML, and the tools provided by their website look at the DOCTYPE to choose the correct set of rules with which to validate. Furthermore, XHTML strict does not allow empty tags or other blatant syntactic errors.

Hope this helps!

2
  • 2
    +1 for "especially if a page looks bad on Firefox and nice on IE!" Jul 11, 2012 at 23:45
  • Thanks. Of course DOCTYPEs are needed for validation, and I do always use <!DOCTYPE html>, and ensure all my pages validate. Just curious as to why HTML5 audio works in XHTML 1.0 Strict on Chrome, which led me to think browsers like Chrome wouldn't bother even checking the DOCTYPE if DOCTYPEs don't make it do things differently.
    – user1318194
    Jul 11, 2012 at 23:54
4

Try this in Chrome:

<!DOCTYPE html>
<title>Test case</title>
<p hidden>My text
<table><tr><td>Hello World</table>

against this

<title>Test case</title>
<p hidden>My text
<table><tr><td>Hello World</table>

Only in the former case will the text "Hello World" be visible.

0
2

In most Modern Browsers, you're not going to notice much difference (depending on the page) when using different Doctypes. The biggest difference you'll notice is not in your markup, but in your use of CSS, and the layout/positioning of elements. The Doctype is used when validating your pages, and in determining the mode, the browser renders the page in. So, depending on the Doctype you use, it will determine if the page is rendered in Standards mode, Quirks mode, etc. In IE, and older browsers, you'll notice much more of a difference.

For a more in-depth information on the subject, check out this link: http://hsivonen.iki.fi/doctype/

0

Yes, they do. It means the difference between Quirks or Standard mode, and can affect how IE handles box containers.

Have a look here:
http://www.quirksmode.org/css/quirksmode.html

And also here:
http://www.webmasterworld.com/forum21/7975.htm They discuss this topic in detail.

0
0

maybe the paragraph called "How DOCTYPES Affect Rendering" could help you?

http://www.upsdell.com/BrowserNews/res_doctype.htm

0

At the current date it is still possible to use DTD entities as variables in chrome/firefox/opera/ie in .xml and .xhtml and .svg and other xml-based files(breaks in .html files as I imagine it uses an html rendered instead of an xml renderer) without having to resort to javascript or php/other server-side preprocessor magic:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [
<!ENTITY theword "bird">
<!ENTITY thexmlns "http://www.w3.org/1999/xhtml">
]>
<html xmlns="&thexmlns;">
  <head>
    <title>The word is &theword;</title>
  </head>
  <body>
    <p>This document uses the word &theword; multiple times.</p>
    <p>This document's word can be changed from &theword; by altering the entity.</p>
  </body>
</html>

This seems like a useful test to see if doctypes still work(save the example above as example.xml or example.xhtml and see if it works).

So far I only found a realistic use for it in android projects xml files to use entities inside attributes to prevent lines from having too much text one one line, or from having the repeated long text in multiple attributes that could have a short entity encode them instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.