Saturday 31 July 2004
PERHAPS IT WAS just his choice of words that caught my concern, but in a recent comment, Anne van Kesteren claims that “. . . a
DOCTYPE isn’t really relevant” . For the theoretician, perhaps this is true. For the practitioner, the relevance is indisputable.
First, a few things about
DOCTYPEs in HTML and XHTML for those unfamiliar:
DOCTYPEdeclarations are that bit of SGML syntax that should be at the top of every HTML or XHTML document you author – they define the document type and provide a URI to the document’s DTD (Document Type Definition)
- Beyond declaring the document’s type,
DOCTYPEdeclarations come into play when the document is validated. The validator uses the information in the declaration to compare against the DTD and report any warnings or errors
DOCTYPEdeclarations are required in conforming HTML or XHTML documents
DOCTYPE declarations also provide us with an incredibly important tool: The
DOCTYPE Switch. Having a correctly formed DOCTYPE will cause browsers to run in compliance mode – an optimal browser mode for standard, conforming documents.
DOCTYPE switching is of course a debate in and of itself. That a piece of code used to identify and validate a document is being made into a functional part of the browser is considered a browser hack by many. I see the rationale behind that point, I do. But right now I’m more concerned with the benefit that switch provides to the working designer and developer.
DOCTYPE switching becomes crucial to the working developer is when designing with CSS layouts. That dominant bitch of a browser, Microsoft Internet Explorer 6.0 for Windows, has several CSS flaws, and one of the most challenging is that its native implementation of the Box Model conforms to the Microsoft interpretation, not the W3C specs. But what many don’t realize is that by using a
DOCTYPE declaration that invokes switching, IE 6.0 will switch over into compliance mode where, guess what? You get the W3C interpretation of the box model, solving a significant concern with CSS design.
DOCTYPE switch might be seen as some to be a hack itself, is using a proper
DOCTYPE declaration required by the specs in the first place a hack? All we’re doing in that scenario is what we’re supposed to be doing anyway, even if there’s the added advantage of solving a serious concern.
The other alternatives available to us are to add hacks and filters into the CSS, fall back on transitional techniques for layout, or look to the CSS3
box-sizing property, which has very limited support because CSS3 isn’t even a recommendation yet! If your target browser base doesn’t include IE browsers below 6.0 and you’re implementing switching, you might not have to add a hack or filter anywhere in your CSS. So in that scenario, you’re following the specs and not hacking to get the correct results.
DOCTYPE debate one of what is ideal versus what is real? Perhaps, but practicality has to rule the day, at least during this very difficult, transitional time where people desperately want to reap the benefits of compliant design. This, despite the fact that the major stumbling block is one primary piece of software, IE 6.0, which also happens to be the most widespread, flawed software that we have to deal with. To my way of thinking, this makes
DOCTYPEs extremely relevant, whether we like it or not.