2.1 - The Overview and Comparation of HTML and XHTML
2.1 - The Overview and Comparation of HTML and XHTML
<h1>My F i r s t Heading</h1>
<p>My f i r s t paragraph.</p>
</body>
</html>
What i s
HTML?
HTML i s a language f o r
describing web pages.
• HTML stands f o r Hyper
Text Markup Language
• HTML i s not a
programming language,
i t is a markup
language
• A markup language i s a set
of markup tags
• HTML usesmarkup tags
to describe web
pages
What i s
XHTML
• XHTML stands f o r
EXt ensible HyperText
Markup Language
• XHTML i s almost i dentical
to HTML 4.01
• XHTML i s as t r i c t e r and
cleaner version of HTML
• XHTML i s HTML defined as an
XML application
• XHTML i s a W3C
Recommendation
• XHTML i s compatible
with HTML 4.01.
• All new browsers
have support f o r
XHTML.
Why
XHTML?
• XHTML i s a combination o f HTML
and XML (EXtensible Markup
Language).
• XHTML c o n s i st s o f a l l the
elements i n HTML 4.01
combinedwith the syntax of
XML.
• We have reached a point where
many pages on the WWW
contain "bad" HTML.
• The following HTML code w i l l
work f i n e i f you view it
in a browser, even i f i t does
Continue...
<html>
<head>
<title>This i s bad HTML</title>
<body>
<h1>Bad HTML
</body>
This i s wrong:
<table WIDTH="100%">
This i s c o r r e c t :
<table width="100%">
XHTML Syntax
At t r i bu t e Values Must Be Quoted
This i s wrong:
<table width=100%>
This i s c o r r e c t :
<table width="100%">
XHTML Syntax
At t ri b ut e Minimization I s Forbidden
This i s wrong:
<input checked>
<input disabled>
<option selected>
This i s c o r r e c t :
<input
checked="checked"
/>
<input
disabled="disable
d" />
XHTML Syntax
The i d At t ri b ut e Replaces
The name At t r i bu t e
HTML 4.01 defines a
name a t t r i b u t e f o r the
elements a , a p p l e t ,
frame, iframe, img, and
map. In XHTML the name
attribute is
deprecated. Use id
instead.
Continue...
This i s wrong:
<img s r c = " p i c t u r e . g i f " name="picture1" />
This i s c o r r e c t :
<img s r c = " p i c t u r e . g i f " id="picture1" />
Note: To i nt e r op e r a t e with older
browsers for a while, you should use
both name andi d , with i d e n t i c a l
attribute val ues, l i k e t h i s :
<img s r c = " p i c t u r e . g i f "
id="picture1" name="picture1" />
IMPORTANT Compatibility Note:
To make your XHTML compatible with
t oda y's browsers, you shouldaddan
extra space beforethe "/" symbol.
XHTML Syntax
Mandatory XHTML Elements
All XHTML documentsmust have a
DOCTYPE d e c l a r a t i o n . The html, head
and body elements must
be p r e s e n t , and the t i t l e must
be present i ns i de the head
element.
<body>
</body>
</html>
XHTML
DTD
<!DOCTYPE> I s Mandatory
An XHTML document
consists of t h r e e main
parts:
* the DOCTYPE
declaration
* the <head>
section
* the <body>
section
Continue...
The basic document s t r u c t u r e i s :
<!DOCTYPE . . . >
<html>
<head>
<title>... </title>
</head>
<body> . . . </body>
</html>
Continue...
This i s a simple (minimal) XHTML document:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html>
<head>
<title>simple document</title>
</head>
<body>
<p>a simple paragraph</p> e1
</body>
</html>
Continue...
Document Type Definitions (DTD)
*A DTD s p e c i f i e s the syntax of a
web pagei n SGML
*DTDs areused by SGML applications,
suchas HTML, t o specify r u l e s f o r
documents of a p a r t i c u l a r ty p e ,
including a s e t of elements and
e n t i t y declar ations
*An XHTML DTD describes i n
p r e c i s e , computer-readable language,
theallowed syntax of
XHTML markup
There are thr ee XHTML DTDs:
*STRICT
*TRANSITIONAL
*FRAMESET
Continue...
• XHTML 1.0 S t r i c t
• <!DOCTYPE html
• PUBLIC "-//W3C//DTD XHTML
1.0 Strict//EN"
• "http://www.w3.org/TR/xhtml1/D
TD
/ xh t m l 1- s t ri c t .dt d" >
• Use the s t r i c t DOCTYPE when
you want really clean
markup, f r e e of prese nt at i onal
c l u t t e r. Use together
with CSS.
Continue...
• XHTML 1.0 Transit ional
• <!DOCTYPE html
• PUBLIC "-//W3C//DTD XHTML
1.0 Transitional//EN"
• "http://www.w3.org/TR/xhtml1/D
TD
/xht m l 1-t ransit i onal .dt d">
• Use the t r a n s i t i o n a l DOCTYPE
when you want to
s t i l l use HTML's
pres ent at i onal f e a t u r e s .
Continue...
• XHTML 1.0 Frameset
• <!DOCTYPE html
• PUBLIC "-//W3C//DTD XHTML
1.0 Frameset//EN"
• "http://www.w3.org/TR/xhtml1/D
TD
/xhtml1-frameset.dtd">
• Use the frameset DOCTYPE
when youwantt o useHTML
Frames to s p l i t the web
page i n t o two or more
frames.
XHTML vs
HTML
• You canprepare yourself
for XHTML by starting
t o write s t r i c t HTML.
• HTML i s the
antecedent technology
to XHTML
XHTML vs
HTML
The Most Important Differences:
• XHTML elements must be
properly nested
• XHTML elements must always be
closed
• XHTML elements must be i n
lowercase
• XHTML documents must have one
root element
XHTML vs
HTML
XHTML Elements Must Be Properly
Nested In HTML, some elements canbe
improperly nested withineach o t h e r, l i k e
this:
<b><i>This t e x t i s bold and i t a l i c </ b>< / i >
This i s wrong:
<BODY>
<P>This i s a paragraph</P>
</BODY>
This i s correct:
<body>
<p>This i s a paragraph</p>
</body>
XHTML vs
HTML
XHTML Documents Must Have One Root Element
Al l XHTML el ement s mus t be nes t ed
wi t hi n t he <ht ml > r oot element. All other
elements can have sub ( c h il d r e n )
elements. Sub elements must be i n
p a i r s and c o r r e c tl y nested within their
parent element. The basic document s t r u c t u r e
is:
<html>
<head> . . . </head>
<body> . . . </body>
</html>
Thank You!