Tag Archives: xhtml

HTML vs XHTML: What’s the Difference?

If you’re learning the ins and outs of web coding, you’ve probably started by learning HTML (and if not, we’ve got a blogpost to get you started). You may have also come across another term, one that’s related to HTML but not quite the same, XHTML. To learn the difference, we must first discuss a little bit of history…

HTML has evolved through many incarnations, and each one addresses compatibility issues by introducing and standardizing new code. Each version also eliminates support for old code that doesn’t work as well.

While HTML, a language created to display data, was progressing, another language used to store data was also developed. This language is called XML, which stands for EXtensible Markup Language. Unlike HTML, XML does not have predefined tags, so while tags like <p> and <div> are standardized in HTML, an XML coder gets to make up their own tags based on the information being stored. An email stored in XML might look like this:

<to>Kermit</to>
<from>Miss Piggy</from>
<subject>Song</subject>
<date>May 7, 2013</date>
<body>It’s not easy being green.</body>

Instead of <body> one might also (and correctly) write <message> because the exact tags are flexible, but the syntax is strict. Two of the most important rules are that tags must be written in lowercase and must also be closed. Having stricter rules ensures a better web experience.

The marriage of XML and HTML is called EXtensible HyperText Markup Language, or XHTML, which combines the rigidity of XML with the tags of HTML. The stricter rules ensure that developers use current, correct code to make the websites built in XHTML more stable. In HTML, the rules are not so rigid, meaning that the website is far more likely to break and also harder to maintain and update since errors are more difficult to spot. A few things XHTML requires that HTML does not include:

  • A DOCTYPE must be specified in the head of the document.
  • All attribute values must be in quotation marks.
  • All tags, attributes, and elements must be written in lowercase.
  • Empty elements (like <br> for “line break”) must be ended with a space and a forward slash (so in XHTML it would be written “<br />”).

Don’t worry if you don’t know what all that means yet (especially about DOCTYPE – more on that coming in an upcoming blogpost!), but this brief overview should help you know some of the most important differences between HTML and XHTML.

Now, which should you use? While there’s no discernible difference in the HTML versus XHTML user experience, XHTML is a simple step forward from HTML, it’s more stable, and it’s future ready. It’s good for developers to strive to ensure that their websites at least meet the standards set forth by XHTML, especially since it’s likely to make their website easier to maintain later on!