HTML Unit - 1
HTML Unit - 1
Cont..
Where do the documents reside?
On webservers.
Also called hypertext transfer
protocol(HTTP)servers.
What is http?
Hypertext transfer protocol
A protocol using which web clients(browsers) interact
with web servers.
It is a stateless protocol.
Fresh connection for every item to be downloaded.
Basic steps:
Client opens socket connection to the
http server.
Typically over port 80.
Illustration
http
reques
th
http
response
Webpage
Types:
Static
Webpage
Dynamic
Webpage
Static vs
Dynamic
Internet
Server
HTML
HTML
HTML
Static
Webpage
Static vs
Dynamic
Internet
Server
DB
Web
page
Web
page
Dynamic
Webpage
HTML
System
Requirements
Text Editor
Web Browser
other
applications
About HTML
Hypertext markup language:
Constitutes a collection of platform
independent styles that define the
various components of a web
document.
Styles indicated by markup tags.
What is HTML really?
plain-text documents can be created
using any text editor.
WYSIWYG editors are also available.
What is markup
language?
One where we can embed special
tags or formatting commands in the
text.
To describe how the text should be
displayed/printed.
HTML is markup language.
Special formatting codes(called
tags) to adjust fonts, create
bulleted lists, create forms,
display images, create tables etc..
Html tags
The left and right angle brackets are
used to enclose all special
instructions called tags.
Two classes of tags.
Those which appears in pairs
<i> good morning </i>.
Those which appear individually
<img src=baby.jpg>.
Browsers interpret the tags to display
a HTML page in properly formatted
form.
Some pints(contd.)
Some tags can have one or more
attributes to define some
additional characteristics of the
tag.
<img src=baby.jpg>
<body text=red
bgcolor=blue>
Comment lines
Comments are included between
<!--- and --- >
Comments cannot be nested
<!--- a comment here --- >
<!--- another comment in
two lines --- >
Body
Contains the actual matter of the
document.
Gets displayed within the browser
window.
17
Example-1
<html>
<head><title>First Page</title></head>
<body bgcolor="blue>
<hr>
Hello! This is my first page of code. I can't
believe I'm on my way to
being a webmaster.<p>
This is so great!!!
<hr>
</body>
</html>
HTML<h1>to<h6>Tags
<html>
<head><title>Demonstration of Headings
</title></head>
<body text="#FFFFFF"
bgcolor="#0000FF">
<h1>This is a first level heading. </h1>
<h2>The second level</h2>
<h3>The third level</h3>
<h4>Fourth level. </h4>
<h5>Fifth level.</h5>
<h6>And, finally, the sixth .</h6>
A small amount of plain non-heading text.
</body>
</html>
Contd.
<BR>
Used to indicate that the text
following <br> should begin on
the next line.
The amount of line spacing is
less than of a <p> break.
Contd.
<hr>
Produces a horizontal line,which
can be used to delimit sections.
Length of the line can be
specified.
Examples
<hr>
<hr size=20> [noshade option
possible]
<hr align=right width=75%
>
Appearance of Text
<b>..</b>
Displays enclosed text in bold.
<i></i>
Displays the enclosed text in
italics.
<cite>..</cite>
Tells the browser that this is a
citation usually displayed in italics.
Contd.
<pre>.</pre>
Allows browser to display
carefully laid out text.
Used to display program listings.
Example
<pre>
Main()
{
Int I,j;abc();
}
</pre>
Contd.
<sub>.</sub>
Displays the enclosed text as subscript.
<sup>..</sup>
Displays the enclosed text as
superscript.
<font>..</font>
Specifies the style of the enclosed text.
Attributes:
Color=color name
Face=typeface
Size=value [ 1 to 7; 3 is the default]
[can also specify as +n or n]
contd
<center>.</center>
Centers the enclosed elements
horizontally on the page.
<p align=option></p>
Used to align a paragraph
Option can be left,right or
center.
<html>
<head><title>Paragaph Aligning</title></head>
<body text=white bgcolor=blue>
<h3>
<P ALIGN=CENTER> This paragraph will be
aligned
at the center. Even as the browser window
size changes, the alignment remains the same.
</P>
<P ALIGN=LEFT>This demonstrates left
alignment. </P>
<P ALIGN=RIGHT>How about aligning by the right
margin? </P>
</h3>
</body>
</html>
<html>
<head><title>Layout Features
1</title></head>
<body text=yellow bgcolor=blue>
<h2> <pre>
begin
if (a > b)
then max := a;
else max := b;
end;
</pre> </h2>
<hr size=8 width=50%>
<hr>
<hr size=20 width="75%" noshade>
</body>
</html>
<html>
<head><title>Layout Features
2</title></head>
<body text=yellow bgcolor=blue>
<h3>Extended Quotations</h3>
<blockquote>
<P>This is the first paragraph within
the BLOCKQUOTE environment. </P>
<P>Another paragraph starts here. </P>
We type some text here without explicitly
giving paragraph break.
</blockquote>
</body>
</html>
<html>
<head><title> Superscript and
Subscript </title></head>
<body text=white bgcolor=blue>
<h1> y = x <sup> 3 </sup> + 2 x
<sup> 2 </sup> + 4 </h1>
<br>
<h2> W <sub> total </sub> = x
<sup> 2 </sup> - 5 <h2>
</body>
</html>
<html>
<head>
<title>Background Image</title>
</head>
<body text="#FFFFFF"
background="starwars.jpg">
<h2><center>
This page illustrates how a
background image
can be specified.
</center></h2>
</body>
</html>
HTML Lists
Types of Lists
Unnumbered List
Used to display a set of related
items that appear in no particular
order.
Each item is indented with a preceding
bullet symbol.
Unnumbered List
(contd.)
The <LI> items can contain multiple
paragraphs, specified using <P>.
Example:
<UL>
<LI> First item of the list
<LI> Second item of the list
<LI> Third item of the list
</UL>
Unnumbered List
(Example 1)
<html>
<head><title> Bulleted list 1 </title></head>
<body text=white bgcolor=blue>
<h2> The flowers I like: </h2>
<h3>
<UL>
<LI> Rose
<LI> Lotus
<LI> Daffodil
<LI> Marigold
</UL>
</h3>
</body>
<html>
Unnumbered List
(Example 2)
<html>
<head><title> Bulleted list 2 </title></head>
<body text=white bgcolor=blue>
<h2> The flowers I like: </h2>
<h3>
<UL type=square>
<LI> Rose
<LI> Lotus
<LI type=circle> Daffodil
<LI> Marigold
</UL>
</h3>
</body>
</html>
Numbered List
Numbered or ordered lists are used
when the sequence of the items is
important.
Specified using the tag:
<OL> </OL>
The individual items in the list are
specified using the <LI> tag.
Example:
<OL>
<LI> This is number one
<LI> This is number two
<LI> This is number three
</OL>
Definition List
Specified using the tag:
<DL> </DL>
Each definition comprises of a
definition term (<DT>) and a
definition description (<DD>).
Web browsers format each
definition on a new line and
indent it.
Nesting of Lists
Any list can be nested within
another list.
When unnumbered lists are nested,
the browser automatically uses a
different bullet symbol for each level.
When numbered lists are nested, by
default, every level is numbered
using the arabic numerals (1, 2, 3,
).
Nesting of Lists
<html><head><title>
List Nesting 1 </title></head>
(Example
1)
<body text=white bgcolor=blue>
<H3> My favorite languages are:
<UL>
<LI> Java <BR>
<UL>
<LI> object-oriented
<LI> platform independent
<LI> can be embedded within HTML
</UL> <BR>
<LI> Perl <BR>
<UL>
<LI> a scripting language
<LI> powerful string handling capabilities
<LI> widely used for writing CGI scripts
</UL>
</UL> </H3>
</body>
</html>
Nesting of Lists
(Example
<html><head><title>
List Nesting 22)
</title></head>
<body text=white bgcolor=blue>
<H3> My favorite languages are:
<OL>
<LI> Java <BR>
<UL>
<LI> object-oriented
<LI> platform independent
<LI> can be embedded within HTML
</UL> <BR>
<LI> Perl <BR>
<OL>
<LI> a scripting language
<LI> powerful string handling capabilities
<LI> widely used for writing CGI scripts
</OL>
</OL> </H3></body></html>
Specifying Hyperlinks
Hyperlinks
Chief power of HTML comes from
its ability to link text and/or
image to another document or
section of a document.
These links are called hyperlinks.
Browser by default highlights the
hyperlinks with color and/or
underline.
Hyperlinks (contd.)
Specified using the anchor tag:
<A> . </A>
Requires an attribute called HREF which
specifies the path of the resource to be linked.
Example:
<A HREF=face.jpg> portrait </A>
<a href=www.google.com> search </a>
<a href=mailto:[email protected]> Mail
me </a>
<a href=slides/ch5.pdf> download
pdf</a>
Absolute URL
<a
href=www.iitkgp.ac.in/people/isg/p
aper5.pdf>
One of my recent papers </a>
Linking to Specific
Sections
Anchors can be used to go to a
particular section in a document.
Within the same (or different) document.
Hyperlinks (Example)
<html><head><title> Link to Other Sites
</title></head>
<body text=white bgcolor=blue link=red vlink=green>
My favorite search engines are:
<ol>
<li> <a href="http://www.google.com"> Google </a>
<li> <a href="http://www.yahoo.com"> Yahoo </a>
<li> <a href="http://www.khoj.com"> Khoj </a>
</ol>
<hr>
<address>
Prof. Indranil Sen Gupta <BR> <BR>
<a href="mailto:[email protected]"> <img
src="mbox.gif"
align=middle> </a>
</address></body></html>
Images
Images
Supported image formats:
JPEG, GIF, PNG
Images (contd.)
Example:
<IMG SRC=blackrose.gif>
<img src=tiger.jpg height=80
width=150>
Images (Example 1)
<html><body>
An image
<img src=book.gif align="bottom" width="48"
height="48">
in the text
<p> An image
<img src =book.gif align="middle" width="48"
height="48">
in the text
<p> An image
<img src =book.gif align="top" width="48"
height="48">
in the text
</body></html>
Images (Example 2)
<html>
<body>
<img src =book.gif align ="left" width="48"
height="48">
A paragraph with an image. The image will float to
the
left of this text.
<p>
<img src =book.gif align ="right" width="48"
height="48">
A paragraph with an image. The image will float to
the
right of this text.
</body>
</html>
Images (Example 3)
<html>
<body>
<img src="book.gif" width="20" height="20"> <p>
<img src="book.gif" width="45" height="45"> <p>
<img src="book.gif" width="70" height="70"> <p>
Resizing an image by changing the values in the
"height" and "width" attributes of the img tag.
</body>
</html>
Images (Example 4)
<html>
<body>
It is possible to use an image as a link.
Click on the
image below to go to google.
<P>
<a href=www.google.com">
<img src=book.gif>
</a>
</body>
</html>
HTML Tables
Introduction
<table>
<tr>
<td> Good </td> <td> Bad </td>
</tr>
<tr>
<td> Cute </td> <td> Ugly </td>
</tr>
</table>
<TR> .. </TR>
Defines a row of cells within a
table.
Can have several attributes:
bgcolor = #rrggbb or color name
align = left | center | right | justify
<CAPTION> .. </CAPTION>
Provides a caption for the table.
Must immediately follow the table
tag, and precede all other tags.
<TD> .. </TD>
Defines a table data cell.
A table cell can contain any content,
like
an image, or even another table.
Can have several attributes:
bgcolor = #rrggbb or color name
colspan = number
== > similar
<TH> .. </TH>
Defines a table header cell.
Browsers generally display the
contents of the header cells in
bold, and centered.
Same attributes as the <TD>
tag.
HTML Frames
Introduction
What are frames?
A method for dividing the browser
window into smaller subwindows.
Each subwindow displaying a
different HTML document.
How does a page with frame look
like?
NEXT SLIDE
<FRAMESET> .. </FRAMESET>
Defines a collection of frames or other
framesets.
Attributes:
cols = list of lengths (number, %, or *)
rows = list of lengths (number, %, or *)
<FRAME>
Defines a single frame within a
frameset.
Attributes:
frameborder = 1 | 0
src = url
scrolling = yes | no | auto
marginwidth = number
marginheight = number
name = text
<NOFRAMES>
</NOFRAMES>
Specifies the contents to be
displayed by browsers that
cannot display frames.
Ignored by browsers that
support frames.
HTML Forms
Introduction
Provides two-way communication
between web servers and browsers.
Demand for most of the emerging
applications.
Providing dynamic contents.
Browser
WebServe
r
FORM Example
<FORM> </FORM>
Tag
This tag is used to bracket a
HTML form.
Includes attributes which specify
where and how to deliver filled-up
information to the web server.
METHOD:
Indicates how the information in
the form will be sent to the web
server when the form is submitted.
Two possible values:
POST: causes a forms contents to be
parsed one element at a time.
GET: concatenates all field names and
values in a single large string.
ACTION:
Specifies the URL of a program on
the origin server that will be
receiving the forms inputs.
Traditionally called Common
Gateway Interface (CGI).
Details of CGI to be discussed later.
Typical usage:
<FORM METHOD=POST
ACTION=cgi-bin/myprog.pl>
..
..
</FORM>
<INPUT> Tag
This tag defines a basic form
element.
Several attributes are possible:
TYPE
NAME
SIZE
MAXLENGTH
VALUE
SRC
ALIGN
TYPE:
Defines the kind of element that is to be
displayed in the form.
TEXT defines a text box, which
provides a single line area for entering
text.
RADIO radio button, used when a
choice must be made among several
alternatives (clicking on one of the
buttons turns off all others in the same
group).
CHECKBOX similar to the radio
buttons, but each box here can be
selected independently of the others.
NAME:
Specifies a name for the input field.
The input-handling program (CGI) in
reality receives a number of
(name,value) pairs.
SIZE:
Defines the number of characters that
can be displayed in a TEXT box without
scrolling.
MAXLENGTH:
Defines the maximum number of
characters a TEXT box can contain.
VALUE:
Used to submit a default value for a TEXT
or HIDDEN field.
Can also be used for specifying the label
of a button (renaming Submit, for
example).
SRC:
Provides a pointer to an image file.
Used for clickable maps.
ALIGN:
Used for aligning image types.
ALIGN = TOP | MIDDLE | BOTTOM
<TEXTAREA>
</TEXTAREA> Tag
Can be used to accommodate
multiple text lines in a box.
Attributes are:
NAME: name of the field.
ROWS: number of lines of text
that can fit into the box.
COLS: width of the text area on
the screen.
<SELECT> . </SELECT>
Tag
Used along with the tag <OPTION>.
Attributes are:
NAME: name of the field.
SIZE: specifies the number of option
elements that will be displayed at a
time on the menu. (If actual number
exceeds SIZE, a scrollbar will appear).
Example 1
Example 1
<HTML>
<HEAD>
<TITLE> Using HTML Forms </TITLE>
</HEAD>
<BODY TEXT="#FFFFFF"
BGCOLOR="#0000FF"
LINK="#FF9900" VLINK="#FF9900"
ALINK="#FF9900">
<CENTER><H3> Student Registration
Form </H3>
</CENTER>
Please fill up the following form about the
courses you will register for this Semester.
Example 2
Example 2
<HTML>
<HEAD>
<TITLE> Using HTML Forms </TITLE>
</HEAD>
<BODY TEXT="#FFFFFF" BGCOLOR="#0000FF"
LINK="#FF9900" VLINK="#FF9900"
ALINK="#FF9900">
<CENTER> <H3> Student Registration Form
</H3>
</CENTER>
Please fill up the form below and press DONE
when
done.
Example 3
Example 3
<HTML>
<HEAD>
<TITLE> Using HTML Forms </TITLE>
</HEAD>
<BODY TEXT="#FFFFFF" BGCOLOR="#0000FF"
LINK="#FF9900" VLINK="#FF9900"
ALINK="#FF9900">
<CENTER> <H3> Student Feedback Form </H3>
</CENTER>
Please fill up the following form and press DONE
when finished.
<FORM METHOD="POST"
ACTION="/cgi/feedback">
<P> Name: <INPUT NAME="name"
TYPE="TEXT"
SIZE="30" MAXLENGTH="50">
<P> Roll Number:
<INPUT NAME="rollno" TYPE="TEXT" SIZE="7">
<P> Password:
<INPUT NAME="code" TYPE=PASSWORD
SIZE="10">
<P> Course Numbers:
<INPUT NAME="course1" TYPE="TEXT"
SIZE="6">
<INPUT NAME="course2" TYPE="TEXT"
SIZE="6">
<INPUT NAME="course3" TYPE="TEXT"
SIZE="6">
properties
background-color: #FFCC66;
color: #990000;
background-image: url("butterfly.gif");
font-family: arial, verdana, sans-serif;
font-variant: small-caps;
font-variant: normal;
font-style: italic;
font-weight: bold;
font-size: 30px;
text-decoration: underline| overline|
line-through;
text-transform: uppercase|lowercase;
text-transform: capitalize;
Inline Styles
<H2 style = color: blue> This will
appear
as blue. </H2>
<P style = font-size: 12pt; fontfamily:
Verdana>
This paragraph will be set as per the
specified
Style. </P>
<html><head>
<style type = text/css>
<! - H2 {color: blue}
P {font-size: 12pt;
font-family: Verdana;
}
-->
</style>
<title> Example of using style sheets </title>
</head>
.
.
</html>
<head>
<link rel = STYLESHEET
href =
/pathname/mystyle.css
type = text/css>
</head>