Mike Griffiths

Tag: doctype

HTML Doctype Selection

by Mike on May.21, 2009, under Findings, Web Development

There’s a lot of contraversy out there over what doctype should be used for HTML pages, the three main ones used are:

  • XHTML Strict
  • XHTML Transitional
  • HTML 4.01

I think it’s fairly safe to say that the majority of the websites on the web use HTML 4.01, due to XHTML versions being more recent. But what’s the point of them all? Why can’t we just have one doctype and leave it at that?

Well, it’s all about standards. Without standards nothing would work properly, not just on the Internet, but anywhere. Take your car for example. If there weren’t standards for, say, tyre connectors then you wouldn’t be able to go out and buy any type of tyre for your car, you’d have to make sure the connector was the same as that on your car, this goes for everything. HTML is the same. There are new browsers cropping up every day, but the main five are:

  • Internet Explorer
  • Mozilla Firefox
  • Opera
  • Netscape
  • and more recently, Google Chrome

If there weren’t standards then all these browsers wouldn’t be able to work. And as it happens, most work differently – thanks to Microsoft’s Internet Explorer, but that’s a whole other story.

Back to the doctype selection, there are supposed advantages to using all of the three doctypes mentioned, let’s start from the bottom.

HTML 4.01
This is the most lax doctype. Most things go here. So long as your elements are spelled correctly and you close quotes off (although you don’t have to have any at all) then your document will probably validate. Because anything goes this leaves a lot of interpretation for browsers. The developer may nest a load of elements together expecting one thing to happen but the browsers may all render completely differently.

XHTML Transitional
XHTML is a little different from HTML. The syntax is slightly different where by any elements with no content must be closed within themselves, for example:
HTML:
<img src="images/mike-griffiths.jpg" alt="Mike Griffiths">
XHTML:
<img src="images/mike-griffiths.jpg" alt="Mike Griffiths" />

Any elements that aren’t simply do not validate. There are also much tighter controls over things such as forms and what elements are allowed inside other elements. All attributes must be quoted correctly and anything that should belong in the <head> should remain there. All elements must be closed.

XHTML Strict
This is the most difficult to develop in, but not hard if you do things properly. As the name suggests, it is a much stricter document type. Everything must be in order for the document to validate. Because there are set rules to follow this means that the browsers should nearly always render what you want them to. There is always going to be issues with Internet Explorer but that’s what conditional HTML statements are for. However, I believe that this strictness is a little excessive. For example, it is sometimes necessary to open a page in a new window, this is normally done by adding target=”_blank” to the anchor (a) element – this will cause your document to fail validation, instead the W3C recommend using JavaScript – the obvious problem here being that the user may not have JavaScript enabled, so what’s going to happen to all those users? Just forget about them? Programming 101 – make sure the application works for all users – so clearly this is unacceptable. Another bad side is that older browser versions may have trouble recognising the document type and rendering.

All in all I believe XHTML Transitional to be the best document type – so long as you’re not a lazy developer and know your HTML and CSS well enough you should have no issues at all. The only bad side being older browsers may have issues rendering your elements how they want – but the likelyhood of your user having such an old browser is pretty low.

1 Comment :, more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post.