Because you don't have time to read everything.TM


Why Every Web Page Needs A DOCTYPE


 

I learned HTML back in the days when it really didn't matter if your syntax was right. If your web page looked good, the syntax was good enough, and we left it at that. So I never bothered with tags that didn't seem to really do anything, like <html>. And I certainly never put a DOCTYPE in my pages.

Much later I learned that it really is important to use good syntax to tell the browser what you're trying to do. Now that we're no longer in a one-browser world, standards are becoming more important. The more you stick to the standards, the more likely your website will look right to the user.

The first essential in creating a standards-compliant web page is to include a DOCTYPE at the top of your page. This tells the browser what version of HTML you're using. No, they're not all the same! In fact, if you don't tell the browser what version you're using, it's likely to go into "quirks mode," which basically means it's telling you "Clearly you have no idea what you're doing, so I'm going to put on the training wheels and render your web page according to what I think your intentions are." This sounds pretty helpful, but different browsers can have very different ideas of how they think your page should look. When you use a DOCTYPE, you're telling the browser "I'm a pro. Render my web page according to the standards."

There are different DOCTYPES for HTML 4.01, XHTML 1.0, and XHTML 1.1, although personally, I don't see the need to move to XHTML yet. The HTML 4.01 and XHTML 1.0 DOCTYPES are available in strict and transitional flavors (and also a frameset variety, which you most likely won't need). If you're new to DOCTYPES, you'll definitely want to start out with transitional, because it will be much easier to get it to validate. XHTML 1.1 only has one DOCTYPE, which is most similar to strict.

Without further ado, here are your DOCTYPES:

HTML 4.01 Strict <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
HTML 4.01 Transitional <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
XHTML 1.0 Strict <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
XHTML 1.0 Transitional <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
XHTML 1.1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

Pick one (I'd suggest HTML 4.01 Transitional if you're not sure), slap it on your HTML document, and run it through a validator. The downside of using a DOCTYPE is that if you tell the browser you know what you're doing, it better be a valid document. But any changes needed to make your page validate for HTML 4.01 Transitional should be pretty small. Take these simple steps, and then sit back knowing you've made major strides in helping browsers render your pages the way you want them to.

 

StumbleUpon Stumble it!    Email Email to a friend


© 2007 - 2008 SpicePuppy.com