Slide 3.5: XHTML (eXtensible HyperText Markup Language)
Slide 3.7: Differences between XHTML and HTML (cont.)
Home

Differences between XHTML and HTML


XHTML is not very different from the HTML 4.01 standard. So, you can prepare yourself for XHTML by starting to write strict HTML.

The Most Important Differences
  • 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 Elements Must Be Properly Nested
In HTML, some elements can be improperly nested within each other:

  <b><i>This text is bold and italic</b></i>

In XHTML, all elements must be properly nested within each other:

  <b><i>This text is bold and italic</i></b>

Note that a common mistake with nested lists, is to forget that the inside list must be within <li> and </li> tags. A </li> tag is inserted after the </ul> tag in the correct code example.

Wrong Correct
  <ul>
    <li>Coffee</li>
    <li>Tea
      <ul>
        <li>Black tea</li>
        <li>Green tea</li>
      </ul>
    <li>Milk</li>
  </ul>
  <ul>
    <li>Coffee</li>
    <li>Tea
      <ul>
        <li>Black tea</li>
        <li>Green tea</li>
      </ul>
    </li>
    <li>Milk</li>
  </ul>


Demonstration
The following demonstration shows how the script of HTML is displayed on the Web.