HTML - XHTML
XHTML is HTML written in XML format.
What is XHTML?
- XHTML stands for Extensible Hypertext Markup Language
- XHTML is almost identical to HTML 4.01
- XHTML is a stricter and cleaner version of HTML
- XHTML is HTML defined as an XML application
- XHTML is a January 2001published W3C Recommendation
- 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 HTML rules):
<html>
<head>
<meta charset="utf-8">
<title>This is a non-standard HTML
title
<
body
<
h1Non-standard HTML
<
p
This is a paragraph
body
XML is a markup language that must be properly tagged and well-formed.
If you want to learn XML, please read ourXML Tutorial。
Today's technology world has a number of different browser technologies. 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 interpret "bad" markup languages.
So - by combining the strengths of XML and HTML, XHTML was developed. XHTML is HTML redesigned as XML.
The most important differences compared with HTML:
Document Structure
- The XHTML DOCTYPE ismandatory
- The XML namespace attribute in is *mandatory*
- 、、
and is also *mandatory*
Element Syntax
- XHTML elements mustproperly nested
- XHTML elements must alwaysclose
- XHTML elements mustlowercase
- An XHTML document must havea root element
Attribute Syntax
- XHTML attributes must uselowercase
- XHTML attribute values must be enclosed inenclosed in quotes
- XHTML attribute minimization is alsoforbidden
is mandatory
An XHTML document must have an XHTML document type declaration (XHTML DOCTYPE declaration).
You can find the complete set in the Runoob Tutorial tag reference manual: XHTML document type.
, ,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>
<meta charset="utf-8">
<title>Document Title
</
title
</
head
<
bodyDocument Content
</
body
</
htmlIn HTML, some elements may not be nested within each other, like this:
<
b
<
iBold and italic text
</
b
</
iIn XHTML, all elements must be properly nested within each other, like this:
<
b
<
iBold and italic text
</
i
</
bIncorrect example:
<
p
This is a paragraph
<
p
This is another paragraph
Correct example:
<
p
This is a paragraph
</
p
<
pThis is another paragraph
p
Empty elements must include a closing tag
Incorrect example:
Line break:
<
br
Horizontal line:
<
hr
Image:
<img src="happy.gif" alt=">Happy face
"
Correct example:
Line break:
<
br
/>Horizontal line:
<
hr
/>Image:
<img src="happy.gif" alt=">Happy face
"
/>
XHTML elements must be lowercase
Incorrect example:
<
BODY
<
PThis is a paragraph
</
P
</
BODYCorrect example:
<
body
<
pThis is a paragraph
</
p
</
bodyIncorrect example:
<table WIDTH="100%">Correct example:
<table width="100%">Incorrect example:
<
table
width
=
100
%Correct example:
<table width="100%">Incorrect example:
<
input
checked
<
input
readonly
<
input
disabled
<
option
selectedCorrect example:
<input checked="checked">
<input readonly="readonly">
<input disabled="disabled">
<option selected="selected">