XHTML Basics
XHTML Basics
Ritu Devi
Web site development
2
Internet Programming
3
Internet
Skills that are often required: Skills that are often required:
• CGI • XHTML
• PHP • Javascript
• ASP • Java
• Perl • Dreamweaver
• Java Servlet, … • Flash
• SMIL, XML …
4
What is XHTML?
5
Features of XHTML
⚫ Platform independent
⚫ The same piece of code can give the same display in Mac, Linux and
Windows
⚫ Text-based
⚫ Program is written with ASCII characters
⚫ Can be written using a text editor, such as notepad
⚫ An XHTML file must have an extension of .html or .htm
⚫ Information is generally enclosed inside paired tags
⚫ E.g. <html> … </html>
⚫ There are many tags in XHTML. They specify different information
required to display the Web page content
start tag
end tag (with a /)
6
Basic Structure of XHTML
<html>
<!-- This is a comment -->
<head>
<title>
This is title, describing the content
</title>
</head>
<body>
This is body, main part of the page
</body>
</html>
7
useful for validating the code to
see if they meet the xhtml standard
<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
comment
<!-- main.html -->
<!-- Our first Web page -->
define the namespace of html
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Internet and WWW How to Program -
Welcome
</title> define the title of the web page
</head>
<body>
<p>Welcome to XHTML!</p>
</body>
</html> <p> - new paragraph
8
Example
See the title defined in head
10
Tags
12
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Internet and WWW How to Program -
Headers</title>
</head>
</body>
13 </html>
Text under <h1> has the largest size
14
Meta Tag
<head>
<meta name=“keywords” content=“lecture notes, html,
form, feedback”>
<meta name=“description” content = “this web site
describes …”>
</head>
Description of a page seen on searching
15
Linking Webpage
⚫ One of the most important XHTML features is the
hyperlink
⚫ Link to another resources, such as web page, image, etc.
⚫ Achieve by using the anchor tag <a>:
⚫ To a web page:
<a href=“http://www.eie.polyu.edu.hk”>PolyU</a>
anchor attribute The name on the Web
page that represents this
Value of the attribute:
link
The address of the Web page
16
strong tag lets the text to be
displayed with bold font
<body>
<h1>Here are my favorite
Other similar tags include
sites</h1> <u> underline and <em> italic
18
Linking Email Addresses
⚫ To a mail address:
<a href=“mailto:enpklun@polyu.edu.hk”> Email me
</a>
⚫ With a subject:
<a href=“mailto:enpklun@polyu.edu.hk?subject=title”> Email
me
</a>
⚫ Multiple recipients:
<a href=“mailto:address1,address2, address3”> Email me
</a>
19
Linking Images
20
Will scale to this size to display
<body>
21
“alt” statement (may not
display the same for
Netscape)
22
Color
⚫ 2 ways to specify:
⚫ Use hexadecimal numbers
⚫ RGB format: FF: strongest, 00 weakest
⚫ #FF0000
⚫ #00FF00
⚫ #0000FF
⚫ Use color names
⚫ Black, White, Red, Cyan, Green, Purple, Magenta,
Blue, Yellow, OrangeRed, SpringGreen, BlueViolet,
Gold, DarkGoldenrod, Burlywood, …
23
Color
⚫ Background color:
⚫ <body bgcolor=“#00FF00”> … </body>
⚫ <body bgcolor =“green”> … </body>
⚫ Text color, links, visited links and activated links:
⚫ <body bgcolor =“white” text=“black” link=“purple”
vlink=“blue” alink=“yellow”>
⚫ Font color:
⚫ <font color=“green”> … </font>
24
Formatting Text
⚫ The format of displayed text can be changed by using <font>
… </font>
⚫ Attributes:
⚫ Color:
⚫ Size:
⚫ Relative: +1, +2, -3, …
⚫ Absolute: 10, 12, …
⚫ Face:
⚫ Font used
⚫ Arial, Verdana, Helvetica, Times, …
⚫ Multiple fonts:
⚫ <font face="Arial, Helvetica, sans-serif">
25
background color is yellow
<body bgcolor = “#ffff00”>
<p><font face="courier" color="green" size=“24”>
This is a test.</font> horizontal ruler
<hr />
<font face="times" color="red" >
This is a test.</font> the backslash is only
</p> to improve readability
<p>
<font face="arial" color="red" size=“+1”>
See the This is a test.</font>
difference <br />
between<font face="times" color="#ff00ff" size=“+2”>
This is a test.</font>
<p> and
</p>
<br> <p align = center><font face="courier" size=“+3”>
This is a test.</font>
26 </p> the text is placed at the center
</body>
size = 24
default size
27
Lists
⚫ Unordered list
⚫ a list that does not order its items by letter or number
⚫ <ul> … </ul> creates a list where each item begins with a
bullet
⚫ List items: <li> … </li>
⚫ For example
<ul>
<li>Apple</li>
<li>Orange</li>
<li>Banana</li>
</ul>
28
Lists
⚫ Ordered list
⚫ List that order their items by letter or
number
⚫ <ol type=“style”> … </ol>
When style equals to
⚫ 1: decimal, 1, 2, 3, …
⚫ I: uppercase Roman, I, II, III, …
⚫ i: lowercase Roman, i, ii, iii, …
⚫ A: uppercase Latin, A, B, C, …
⚫ a: lowercase Latin, a, b, c, …
⚫ List items: <li> … </li>
29
Table
Table caption
Table header
Table body
Table footer
30
Table border
● <table attribute=“value”> … </table>
● Attribute examples:
– border=“1” ⇒ the larger the number, the thicker is the border.
“0” means no border
– align=“center” ⇒ the table is aligned at the center of the
browser
– width=“60%” ⇒ to set the table width to 60% of the browser’s
width
● Caption of the table: <caption> … </caption>
● Insert a table row: <tr> … </tr>
● The head, body and foot sections are defined by
<thead> … </thead>
<tbody> … </tbody>
<tfoot> … </tfoot>
31
<table border = "1" width = "40%" align = left
summary = "This table provides information about
the price of fruit">
<caption><strong>Price of Fruit</strong></caption>
<thead>
<tr> <!-- <tr> inserts a table row -->
<th>Fruit</th> <!-- insert a heading cell -->
<th>Price</th>
</tr> The use of th tag
</thead> defines the
The tr tag insert content of header
<tbody> a new row or footer cells
<tr>
<td>Apple</td> <!-- insert a data cell -->
<td>$0.25</td>
</tr>
32
<tr> <tfoot>
<td>Orange</td> <tr>
<td>$0.50</td> <th>Total</th>
</tr> <th>$3.75</th>
<tr> </tr>
<td>Banana</td> </tfoot>
<td>$1.00</td> </table>
</tr>
<tr>
<td>Pineapple</td>
<td>$2.00</td> The use of th tag
</tr>
The use of td tag defines the
</tbody> content of header
defines the
content of body or footer cells
cells
33
34
Col span and Row span
⚫ colspan and rowspan allow merging columns/rows
⚫ <colspan=“number”>
⚫ data cell spans more than one column
⚫ <rowspan=“number”>
⚫ data cell spans more than one row
35
<table border=“1” width=“60%”>
<caption> Average Grades </caption>
<tr>
<th colspan=“4”> Report </th> first row
</tr>
<tr>
<th> </th> <th> 2000 </th> <th> 2001 </th>
<th> 2002 </th>
</tr> 2nd row
<tr>
<td> Maths </td> <td> A </td> <td rowspan=“2”
valign=“center”> B </td> <td> C </td>
</tr>
<tr> vertical alignment 3rd row
<td> English </td> <td> C </td> <td> A </td>
</tr>
</table>
4th row
36
37
Forms
38
A C
pp GI Internet
Web Server Web Client
1
www.abc.com/form.htm
2
www.abc.com
method = post or get
3
action = program name
(script) in server to
receive the data
Name = ???
and others
39
● A form element is inserted into a web page by the
<form> tag
● <form method = “value1” action = “value2”> … </form>
● Attributes:
– method = “post” or “get”
● Indicates the way the Web server will organize and
send you the form output
● post: causes changes to server data, e.g., update
a database
● get: does not cause any changes in server-side
data, e.g., make a database request
– action = “”
● Path to script, e.g., CGI
40
use post method script that will be called to
execute in the server
42
Form example 1
Thing that sends back to server
43
Form example 2
<p><label>Name:
<input type= "text" name= "name" size="25"
maxlength="30"/>
</label>
send the input the textbox to server
</p>
<input type= "submit" value="Submit your entries"/>
<input type= "reset" value="Clear Your Entries"/>
44 clear the content of textbox
Form example 3
Masked by asterisk
Space is counted here
<p><label>Comments:<br />
<textarea name= "comments" rows="4" cols="36">
Enter your comments here.
</textarea> </label></p>
<p><label>Please input your password:
<input name= "secret" type="password" size="25"/>
</label></p>
<input type= "submit" value="Submit Your Entries"/>
45<input type= "reset" value="Clear Your Entries"/>
Form example 4