As some of you might be aware, the very first line of code in your (X)HTML files should be the doctype. They come in many flavors. Here are a few:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "
http://www.w3.org/TR/html4/strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Now, I won't bore you with details and would advise you check the w3c site and/or google for more information. However, as an explanation, I will explain what the above 3 mean and why, in general, specifying a doctype is very important. Focus on the bold portions please:
#1 and #2 declare that the document will be validated against the strict interpretation of HTML and XHTML respectively. #3 basically declares that the document will be validated against a loose interpretation of XHTML which means that it will overlook things like using tables while still enforcing things like making sure all tags are opened and closed. For the most part, sites today are validated against #3 as not all browsers are web standards-compliant. You can also define your own doctype but that is beyond the scope of this post.
Why is specifying a doctype important?Because it is important that, especially if you are using a web standards-compliant browser, the document gets "interpreted" properly. Where no doctype is specified, "funny" things an happen. This is what is known as the browser entering "quirks mode" which is another way of saying that the browser will fall back to some default mode. In IE for instance, quirks mode means that your document will default to being displayed as though you were using IE4, not something you would want of course.
Conclusion:Always specify a doctype. #3 is preferred as it ensures the minimum required to guarantee that your sites, even without testing, will appear and function properly on a PC, PDA, Screen reader, etc. I have developed many sites over the years and taken for granted the importance of specifying a doctype only to appreciate it as many years later, not one of my sites has been found wanting on a variety of devices.
Did you find this lesson in learning of any use? If so, let me know and I will post more from time to time. Otherwise, I will stop.
Thanks,