The differences Between XHTML and HTML
XHTML is almost the same language as HTML, but there are some major differences.
This lesson focuses on:
- The differences between XHTML and HTML
The differences between XHTML and HTML
-
Tags in XHTML must be properly nested
In HTML, you might have a situation where tags are not closed in the proper order.
Example:
<html> <head> <title>Tags not properly closed</title> </head> <body> <pre><i>Preformatted and italic text</pre></i> </body> </html>In XHTML, all tags must be closed in the proper order:
Example:
<html> <head> <title>Tags properly closed</title> </head> <body> <pre><i>Preformatted and italic text</i></pre> </body> </html>
-
Tags in XHTML must be closed
This is wrong:
<b>this text is bold
This is right:
<b>this text is bold</b>
NOTE: Empty tags such as <br> and <img> must be closed as well. Such tags are closed with />
This is wrong:
<br> <img src="image.jpg">
This is right:
<br /> <img src="image.jpg" />
-
Tags in XHTML must be in lowercase
Not just tags, but their attributes as well must all be in lowercase in XHTML.
This is wrong:
<TABLE> <TR> <TD ALIGN="center">Cell 1</TD> <TD ALIGN="center">Cell 2</TD> </TR>
This is right:
<table> <tr> <td align="center">Cell 1</td> <td align="center">Cell 2</td> </tr>
-
XHTML documents can only have one root tag
The root tag of XHTML documents is <html>. All the other tags of an XHTML document must be nested within it. They can have sub-elements within them, all which must be nested properly within their parent elements.
Basic structure of an XHTML document:
<html> <head> <title>document title</title> </head> <body> document content </body> </html>




