HTML- XHTML
XHTML is a HTML written in XML format.
What is XHTML?
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
Why use XHTML?
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):
<html><head><metacharset="utf-8"><title>This is an non-standard
HTML</title><body><h1>non-standard HTML<p>This is a paragraph</body>
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.
The most important difference compared to HTML:
Document structure
XHTML DOCTYPE is mandatory.
<html>
XML innamespace
attribute is mandatory<html>
、<head>
、<title>
and<body>
is also mandatory.
Element syntax
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
Attribute syntax
The XHTML property must be lowercase
The XHTML attribute value must be enclosed in quotation marks
XHTML attribute minimization is also prohibited
<! DOCTYPE…. > is mandatory.
XHTML documents must have XHTML document type declarations (XHTML DOCTYPE declaration).
the xmlns attribute in <html>
specifies the XML namespace for the document.
The following example shows an XHTML document with the fewest required tags:
<!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>
XHTML elements must be reasonably nested
In HTML, some elements can not be nested within each other, like this:
<b><i>Bold and Italic Text</b></i>
In XHTML, all elements must be reasonably nested within each other, like this:
<b><i>Bold and Italic Text</i></b>
The XHTML element must be related to a closed tag
Example of error:
<p>This is a paragraph<p>This is another paragraph
Correct example:
<p>This is a paragraph</p><p>This is another paragraph</p>
An empty element must contain a close tag
Example of error:
branch:<br>horizontal line:<hr>picture:<imgsrc="happy.gif"alt="Happy face">
Correct example:
branch:<br/>horizontal line:<hr/>picture:<imgsrc="happy.gif"alt="Happy face"/>
XHTML element must be lowercase
Example of error:
<BODY><P>This is a paragraph</P></BODY>
Correct example:
<body><p>This is a paragraph</p></body>
Attribute name must be lowercase
Example of error:
<tableWIDTH="100%">
Correct example:
<tablewidth="100%">
Attribute values must have quotation marks
Example of error:
<tablewidth=100%>
Correct example:
<tablewidth="100%">
Attribute abbreviations are not allowed
Example of error:
<inputchecked><inputreadonly><inputdisabled><optionselected>
Correct example:
<inputchecked="checked"><inputreadonly="readonly"><inputdisabled="disabled"><optionselected="selected">
How to convert HTML to XHTML
Add a XHTML
<!DOCTYPE>
go to your web pageAdd
xmlns
property is added to thehtml
element.Change all elements to lowercase
Turn off all empty elements
Modify all attribute names to lowercase
Add quotation marks to all attribute values