The badass guide to master DOCTYPE
You love proper code, with a beautiful Strict DOCTYPE that you validate constantly… don’t you?
You cannot sleep as long as a small error remains hidden in your code, and you don’t use any hack because you learned that “hacks are evil”?
Playing the good student role has its good parts but I’ll show you that it’s possible to do as well or even better without all that hassle!
What’s DOCTYPE?
DOCTYPE is the gibberish looking code that you put at the top of your (X)HTML files. It looks like this:
The DOCTYPE tells the browsers how to interpret the code in your (X)HTML files. Without DOCTYPE the browsers don’t know which version of the code is used and fall in quirks mode.
To sum it up, the DOCTYPE makes sure that your page won’t be rendered like an old, outdated one.
The badass DOCTYPE
The problem is that there are many different DOCTYPEs and it’s sometimes difficult to decide which one to use. Moreover the DOCTYPE declaration is long and difficult to remember.
What if a shorter declaration could work as well or even better? Too good to be true?
In fact such a short DOCTYPE exists! You can code in XHTML 1.0, HTML 4.01, Strict or Transitional, just put the following piece of code and… voilà! It does wonders.
The only problem is that some validation tools won’t recognize this DOCTYPE properly yet. So they will flag your code with errors… but only the good student would care! (Remember, it’s the badass guide to master DOCTYPE so you shouldn’t care).
It’s future-proof!
The best thing with this short DOCTYPE may be that it is future-proof. As you know, we’ll probably have to switch to HTML 5 in the next years, and this DOCTYPE is forward compatible.
You don’t have to worry about DOCTYPE anymore! Forget your long, painful DOCTYPE header. The <!doctype html> header will work perfectly and be valid for many years.
Enjoy!
For code’s sake
One last piece of advice. Coding directly with the <!doctype html> header might not be the very best idea for beginners until HTML 5 has matured a little. A stricter canvas is required in order to develop good coding habits.
That’s why I would recommend this:
- first write your code in XHTML 1.0 Strict DTD or HTML 4.01 Strict DTD
- then make sure all your code validates, or that you know and willingly use things that do not validate (for instance browser specific hacks)
- last, change the DOCTYPE to <!doctype html>
That way you’ll learn to write clean code, but you will not be untangled in the only-perfectly-valid code obsession.
I hope this little article on DOCTYPE will make your life as a Web Designer a little easier!
Related Posts
You may want to check out the following related posts: