Developing under the web standards and using DOCTYPEs
in HTML / CSS by Code It Red on June 19th, 2008
Any web developer these days has to know about the various Web Standards out there such as the W3C validation systems. Sometimes it can be a lot of trouble to stick to these standards but still maintain cross-browser compatibility. You can spend relentless hours trying to get something to work in both Internet Explorer and Firefox only to realize the whole thing isn’t even valid XHTML or CSS.
What are the standards?
The most commonly seen set of standards that are being utilized across many different sites around the web, is that of W3C (World Wide Web Consortium). W3C is a growing organization that has now become one of the many icons of the internet. The W3C standards include:
- HTML 4.0 (HyperText Markup Language)
- XML 1.0 (Extensible Markup Language)
- XHTML 1.0, 1.1 and Modularization
- CSS (Cascading Style Sheets)
- DOM 1 (Document Object Model Level 1)
Of course, there are still many other standards other than the W3C standards. Another significant standard that is also quite big is The European Computer Manufacturers Association (ECMA) standard.
Why should we develop under these standards?
When you develop something, and you send it of to someone else to use, it may be difficult for them to be able to understand what is going on if you are a messy coder. Everyone’s developing style is different and there is no ‘web law’ stating that you MUST code under the standards, however doing so is highly profitable and often makes your coding a lot easier to comprehend and in turn makes the browsing experience of your users enjoyable. Here are just a few of the reasons why everyone should at least attempt to follow the standards:
- Cleaner coding (Which leads to my next point)
- More efficient coding
- Valid documents and pages often receive higher ranking in many search engines
- Compliant documents can also be very easily converted to other formats
- Browsers that have disabilities can often still render compliant pages properly
- Most web standards have both forward + backward compatibility with many different browsers and Operating Systems
DOCTYPES
According to the World Wide Web Consortium (W3C), each (X)HTML document needs to include a document type declaration (DOCTYPE). This DOCTYPE has to be placed at the very start of any (X)HTML document and “tells” any tool which processes (X)HTML documents (browsers, validator, etc) which version of (X)HTML to use to render the page. If you do not use a DOCTYPE at all the browser will render the page in quirks mode instead of standards mode which usually will give you all sorts of strange results as each browser uses different rendering engines in their quirks mode.
Common DOCTYPEs
It is more than likely you will be looking to use one of the common DOCTYPEs below but the W3C have a list of all the available DOCTYPEs for you to use.
HTML 4.01 Strict
< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
This is a trimmed down version of HTML 4.01 which concentrates on structure over presentation. Depreciated elements and attributes are not allowed in this rendering engine. Using HTML 4.01 strict allows the author to achieve fully accessible documents with great structure that will adapt easily to any style sheet applied. Although HTML 4.01 Strict documents may look fairly bland in very old browsers not capable of using style sheets, there are not many people still using those browsers, so it does not pose a serious problem anymore.
HTML 4.01 Transitional
< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
This is the same as HTML 4.01 Strict but allows you to use presentational attributes, depreciated elements and link attributes.
HTML 4.01 Frameset
< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
This is a version of HTML 4.01 that is only to be used in documents using frames.
XHTML 1.0 Strict
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
This is an XML version of HTML 4.01 Strict.
XHTML 1.0 Transitional
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
This is an XML version of HTML 4.01 Transitional.
XHTML 1.0 Frameset
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
This is an XML version of HTML 4.01 Frameset.
When creating a (X)HTML document it is best to choose the DOCTYPE for the latest version of the language you will be coding in, at the time this article was written the most recent version would be XHTML 1.0 or HTML 4.01.
As for choosing whether to use strict, transitional or frameset it should be fairly straightforward. You should use strict on any document, unless you absolutely have to use a depreciated element/attribute in which case you would use transitional, and of course, if you use frames at all in the document then you will want to use the frameset DOCTYPE.
Summing up
As a whole, developing under the web standards and utilizing web DOCTYPEs all really have their advantage. If you are just starting out with developing your own projects, then I recommend that you should familiarize yourself with the W3C standards as soon as possible. This is because, these standards will most likely evolve to be the general web standards and you will more than likely be using these standards for a long, long time. A few handy resources for the W3C standards are below:
Hopefully, you have all learned a little something from this post that you can take with you and maybe even pass on to some of your fellow developers.
Related Content:Sorry, no related posts.

