HTML vs XHTML

Ever wondered what HTML and XHTML is about? Long and official story can be found at W3Schools. Short story, below.

Simply put, XHTML is the same as HTML but stricter. There are rules in place that one must follow. You are no longer allowed to leave tags unclosed or place them wherever you want. And guess what, the only beneficiary from following these rules, is you, the web developer. Because your site will then be supported by most of the browsers out there; definitely more than your badly formatted HTML is today.

Quoting W3Schools, the most important differences from HTML are listed below.
Please visit W3Schools post to see examples of good vs bad code.

Document Structure

  • XHTML DOCTYPE is mandatory
  • The xmlns attribute in <html> is mandatory
  • <html>, <head>, <title>, and <body> are mandatory

XHTML Elements

  • XHTML elements must be properly nested
  • XHTML elements must always be closed
  • XHTML elements must be in lowercase
  • XHTML documents must have one root element

XHTML Attributes

  • Attribute names must be in lower case
  • Attribute values must be quoted
  • Attribute minimization is forbidden

How to convert from HTML to XHTML

  1. Add an XHTML <!DOCTYPE> to the first line of every page
  2. Add an xmlns attribute to the html element of every page
  3. Change all element names to lowercase
  4. Close all empty elements
  5. Change all attribute names to lowercase
  6. Quote all attribute values

Moreover, these guys also developed a website where you can validate your page to be XHTML (and not only) compliant. They will also tell you exactly what you did wrong and how to correct. And don’t worry, it’s free! It only costs your willingness to do it the right way.