Welcome to another article on Building Better Web Pages. This article series comprehensively covers building an HTML document: easily learned, but rarely perfected.
Today’s article covers Doctype declarations in regards to XHTML and HTML.This is one of the most intriguing markup debates out there. I personally waffled back and forth between the two.
Solid Statement: Don’t be a whiny prima donna about this issue. The XHTML Doctype helps you develop good coding habits. While HTML 4.01 has its set of standards, it allows for ‘sloppy’ code that doesn’t fly in any other language or platform.
Pitfalls to Watch Out For
Arguments over this topic are widespread. These arguments are actually strong in certain circumstances. However, if you have been following the principles suggested in the Building Better Web Page series, some of those arguments will be irrelevant. These include arguments about your document becoming invalid after switching to an XHTML Doctype because you weren’t writing well-formed code.
Opponents suggest that there is no point in using XHTML at this point, because it is nearly always served with the Content-type of text/html.
Technically, XHTML is designed to be served as application/xhtml+xml. Since it is not served that way, many of the advantages of the X are thrown out. You will notice that I never talk about those advantages, obviously, as I don’t suggest XHTML because of those features. I suggest it because it enforces better coding standards: closing tags, quoted attributes, lowercase elements, proper nesting. When I say enforces, I mean it won’t validate without proper formatting. If you don’t validate your webpages, you obviously would not see those benefits.
How to Serve XHTML as Intended
You can actually use the HTTP Accept header to send either Content-type if you so desire. Check out my examples of content negotiation for Apache htaccess files and various scripting languages. The concept is rather simple: you check for the HTTP Accept request header sent by the browser to see if it supports the MIME media type of
application/xhtml+xml and serve it up if so. Otherwise, the page is served as traditional
I’ve Always Used HTML, Should I Switch?
If an advanced designer were to follow the XHTML conventions out of habit, it would be completely fine to switch the Doctype back to HTML. This obviously means you would lose the extended features of xml, but I honestly don’t know anyone who uses those. Some people can’t mentally get over the fact that their document says “XHTML” at the top while always being served simply as “HTML.” While some designers consider that silly and like to make spectacles about it in public forums, you won’t hear me complaining. I believe attention to detail, no matter how minuscule, is a worthy virtue.
Markup Conventions Compared to HTML
- XHTML is case-sensitive. All tags and attributes must be lowercase in XHTML. HTML doesn’t care.
- XHTML, must be well-formed. Element must always have a closing tag or have self-closing syntax where available. HTML allows ommission of various start and end tags.
- All attributes must have a value in XHTML. HTML allows some attributes (e.g., selected) to be minimised.
- All attribute values must be quoted, double or single. HTML allows quotes to be omitted.
For building better web pages, any of the following books are a great! “Web Design For Dummies” introduces pretty much every aspect of design, including planning and research. If you are interested more in the concepts and ideas of proper markup, go with “HTML and CSS Web Standards Solutions”. Finally, for a more conversational tone, “Designing with Web Standards” is reading geared toward the practical application, rather than the concepts themselves.