Differences between HTML and XHTML

XHTML stand for EXtensible HyperText Markup Language which is a combination of HTML and XML. In early 2000 XHTML 1.0 became a W3C Recommendation. If you are still using regular HTML, it’s time to change. XHTML isn’t just the future, it’s the now, and HTML is phasing out. But don’t worry too much, the change won’t be painful.

XHTML is a lot like HTML, but more normalized. It forces you to abide by it’s rules, which is a great thing when you are programming! It clearly defines what is OK and what is not. It makes HTML look rather chaotic.

As a result it works in all internet browsers, whereas bad or poorly written HTML may not, especially on mobile phone or other small devices.

So let’s get to it and demonstrate some of the differences between HTML and XHTML.

  • XML requires things to be marked up correctly, in well-formed documents.
  • XML describes data, while HTML displays data.
  • XHTML elements must be properly nested.
  • XHTML elements must be closed even if they are empty.
  • XHTML element and attribute names must be written in lowercase.
  • XHTML documents can only have one root element.
  • Attribute values must be in quotes.
  • Attribute minimization is forbidden, in other words attributes must define a value even if it’s an empty string.
  • The id attribute is now used in place of the name attribute.
  • In XHTML there are some required elements.

The following table contains examples of what works in XHTML and what does not.

Does not work Works
<b><u>
some bold and underlined text
</b></u>
<b><u>some bold and underlined text</u></b>
<h1>Header Text
<p>Paragraph text
<h1>Header Text</h1>
<p>Paragraph text</p>
<br>
<br />
<P>Some text here</P>
<p>Some text here</p>
<head>
<title></title>
</head>
<body></body>
<html>
<head>
<title></title>
</head>
<body></body>
</html>
<a HREF="..."></a>
<a href="..."></a>
<table width=80%>
<table width="80%">
<option selected>
<option selected="selected">