XHTML is a HTML written in XML format. XHTML refers to Extensible Hypertext markup language XHTML and HTML 4.01 are almost the same. XHTML is a stricter and purer version of HTML XHTML is a HTML defined as a XML application. XHTML is a W3C recommendation released in January 2001. XHTML is supported by all major browsers Many pages on the Internet contain “bad” HTML. If you view it in a browser, the following HTML code works perfectly (even if it does not follow the HTML rules): XML is a well-formed markup language that must be tagged correctly. There are some different browser technologies in today’s technology world. Some of them run on computers, while others may run on mobile phones or other small devices. Small devices often lack the resources and ability to explain “bad” markup languages. So-by combining the strengths of XML and HTML, XHTML was developed. XHTML is a redesigned HTML as XML. XHTML DOCTYPE is mandatory. XHTML elements must be nested correctly The XHTML element must always be closed XHTML elements must be lowercase An XHTML document must have a root element The XHTML property must be lowercase The XHTML attribute value must be enclosed in quotation marks XHTML attribute minimization is also prohibited XHTML documents must have XHTML document type declarations (XHTML DOCTYPE declaration). the xmlns attribute in The following example shows an XHTML document with the fewest required tags: In HTML, some elements can not be nested within each other, like this: In XHTML, all elements must be reasonably nested within each other, like this: Example of error: Correct example: Example of error: Correct example: Example of error: Correct example: Example of error: Correct example: Example of error: Correct example: Example of error: Correct example: Add a XHTML Add Change all elements to lowercase Turn off all empty elements Modify all attribute names to lowercase Add quotation marks to all attribute values 11.29.1. What is XHTML? ¶
11.29.2. Why use XHTML? ¶
<html><head><metacharset="utf-8"><title>This is an non-standard
HTML</title><body><h1>non-standard HTML<p>This is a paragraph</body>
11.29.3. The most important difference compared to HTML: ¶
Document structure ¶
<html>
XML in
namespace
attribute is mandatory
<html>
、
<head>
、
<title>
and
<body>
is also mandatory.Element syntax ¶
Attribute syntax ¶
11.29.4. <! DOCTYPE…. > is mandatory. ¶
<html>
specifies the XML namespace for the document.<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0
Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metacharset="utf-8"><title>document title</title></head><body>document content</body></html>
11.29.5. XHTML elements must be reasonably nested ¶
<b><i>Bold and Italic Text</b></i>
<b><i>Bold and Italic Text</i></b>
11.29.6. The XHTML element must be related to a closed tag ¶
<p>This is a paragraph<p>This is another paragraph
<p>This is a paragraph</p><p>This is another paragraph</p>
11.29.7. An empty element must contain a close tag ¶
branch:<br>horizontal line:<hr>picture:<imgsrc="happy.gif"alt="Happy face">
branch:<br/>horizontal line:<hr/>picture:<imgsrc="happy.gif"alt="Happy face"/>
11.29.8. XHTML element must be lowercase ¶
<BODY><P>This is a paragraph</P></BODY>
<body><p>This is a paragraph</p></body>
11.29.9. Attribute name must be lowercase ¶
<tableWIDTH="100%">
<tablewidth="100%">
11.29.10. Attribute values must have quotation marks ¶
<tablewidth=100%>
<tablewidth="100%">
11.29.11. Attribute abbreviations are not allowed ¶
<inputchecked><inputreadonly><inputdisabled><optionselected>
<inputchecked="checked"><inputreadonly="readonly"><inputdisabled="disabled"><optionselected="selected">
11.29.12. How to convert HTML to XHTML ¶
<!DOCTYPE>
go to your web page
xmlns
property is added to the
html
element.