Differences from HTML: XHTML Elements

XHTML Elements

In HTML, some elements can be improperly nested within each other, like this:

<b><i>This text is bold and italic</b></i>
In XHTML, all elements must be properly nested within each other, like this:

<b><i>This text is bold and italic</i></b>
//XHTML elements must always be closed

//this is wrong
<p>This is a paragraph
<p>This is another paragraph

//this is correct
<p>This is a paragraph</p>
<p>This is another paragraph</p>
//empty elements must also be closed
//this is wrong
A break: <br>
A horizontal rule: <hr>
An image: <img src="happy.gif" alt="Happy face">

//this is correct
A break: <br />
A horizontal rule: <hr />
An image: <img src="happy.gif" alt="Happy face" />
//XHTML elements must be in lower case
//this is wrong
<BODY>
<P>This is a paragraph</P>
</BODY>

//this is correct
<body>
<p>This is a paragraph</p>
</body>
  • Must be properly nested.
  • Must always be closed.
  • Must be in lowercase.
  • XHTML documents must have one root element.

Related concepts

Differences from HTML: XHTML Elements — Structure map

Clickable & Draggable!

Differences from HTML: XHTML Elements — Related pages: