HTML - XHTML
XHTML is HTML written in XML format.
What is XHTML?
XHTML refers to Extensible Hypertext Markup Language
- ##XHTML and HTML 4.01 is almost the same
- XHTML is a stricter and purer version of HTML
- XHTML is HTML defined in an XML application
- XHTML is a W3C recommended standard released in January 2001
- XHTML is supported by all major browsers
Why use XHTML?Many pages on the Internet contain "bad" HTML. If viewed in a browser, the following HTML code runs perfectly fine (even though it does not follow the HTML rules):
<html> <head> <title>This is bad HTML</title> <body> <h1>Bad HTML <p>This is a paragraph </body>XML is a document that must be properly marked up and well-formed markup language.
The most important difference compared to HTML: Document structure
- XHTML DOCTYPE is
mandatory The XML namespace attribute in
- <html> is
mandatory
##<html>, < head>, <title> and <body> are also - mandatory
- XHTML elements Must
- be properly nested
- closed
The XHTML document must have
a root elementAttribute syntax
- lowercase
XHTML attribute values must be surrounded by
quotesXHTML attribute minimization is also
prohibited##<!DOCTYPE ....> is mandatory
You can find the complete XHTML document type in W3School's Tag Reference Manual. The
<html>, <head>, <title>, and <body> elements must also be present, and the xml namespace must be specified for the document using the xmlns attribute in <html>.
The following example shows an XHTML document with the minimum required tags:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Title of document</title> </head> <body> ...... </body> </html>
XHTML elements must be nested reasonably
In HTML, some elements do not need to be nested in 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 have a closing tagIncorrect example:
<p>This is a paragraph <p>This is another paragraph
<p>This is a paragraph</p> <p>This is another paragraph</p>
Incorrect example:
A break: <br> A horizontal rule: <hr> An image: <img src="../style/images/happy.gif" alt="Happy face">Correct example:
A break: <br /> A horizontal rule: <hr /> An image: <img src="../style/images/happy.gif" alt="Happy face" />
XHTML elements must be lowercase
Incorrect example:
<BODY> <P>This is a paragraph</P> </BODY>Correct example:
<body> <p>This is a paragraph</p> </body>
Incorrect example:
<table WIDTH="100%">
Correct example:
<table width="100%">
Attribute values must have quotes
Wrong example:
<table width=100%>Correct example:
<table width="100%">
Attribute abbreviation not allowed
Incorrect example:
<input checked> <input readonly> <input disabled> <option selected>
Correct example:
<input checked="checked"> <input readonly="readonly"> <input disabled="disabled"> <option selected="selected">
How to convert HTML to XHTML
- Add an XHTML <!DOCTYPE> to your web page中
- Add the xmlns attribute to the html element of each page.
- Change all elements to lowercase
- Close all empty elements
- Change all Attribute names are lowercase
- Add quotes to all attribute values