Difference between HTML and XHTML

One of the reasons that today's browsers are so large is that HTML documents can be constructed much more loosely than XML documents. For example, the following is a perfectly acceptable HTML document:

<head><title>Message of the Day</title></head>
There is no message of the day.
Try back tomorrow.

But because the <p> tag isn't closed and the <html> and <body> tags don't match their closing tags, this isn't a well-formed XML document.

XHTML takes HTML as defined in version 4.01 and applies the rules of well-formed XML documents. In order to be an XHTML document, our example above would have to read as follows:

<head><title>Message of the Day</title></head>
<p>There is no message of the day.</p>
<p>Try back tomorrow.</p>


XHTML is also broken down into several "flavours":

XHTML 1.0 Transitional
XHTML 1.0 Transitional contains all of the elements and attributes defined in HTML 4.01, with the notable exception of those related to the use of frames.
XHTML 1.0 Strict
XHTML 1.0 Strict contains only those elements and attributes related to structure, and very few of those related to presentation. For example, the <center></center> element is not part of XHTML 1.0 Strict.
XHTML 1.0 Frameset
XHTML 1.0 Frameset includes all of the HTML 4.01 elements and attributes, including those related to frames.

Other changes

With XHTML replacing HTML, there are a few more changes that are coming through, other than enforcing well-formed XHTML:

  • The tags must be lower case, so instead of <IMG SRC="resource/frankisboat.gif" WIDTH="389" HEIGHT="227" BORDER="0" ALT="boat">, as we would do in HTML, we instead use: <img src="resource/frankisboat.gif" width="389" height="227" border="0" alt="boat" />
  • All tags must close, either by using a corresponding closing tag which has a slash, like paragraph ( <p></p> ) for example, or some tags are self closing like the above img src tag and line break ( <br /> ). In HTML, many of these tags were simply left open.
  • All tags must be properly nested, so if you start tag "a" and then start tag "b", you must close tag "b" before you close tag "a".
  • Some tags which were previously allowed are no longer allowed.
  • All attributes must also be lower-case.
  • All values for attributes must be encased in single or double quotes.
by 1.1K

Remember to vote! Voting helps everyone find the best posts

Tags: None