You are on page 1of 47

INTRODUCTION TO

XHTML

HTML and XHTML


2

HTML: Hyper-Text Markup Language: the


foundation of the World-Wide Web.
Platform

independence: pages can be viewed


using a variety of different computers and
browsers.
Convenient linking from one page to another
(hypertext).
XHTML:
Extensible Hyper-Text Markup Language.
Based on HTML.

Editing XHTML
3

XHTML documents
Source-code

form
Text editor (e.g. Notepad)
.html or .htm file-name extension
Web server
Stores

Web

XHTML documents

browser

Requests

XHTML documents

First XHTML Example


4

<?xml version = "1.0"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"

"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

4
5

<!-- Fig. 4.1: main.html -->

<!-- Our first Web page

-->

7
8
9
10
11

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


<head>
<title>Internet and WWW How to Program - Welcome</title>
</head>

12
13
14
15

<body>

main.html
(1 of 1)

<p>Welcome to XHTML!</p>
</body>

16 </html>

Tag
5

A tag is a tag-name enclosed in angle brackets.

Tags usually come in pairs: an opening tag


and a closing tag, which is the same tag-name
preceded by a slash.

<tag-name>Content affected by tag</tag-name>

Opening Tag

ClosingTag

Tags for Document Structure


6

Some tags specify the overall structure of the


document:
<html> ... </html> encloses the entire document.

<head> ... </head> encloses the head portion of the


document.
Title of the document.
Style sheets and scripts.
<body> ... </body> encloses the body portion of the
document.
Pages content the browser displays.

First XHTML Example


7

XHTML comments
Start

with <!-- and end with -->

Paragraph
<p>

paragraph text </p>

Nesting of tags
8

Opening and closing tags define regions


affected by the tags. These regions must
nest, not overlap.

Correct:

<tag1>Some text <tag2>more text</tag2> and more.</tag1>

Wrong:

<tag1>Some text <tag2>more text</tag1> and more.</tag2>

Rules about Tags


9

Not all tags need closing tag

For some tags, a closing tag is optional:


<P> paragraph. Implies closing of previous paragraph tag.
Thus, the closing </p> tag is optional but recommended,
especially if the tag contains attributes.

For some tags, a closing tag is never used:


<br /> line break. Marks a location, not a region.

Tag names are case-insensitive


<br /> and <BR /> and <Br /> are all equivalent.

Rules about Tags


10

Unknown tags are ignored.

This rule allows new tags to be introduced


without causing problems for older browsers.

But it also means you need to be careful to


spell tag names correctly!

Tags with attributes


11

Some tags can be qualified by attributes that


provide needed additional information or
change the default properties of the tag.

Attributes are specified within the angle brackets


following the opening tag name.

Attributes are never listed in a closing tag.

<tag-name attribute="value attribute="value">Content text </tag-name>

Element
Tag

Property
Attribute

W3C XHTML Validation Service


12

Validation service ( validator.w3.org )


Checking

a documents syntax

URL

that specifies the location of the file


Uploading a file to the site
validator.w3.org/file-upload.html

W3C XHTML Validation Service


13

W3C XHTML Validation Service


14

Headers
15

Six headers ( header elements)


h1

through h6

<?xml version = "1.0"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"

"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

4
5

<!-- Fig. 4.4: header.html -->

<!-- XHTML headers

-->

7
8
9
10
11

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


<head>
<title>Internet and WWW How to Program - Headers</title>
</head>

12
13

<body>

14
15

<h1>Level 1 Header</h1>

16

<h2>Level 2 header</h2>

17

<h3>Level 3 header</h3>

18

<h4>Level 4 header</h4>

19

<h5>Level 5 header</h5>

20

<h6>Level 6 header</h6>

21
22

</body>

23 </html>

16

17

Images
18

Three most popular formats

Graphics Interchange Format (GIF).


Joint Photographic Experts Group (JPEG).
Portable Network Graphics (PNG).

There is no closing tag.


img element
src attribute

Specifies the location of the image file


width and height attributes

Alt attribute

Images: example
19
1

<?xml version = "1.0"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"

"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

4
5

<!-- Fig. 4.7: picture.html

-->

<!-- Adding images with XHTML -->

7
8
9
10
11

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


<head>
<title>Internet and WWW How to Program - Welcome</title>
</head>

12
13

<body>

14
15

<p>
<img src = "xmlhtp.jpg" height = "238" width = "183"

16

alt = "XML How to Program book cover" />

17

<img src = "jhtp.jpg" height = "238" width = "183"

18

alt = "Java How to Program book cover" />

19
20

</p>

21

</body>

22 </html>

Images: example
20
1

<?xml version = "1.0"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"

"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

4
5

<!-- Fig. 4.7: picture.html

-->

<!-- Adding images with XHTML -->

7
8
9
10
11

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


<head>
<title>Internet and WWW How to Program - Welcome</title>
</head>

12
13

<body>

14
15

<p>
<img src = "xmlhtp.jpg" height = "238" width = "183"

16

alt = "XML How to Program book cover" />

17

<img src = "jhtp.jpg" height = "238" width = "183"

18

alt = "Java How to Program book cover" />

19
20

</p>

21

</body>

22 </html>

Images: example
21

Linking
22

Hyperlink
References

other sources such as XHTML


documents and images.
Both text and images can act as hyperlinks.
Created using the <a> (anchor) tag
Attribute href

Specifies the location of a linked resource.


Link to e-mail addresses using mailto: URL.

<?xml version = "1.0"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"

"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

23

<!-- Fig. 4.5: links.html

-->

<!-- Introduction to hyperlinks -->

7
8
9
10
11

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


<head>
<title>Internet and WWW How to Program - Links</title>
</head>

12
13

<body>

14
15

<h1>Here are my favorite sites</h1>

16
17

<p><strong>Click a name to go to that page.</strong></p>

18
19

<!-- Create four text hyperlinks -->

20

<p><a href = "http://www.deitel.com">Deitel</a></p>

21
22

<p><a href = "http://www.prenhall.com">Prentice Hall</a></p>

23
24
25

<p><a href = "http://www.yahoo.com">Yahoo!</a></p>

26

<p><a href = "http://www.usatoday.com">USA Today</a></p>

27
28

</body>

29 </html>

24

<?xml version = "1.0"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"

"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

25

<!-- Fig. 4.6: contact.html

-->

<!-- Adding email hyperlinks -->

7
8
9
10
11

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


<head>
<title>Internet and WWW How to Program - Contact Page</title>
</head>

12
13

<body>

14
15

<p>

16

My email address is

17

<a href = "mailto:deitel@deitel.com">


deitel@deitel.com

18
19

</a>

20

. Click the address and your browser will

21

open an e-mail message and address it to me.

22

</p>

23

</body>

24 </html>

26

Image as a hyperlink
27

Nested tags.
<a> <img ..../> </a>

<?xml version = "1.0"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"

"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

4
5

<!-- Fig. 4.8: nav.html

-->

<!-- Using images as link anchors -->

7
8
9

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


<head>

10

<title>Internet and WWW How to Program - Navigation Bar

11

</title>

12

</head>

13
14

<body>

15
16
17
18
19
20

<p>
<a href = "links.html">
<img src = "buttons/links.jpg" width = "65"
height = "50" alt = "Links Page" />
</a><br />

21
22
23
24
25

28

<a href = "list.html">


<img src = "buttons/list.jpg" width = "65"
height = "50" alt = "List Example Page" />
</a><br />

26
<a href = "contact.html">

27

<img src = "buttons/contact.jpg" width = "65"

28

height = "50" alt = "Contact Page" />

29

</a><br />

30
31

<a href = "header.html">

32

<img src = "buttons/header.jpg" width = "65"

33

height = "50" alt = "Header Page" />

34

</a><br />

35
36

<a href = "table1.html">

37

<img src = "buttons/table.jpg" width = "65"

38

height = "50" alt = "Table Page" />

39

</a><br />

40
41

<a href = "form.html">

42

<img src = "buttons/form.jpg" width = "65"

43

height = "50" alt = "Feedback Form" />

44

</a><br />

45
46

</p>

47
48

</body>

49 </html>

29

30

31

Special Characters and More Line


Breaks

Character entity references (in the form &code;)


Numeric character references (e.g. &#38;)
del

sup

Superscript text

sub

Strikethrough text:

Subscript text

<hr />

Horizontal rule (horizontal line)

<?xml version = "1.0"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"

"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

4
5

<!-- Fig. 4.9: contact2.html

-->

<!-- Inserting special characters -->

7
8
9

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


<head>

10

<title>Internet and WWW How to Program - Contact Page

11

</title>

12

</head>

13
14

<body>

15
16

<!-- special characters are entered -->

17

<!-- using the form &code;

18

<p>

-->

19

Click

20

<a href = "mailto:deitel@deitel.com">here

21

</a> to open an e-mail message addressed to

22

deitel@deitel.com.

23

</p>

24
25

32

<hr /> <!-- inserts a horizontal rule -->

26
27

<p>All information on this site is <strong>&copy;</strong>


Deitel <strong>&amp;</strong> Associates, Inc. 2002.</p>

28
29
30

<!-- to strike through text use <del> tags

-->

31

<!-- to subscript text use <sub> tags

-->

32

<!-- to superscript text use <sup> tags

-->

33

<!-- these tags are nested inside other tags -->

34

<p><del>You may download 3.14 x 10<sup>2</sup>

35

characters worth of information from this site.</del>

36

Only <sub>one</sub> download per hour is permitted.</p>

37
38

<p>Note: <strong>&lt; &frac14;</strong> of the information


presented here is updated daily.</p>

39
40
41

</body>

42 </html>

33

34

Unordered Lists
35

Unordered list element ul


Creates

a list in which each item begins with a


bullet symbol
li (list item)
Entry

in an unordered list

<?xml version = "1.0"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"

"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

4
5

<!-- Fig. 4.10: links2.html

-->

<!-- Unordered list containing hyperlinks -->

7
8
9
10
11

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


<head>
<title>Internet and WWW How to Program - Links</title>
</head>

12
13

<body>

14
15

<h1>Here are my favorite sites</h1>

16
17

<p><strong>Click on a name to go to that page.</strong></p>

18
19

<!-- create an unordered list -->

20

<ul>

21
22

<!-- add four list items -->

23

<li><a href = "http://www.deitel.com">Deitel</a></li>

24
25

36

<li><a href = "http://www.w3.org">W3C</a></li>

26
<li><a href = "http://www.yahoo.com">Yahoo!</a></li>

27
28

<li><a href = "http://www.cnn.com">CNN</a></li>

29

</ul>

30
31

</body>

32 </html>

37

Nested and Ordered Lists


38

Represent hierarchical relationships


Ordered lists (ol)
Creates

number

a list in which each item begins with a

<?xml version = "1.0"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"

"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

4
5

<!-- Fig. 4.11: list.html

-->

<!-- Advanced Lists: nested and ordered -->

7
8
9
10
11

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


<head>
<title>Internet and WWW How to Program - Lists</title>
</head>

12
13

<body>

14
15

<h1>The Best Features of the Internet</h1>

16
17

<!-- create an unordered list -->

18

<ul>

19
20
21
22
23

39

<li>You can meet new people from countries around


the world.</li>
<li>
You have access to new media as it becomes public:

24

<!-- this starts a nested list, which uses a -->

25

<!-- modified bullet. The list ends when you -->

26

<!-- close the <ul> tag.

27

<ul>

28

<li>New games</li>

29

<li>

30

New applications

31
32

<!-- nested ordered list -->

33

<ol>

34

<li>For business</li>

35

<li>For pleasure</li>

36
37

</ol>
</li>

38
39

<li>Around the clock news</li>

40

<li>Search engines</li>

41

<li>Shopping</li>

42

<li>

43

Programming

44

40

45

<!-- another nested ordered list -->

46

<ol>

47

<li>XML</li>

48

<li>Java</li>

-->

49

<li>XHTML</li>

50

<li>Scripts</li>

51

<li>New languages</li>
</ol>

52
53

</li>

54
55

</ul> <!-- ends the nested list of line 27 -->

56

</li>

57
58
59

<li>Links</li>

60

<li>Keeping in touch with old friends</li>

61

<li>It is the technology of the future!</li>

62
63

</ul>

64
65

</body>

66 </html>

41

<!-- ends the unordered list of line 18 -->

42

Lists
43

type attribute:
Ordered

list:

1:

1, 2, 3, ..
a: a, b, c, ..
A: A, B, C, ..
i: i, ii, iii, ..
I: I, II, III, ..
Unordered
Circle
square

disc

list:

o gg

gg
gg

Tags for Style


44

Explicit style tags


<b>Boldfaced text</b>
<i>Italicized text</i>
<u>Underlined text</u>
<tt>Typewriter-font text</tt>

Logical style tags


<strong>Prominent text</strong> - usually bold
<em>Emphasized text</em> - usually italics
<cite>Cited text</cite> - usually italicized
<code>Computer code</code> - usually in typewriter
font

Special characters
45

Some characters such as angle brackets are


reserved for special meanings in HTML. Others
are not available on many keyboards. These
characters can be put into content using codes
between ampersand and semicolon:
&lt; - the less-than symbol < (left angle bracket)
&gt; - the greater-than symbol > (right angle bracket)
&amp; - the ampersand sign &
&copy; - the copyright symbol

Many more are defined. Note that unlike tags,


these codes are case-sensitive.

Organizational Tags
46

Paragraphs and Layout


<center>Centered text</center>
- changes the justification of the enclosed text
(normally left-justified) to centered.
<blockquote>Quoted text</blockquote>
- for large blocks of quoted material.

Other HTML tags


47

Horizontal rule (line): use <hr>.


It

always appears on a line by itself.

This tag takes an optional attribute width


such as <hr width="50%"> to control how
far across the page it extends.

For more HTML tags and attributes, see HTML


reference sheet.

You might also like