Internet Standards

Writing Valid XHTML 1.1

There’s a lot of good reasons to write valid XHTML (even if the vast majority of sites don’t bother):

  • Your site will render better, faster and more consistently across all browsers.
  • Your layout will be pushed from tables and tags to CSS, separating data from presentation and reducing maintenance costs.
  • Computers (most notably, search engines) will be able to parse and make sense of your content easier than they might otherwise have been able to.
  • You’re supporting standards compliance (which translates to freedom for you and your users) and you can advertise valid XHTML using the W3C logos:

Once you’ve gone to the effort of writing valid XHTML and CSS and the W3C Markup Validation Service ( is happy with your efforts you’ll still want to make sure you’re serving your content with the right mime-type: application/xhtml+xml, but only to browsers that support it (and ask for it via the HTTP Accept: header)… most notably not IE6 😐

It’s unfortunate those who care about standards compliance have to jump through hoops by implementing content negotiation, but it’s not too hard to do…. for example in PHP you can do something like this:

  header("Vary: Accept");
  if (stristr($_SERVER["HTTP_ACCEPT"], "application/xhtml+xml") || stristr($_SERVER["HTTP_USER_AGENT"], "W3C_Validator"))
    header("Content-Type: application/xhtml+xml; charset=utf-8");
     header("Content-Type: text/html; charset=utf-8");

Notice that the validator won’t send an Accept header by default. You can force it to, but I’m just checking for the user agent; if you don’t you’ll get a warning about the mime-type even if the document is valid (and you’re serving it correctly).

Note also that neither this blog nor the Australian Online Solutions blog are valid XHTML (and I’m not rewriting Blogger templates to make them compliant), but is and validates cleanly.

By Sam Johnston

Sam Johnston CMgr FCMI/FIML GAICD MACS Snr CP is an Australian technology executive and serial entrepreneur with over 20 years experience founding and advising startups, and in leadership roles at top global technology companies including Google, Equinix, Citrix, and DXC Technology.

Sam is currently chief entrepreneur officer (CEO) at Acumino, a Singapore venture studio focusing on emerging technologies and disruptive innovation. He is working with other founders to create the businesses of tomorrow by applying his research into emerging technologies including drones, robotics & humanoids, 3D printing, computer vision & voice, augmented & virtual reality, artificial intelligence & machine learning, blockchain, chatbots, and quantum computing.

Sam has a bachelor of computer science degree from the University of New South Wales, and is based in Singapore, having worked in Australia, Asia, Europe, and the USA.