When you use a
DOCTYPE declarations in your web pages (and many HTML editors like Dreamweaver add them in automatically), you are telling the web browser what version of (X)HTML your web page should be displayed in. The doctype gives the browser a list of supported tags and does not include any deprecated or proprietary tags in the list.
But most HTML editors will allow you to write any HTML (or non-HTML) tags that you want inside your documents, even if you specify a very strict
DOCTYPE from the many
DOCTYPE declarations available. Some will flag the invalid tags for you, or report them when you validate the HTML. But unlike many XML editors, HTML editors will allow you to write and save anything you want, even if it's incorrect.
Web Browsers are More Forgiving
You can get away with writing invalid or incorrect HTML code because most web browsers are amazingly forgiving. They do not require that the HTML be valid or well-formed, and most will attempt to display anything that is handed to them, as long as it's defined as HTML or text.
Unlike XML applications, web browsers attempt to guess at what the web page author is driving at, and display what it can, however it can.
Web Browser Quirks Mode
Most web browsers will display web pages slightly differently when in quirks mode. Some of the quirks you might notice if your web page doesn't have a doctype or it's got a doctype without a DTD attached include:
- CSS class names are case-insensitive
- HTML colors are parsed differently (the # is not required, missing digits are filled in differently)
- Sizes are defined as pixels (px) if the unit is left off
- Pages attempt to view like in Netscape 4 instead of modern browsers
Where Did that Scroll Bar Come From?
Internet Explorer 6 has an interesting “feature” that it adds to documents that have deprecated and invalid HTML tags inside a page. It adds a horizontal scroll bar.
The best way to avoid the horizontal scroll bar is to remove deprecated HTML tags and proprietary HTML tags from within a page with a
DOCTYPE declaration. If you can't do that, you can remove the DTD link from your declaration, but this will make other browsers, like Firefox, view the page in quirks mode.
It's a good idea to get in the habit of using
DOCTYPE declarations on your web pages. That way, you won't be surprised by how your pages display. And once you're comfortable with using them, be sure to always validate your HTML so that you don't end up with unexpected surprises like the IE 6 horizontal scroll bar.