the overview and comparation of html and xhtml · what is html? html is a language for describing...

33
The Overview and Comparation of HTML and XHTML Su Wei 860424-T086 [email protected]

Upload: others

Post on 03-Jun-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

The Overview and Comparationof HTML and XHTML

Su Wei

860424-T086

[email protected]

Page 2: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

HTML Example

<html>

<body>

<h1>My First Heading</h1>

<p>My first paragraph.</p>

</body>

</html>

Page 3: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

What is HTML?

HTML is a language for describingweb pages.

• HTML stands for Hyper TextMarkup Language

• HTML is not a programminglanguage, it is a markuplanguage

• A markup language is a set ofmarkup tags

• HTML uses markup tags todescribe web pages

Page 4: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

What is XHTML

• XHTML stands for EXtensibleHyperText Markup Language

• XHTML is almost identical toHTML 4.01

• XHTML is a stricter and cleanerversion of HTML

• XHTML is HTML defined as an XMLapplication

• XHTML is a W3C Recommendation

Page 5: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

• XHTML is compatible withHTML 4.01.

• All new browsers havesupport for XHTML.

Page 6: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

Why XHTML?

• XHTML is a combination of HTML andXML (EXtensible Markup Language).

• XHTML consists of all the elementsin HTML 4.01 combined with thesyntax of XML.

• We have reached a point where manypages on the WWW contain "bad" HTML.

• The following HTML code will workfine if you view it in a browser,

even if it does not follow theHTML rules:

Page 7: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

Continue...

<html>

<head>

<title>This is bad HTML</title>

<body>

<h1>Bad HTML

</body>

Bad html b-xhtml f-xhtml

Page 8: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

Continue...

• XML is a markup language where everythinghas to be marked up correctly, whichresults in "well-formed" documents.

• XML was designed to describe data and HTMLwas designed to display data.

• Today's market consists of differentbrowser technologies, some browsers runInternet on computers, and some browsersrun Internet on mobile phones or othersmall devices. The last-mentioned do nothave the resources or power to interpret a"bad" markup language.

• Therefore - by combining HTML and XML, andtheir strengths, we got a markup languagethat is useful now and in the future - XHTML.

Page 9: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

XHTML Syntax

Some XHTML Syntax Rules

• Attribute names must be in lowercase

• Attribute values must be quoted

• Attribute minimization isforbidden

• The id attribute replaces thename attribute

• The XHTML DTD defines mandatoryelements

Page 10: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

XHTML Syntax

Attribute Names Must Be In Lower Case

This is wrong:

<table WIDTH="100%">

This is correct:

<table width="100%">

Page 11: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

XHTML Syntax

Attribute Values Must Be Quoted

This is wrong:

<table width=100%>

This is correct:

<table width="100%">

Page 12: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

XHTML Syntax

Attribute Minimization Is Forbidden

This is wrong:

<input checked>

<input disabled>

<option selected>

This is correct:

<input checked="checked" />

<input disabled="disabled" />

<option selected="selected" />

Page 13: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

XHTML Syntax

The id Attribute Replaces

The name Attribute

HTML 4.01 defines a nameattribute for the elementsa, applet, frame, iframe,img, and map. In XHTML thename attribute isdeprecated. Use id instead.

Page 14: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

Continue...

This is wrong:<img src="picture.gif" name="picture1" />This is correct:<img src="picture.gif" id="picture1" />Note: To interoperate with older browsers for

a while, you should use both name and id,with identical attribute values, likethis:

<img src="picture.gif" id="picture1"name="picture1" />

IMPORTANT Compatibility Note: To make your XHTML compatible with

today's browsers, you should add an extraspace before the "/" symbol.

Page 15: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

XHTML Syntax

Mandatory XHTML Elements

All XHTML documents must have a DOCTYPEdeclaration. The html, head and bodyelements must be present, and the titlemust be present inside the head element.

Note: The DOCTYPE declaration is not apart of the XHTML document itself.It is not an XHTML element, and itshould not have a closing tag.

Page 16: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

Continue...

This is a minimum XHTML document template:

<!DOCTYPE Doctype goes here>

<htmlxmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Title goes here</title>

</head>

<body>

</body>

</html>

Page 17: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

XHTML DTD

<!DOCTYPE> Is Mandatory

An XHTML document consistsof three main parts:

* the DOCTYPE declaration

* the <head> section

* the <body> section

Page 18: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

Continue...

The basic document structure is:

<!DOCTYPE ...>

<html>

<head>

<title>... </title>

</head>

<body> ... </body>

</html>

Page 19: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

Continue...

This is 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>

Page 20: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

Continue...Document Type Definitions (DTD) ‏ * A DTD specifies the syntax of a web

page in SGML

* DTDs are used by SGML applications,such as HTML, to specify rules fordocuments of a particular type, includinga set of elements and entity declarations

* An XHTML DTD describes in precise,computer-readable language, the allowedsyntax of XHTML markup

There are three XHTML DTDs:

* STRICT

* TRANSITIONAL

* FRAMESET

Page 21: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

Continue...

• XHTML 1.0 Strict

• <!DOCTYPE html

• PUBLIC "-//W3C//DTD XHTML 1.0Strict//EN"

• "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

• Use the strict DOCTYPE when youwant really clean markup, freeof presentational clutter. Usetogether with CSS.

Page 22: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

Continue...

• XHTML 1.0 Transitional

• <!DOCTYPE html

• PUBLIC "-//W3C//DTD XHTML 1.0Transitional//EN"

• "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

• Use the transitional DOCTYPEwhen you want to still useHTML's presentational features.

Page 23: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

Continue...

• XHTML 1.0 Frameset

• <!DOCTYPE html

• PUBLIC "-//W3C//DTD XHTML 1.0Frameset//EN"

• "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

• Use the frameset DOCTYPE whenyou want to use HTML Frames tosplit the web page into two ormore frames.

Page 24: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

XHTML vs HTML

• You can prepare yourself forXHTML by starting to writestrict HTML.

• HTML is the antecedenttechnology to XHTML

Page 25: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

XHTML vs HTML

The Most Important Differences:

• XHTML elements must be properlynested

• XHTML elements must always be closed

• XHTML elements must be in lowercase

• XHTML documents must have one rootelement

Page 26: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

XHTML Elements Must Be Properly Nested

In HTML, some elements can be improperlynested within each other, like this:

<b><i>This text is bold and italic</b></i>

In XHTML, all elements must be properlynested within each other, like this:

<b><i>This text is bold and italic</i></b>

XHTML vs HTML

Page 27: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

This is wrong:

<ul>

<li>Coffee</li>

<li>Tea

<ul>

<li>Black tea</li> <li>Green tea</li> </ul>

<li>Milk</li>

</ul>

XHTML vs HTML

Page 28: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

This is correct:

<ul>

<li>Coffee</li>

<li>Tea

<ul>

<li>Black tea</li>

<li>Green tea</li>

</ul>

</li>

<li>Milk</li>

</ul>

XHTML vs HTML

Page 29: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

XHTML Elements Must Always Be Closed

Non-empty elements must have an end tag.

This is wrong:

<p>This is a paragraph

<p>This is another paragraph

This is correct:

<p>This is a paragraph</p>

<p>This is another paragraph</p>

XHTML vs HTML

Page 30: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

• Empty Elements Must Also Be Closed

• Empty elements must either have an end tag or thestart tag must end with />.

This is wrong:

A break: <br>

A horizontal rule: <hr>

An image: <img src="happy.gif" alt="Happy face">

This is correct:

A break: <br />

A horizontal rule: <hr />

An image: <img src="happy.gif" alt="Happy face" />

XHTML vs HTML

Page 31: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

XHTML Elements Must Be In Lower Case The XHTML specification defines that the tag names and

attributes need to be lower case.

This is wrong:

<BODY>

<P>This is a paragraph</P>

</BODY>

This is correct:

<body>

<p>This is a paragraph</p>

</body>

XHTML vs HTML

Page 32: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

XHTML Documents Must Have One Root Element All XHTML elements must be nested within the <html> root

element. All other elements can have sub (children)elements. Sub elements must be in pairs and correctlynested within their parent element. The basic documentstructure is:

<html>

<head> ... </head>

<body> ... </body>

</html>

XHTML vs HTML

Page 33: The Overview and Comparation of HTML and XHTML · What is HTML? HTML is a language for describing web pages. •HTML stands for Hyper Text Markup Language •HTML is not a programming

Thank You!