Cs1 Chapter 4 - HTML
Cs1 Chapter 4 - HTML
HTML.
INTRODUCTION
HTML is an evolving language,
and stands for Hyper Text Markup Language
It is a text file containing small
markup tags which are instructions given to
browser about how to display the
page.
An HTML file must have an
htm or html file extension.
An HTML file can be created using a
simple text editor (like Notepad in
windows).
HTML was invented by Tim Berners-Lee
while at CERN, the European Laboratory
for Particle Physics in Geneva.
Advantages of HTML
1) HTML is an easy to use,
learn, implement and flexible alternative to
traditional presentation and tedios software.
2) Contains powerful formatting facilities.
3) HTML documents are device and platform
independent. (Since it can be
designed to work on not only home PCs but also on graphical workstations,
dumb terminals, network computers, hand-held devices etc.)
4) You can traverse to any HTML document required because
of hyper linking
facility available, thus controlled navigation is possible.
) Required HTML pages can be updated easily, without changing whole
document.
O) lt is a kind of software, which has been called world ware.
) Independent work can be done and you need not rely cn application or
program vendor.
) No expensive license software or hardware required.
HTML
126
Disadvantages of HTML
1) HTML doesn't offer programming languages features and capabilities.
2) It's easy to write "bad" HTML containing errors.
3) Complex HTML code is hard to read and understand and code complexity
increases to make interactive web page. So building comnplex pages is very
time consuming.
4) I's easy to make mistakes (e.g. leaving out a ">" or "/" character).
5) Special types of software like scripting languages (VB Script, Java Script) are
required for handling different events and validations.
6) Can't detect errors easily since no special debugging tool is provided.
HTML Editors
HTML Editors are programming tools for Hyper Text Markup Language
(HTML) documents.
There are three categories of HTML Editors:
1. Text Editors
1)Text Editors
These editors only edit ASCII text. They offer no functionality to facilitate
better HTML development. They are tuseful if your knowledge of HTML is excellent.
Some examples Text Editors include Notepad (Windows), Simple Text
of
(Macintosh), and Pico (Unix).
They are typically WYSIWYG. WYSIWYG is an acronym for "what you se
is what you get"; it means that you design your HTML document visually, as if yo
were using a word processor, instead
of writing the markup tags in a plain-text
and imagining what the resulting page will look like.
KHTML>
<HEAD>
<TITLE> HOME PAGE
STITLE>
<SHEAD>
<BODY> THIS
IS MY FIRST WEB
<BODY> PAGE
KHTML>
HTML
129
(When yOu save an HTML file, you can use either the .htm or the .html extension.
Save the file as "firstpage.htm". Open this file through your Internet browser.)
Example Explained
The first tag in your HTML document is <HTML>. This tag tells your browser
that this is the start of an HTML document. The last tag in your document is
sIHTML>. This tag tells your browser that this is the end of the HTML document.
The text between the <HEAD> tag and the <HEAD> tag is header information.
Header information is not displayed in the browser window. The title is displayed in
your browser's caption.
The text between the <BODY> tags is the text that will be displayèd in your
browser.
The text between the <TITLE> tags is the title of your page
1.<HTML>
The HTML tag identifies a document as
an HTML document. All HTML documents
should start with the <HTML> tag and end with the </HTML> tag.
Syntax
<HTML>......HTML>
e.g.
a
The following example begins and ends short document with
the HTML tag.
<HTMLS
<BODY
This is HTML file.
<BODY>
HTML>
Syntax
<HEAD>...SHEAD>
HTML
130
C.g. <HTML>
<HEAD>
<TITLE>WELCOME TO FIRST WEBSITE<TITLE>
HEAD>
<HTML>
D) Character-Level Elements
Then are what I call character-level elements, namely line breaks (BR) and images
(IMG). These are treated much like characters, and can appear wherever there is a
character in a document.
E) Character References
Finally there are character or entity references. These are special HTML "escape"
codes that can be used to enter special characters that are hard to type, such as
accented or other non-ASCII characters. You also need to use these to type angle
brackets or ampersand characters -- as these are otherwise interpreted as HTML tags
(<.. >)or as the beginnings of character or entity references (&).
Analogous to the text-level markup is the anchor (A) element. This is the element that
marks hypertext links. Obviously you want to know a lot about this one.
ADDRESS Elemnent
The ADDRESS element is used for address
information, signatures, statementsO
authorship, etc. It is often placed at the
bottom (or top) of a document. The renderin8
of the contents of the ADDRESS is left up to the
browser -- most browsers render
ADDRESS in italics. It may also be right
justified, or indented. th
HTML
133
e.g.
ADDRESS><A HREF="c:ladd.html">X.Y.Z.</A><IADDRESS>
<P><ADDRESS> <P>
WEB DESIGNER<BR>
Tel (023) 122 123.
ADDRESS> <P>
These. are rendered as
X.Y.Z
WEB DESIGNER
Tel (023) 122 123.
An address cannot contain P, BLOCKQUOTE, FORM or other block elements, but
can contain text, text markup (emphasis, etc.), anchor elements or even images.
e.g.<BODY>
<H1>This is my first web page</Hl>
WIDTH="20%">
<HR SIZE=5
<BODY>
HTML source code Comments in HTML.
O. <! Defines a comment in the your
a comment. You can use comments to explain
The browser will ignore a date.
can you when you edit the source code at later
Code, which help
7. Headings
<HI>---<H6> Defines heading 1 to heading 6.
Headings are defined with the <HI> to <H6> tags. <Hl> defines the largest
heading. <H6> defines the smallest heading (as shown).
8. <PRE> tag
This tag preformats the text. The text appearing between <pre> and </pre> is
displayed in monospace form. Using this tag, we can position the characters. It can
also be used for columnar lists.
Eg. <PRE> Employee_name Employee_number Employee_address </PRE>
So output is displayed as :
Employee_name Employee_number Employee_address
4.g FONT TAGS IN HTML
To have different size and color to the text, rather than using headings tags,
many people uses <FONT>tag.
The <FONT> tag in HTML is deprecated. It is supposed to be removed in a future
version of HTML..
Font attributes:
Attribute Example Purpose
size="number" size="2" Defines the font size
size="+number" size="+1" Increases the font size
size="-number" size="-1" Decreases the font size
|face="face-name" face=*Times new Roman' Defines the font-name
color="color-value" color="#eeff00 Defines the font color
color="color-name" color="red" Defines the font color
HTML 135
C.g•
<P>
RONT SIZE=*5 FACE=VERDANA" COLOR="#AA0OFF"s
This is example of demonstrating fonts. <FONT>
<P>
<MARQUEE> TAG
MARQUBE, Supported only by the Microsoft Internet Explorer 2 (and later)
hrowser., is used to create a scrolling text marquee.
Character Formatting
HTML has two types of styles for individual words or sentences: logical and
physical. Logical styles tag text according to its meaning, while physical styles
indicate the specific appearance of a section. For example, in the preceding sentence,
the words "logical styles" was tagged as “strong." The same effect (formatting those
words in italics) could have been achieved via a different tag that tells
your browser
to "put these words in bolds." Try to be consistent about which type of style
you use.
Logical Styles:
<EM>
cannot reset your
for emphasis. Typically displayed in italics. (Consultants
password unless youcall the help line.)
<CODE
for computer code. Displayed in
a
fixed-width font. (The <stdio.h> header
file)
<STRONG> your
strong emphasis. Typically displayed in bold. (NOTE: Always check
for
links.)
<VAR>
you will replace the variable with specific information.
for a variable, where file.)
displayed in italics. (rm filename deletes the
Typically
136 HTML
Physical Styles
<B> bold text :It boldface text appearing between <B> and </B> tag.
e.g.<B>n Bold</B>
Output is In Bold
<>italic text : It italicize text appearing between <I> and </> tag.
e.g.<I>In Italics</>
Output is In Italics
<U>underline text : It underlines text appearing between <U> and <U> tag.
e.g.<U>Underlined<U>
Output is Underlined
different document.
HTML
138
as a tab wi. un the fileB.html file
Think of the characters after the hash (#) mark
at the top of the window when
This tab tells your browser what should be displayed
the link is activated.
Next, create the named anchor (in this example
"differentlink ") in fileB.html as:
<H2><A NAME=" differentlink "> to a specific section <Á><H2>
in place, you can bring a reader directly to , " to a
With both of these elements
specific section"word in fileB.html
Important Hint
You cannot make links to specific sections within a different documnent unless
or that
either you have write permission to the coded source of that document
document already contains in-document named anchors
Attributes for A and LINK :>The following are the attributes appropriate to
either Anchor or LINK elements. The other attributes are less common, and can be
omitted at an introductory reading.
1. HREF (link to object)
2. NAME (link from object
3. TITLE (TITLE of document)
4. METHODS (how to link -- this attribute has been dropped from the HTML
specification, and should not be used)
2.0rdered Lists a list of items. The list items are marked with
An ordered list is also
an numbered is identical to an unnumbered list,
numbers. A ordered list also called a you can put paragraphs, line
except it uses <OL> instead of <UL>. Inside list item
lists, etc. You can specify style of numbering for the list
breaks, images, links, other can take values "I" for uppercase
<OL> tag and it
Items by giving type attribute in
uppercase letters, "a" for lower case alpha
roman, ";" for lower case roman, "A" for
start attribute in <OL> tag is used to start the list from the
numeric letter. The
e.g. <OL start = "6"> will start the list items from number 6.
Tequired number.
e.g. <HTML>
<BODY> List<B><H4
<H4><B>This is an Ordered
<OL type = "i">
<LIbSunday</LI
<LIbMonday</LI>
<LI>Tuesday</LI>
<JOL>
140
</BODY>
</HTML>
so output given by browser is:
4.Nested lists
Lists can be nested. You can also have a number of paragraphs, each containing a
nested list, in a single list item.
C.g.
<HTML>
<BODY>
<H4>This example of Nested List</H4>
HTML
141
<UL>
<LIbScripted Programming</LI>
<LbStructured Programming.
<UL>
<LIbBasic</LI
<LI>Pascal</LI>
<SUL>
<LS
<LbObject Oriented Languages</LI>
<SUL>
<BODY>
<HTML>
ACWy Documentsla.html- Microsoft Inteinet Explorer
Help
Fe Edt View Go Favornes
• Scripted Programming
• Structured Programming
o Basic
o Pascal
• Object Oriented Languages
CELLSPACING="value"
HEIGHT="height"
WIDTH="width"
COLS="numOfCols"
HSPACE-"horizMargin"
VSPACE="vertMargin"
STABLE,
> 'Table Elements
<TABLE> </TABLE> defines a table in HTML. If the BORDER
attribute is present, your browser displays the table with a border
...
<CAPTION> <ICAPTION> >defines the caption for the title of the table.
The default position of the title is centered at the top of the table. The
attributes ALIGN=BOTTOM can be used to position the caption below
the table.
<TR>...JTR>> specifies a table row within atable. You may define default
attributes for the entire row: ALIGN (LEFT, CENTER, RIGHT) and/or
VALIGN (TOP, MIDDLE, BOTTOM).
...
<TH> <STH> > defines a table header cell. By default the text in this cell is
bold and centered. Table header cells may contain other attributes to
determine the characteristics of the cell and/or its contents.
TD> TD> >defines a table data cell. By default themay text in this cell is
aligned left and centered vertically. Table data cells contain other
attributes to determine the characteristics of the cell and/or its contents.
BGCOLOR="color'"
sets the color of the background for the table. This color can be overridden by
a
BGCOLOR tag in the TH, TR, Or TD tags.
CELLPADDING="value"
determines the amount of space, in pixels, between the border of a cell and the
contents of the cell. The default is 1.
HTML
143
HEIGHT="height"
specifies the height of the table. The default is the optimal height determined
by the contents of each cell. Can be a number of pixels, or a percentage of the
height of the page or parent element.
WIDTH="width"
defines the width of the table. The default is the optimal width determined by
the contents of each cell. Can be a number of pixels, or a percentage of the
height of the page or parent element.
COLS="numberOfColumns"
Indicates how many virtual columns of equal width fit in the width of the
window. If the WIDTH attribute is supplied, the COLS attribute indicates how
many virtual columns fit in the specified width. Suppose that the WIDTH
case, each column takes
attribute is "80%" and the COLS attribute is 4. In this
up 20% of the width of the window. Note, however, that if the minimum
an actual column is greater than the
width needed to display the contents of
to fit its
width of a virtual column, then the width of the column is expanded
contents.
HSPACE-"horizontalMargin"
the table and any
Specifies the distance between the left and right edges of
surrounding content.
VSPACE="verticalMargin"
the top and bottom edges of the table and any
Specifies the distance between
surrounding content. or
<TD>... </TD>
within <THS </THS
Similarly you can define Attributes
cells as-- Horizontal alignment of a cell..
ALIGN (LEFT, CENTER, RIGHT)
(TOP, MIDDLE, BOTTOM) Vertical alignment of a cell.
VALIGN a cell spans.
COLSPAN=n The number (n) of columns
rows a cell spans.
ROWSPAN=n The number (n)of
are
Important Hint
always have end tags. Although the end tags
1. TH, TD and TR should formatting of the table if
many browsers will mess up the
formally optional, always use end tags if you
you should
you omit the end tags. In particular,
a html document.
have a TABLEwithin
HTML
144
<TD>300</TD>
STR>
<H4>A BACKGROUND IMAGE:<H4>
<TABLE BORDER="1"
BACKGROUND=".CADESKTOPXYZ.JPG">
<TR>
<TD>SUNDAY<TD>
<TD>MONDAY</TD>
<TR>
<TR>
<TD>TUESDAY</TD>
<TD>WEDNESSDAY<TD>
TR>
<TABLE>
<JBODY>
<JHTML>
output displayed by browser is:
A Background Color:
100206l306:
A Background Image:
SUNDAY MORDAN
TUESBDAYWEDNESSDAY
<JTR>
<TR>
<TD> WEDNESSDAY </TD>
<TD> THURSDAY </TD>
<TR>
<TABLE>
<BODY>
HTMLs
so output displayed by browser is:
WITHOUT CELLSPACING:
SUNDAY
MONDAY
WEDNESSDAYTHURSDAY
WITH CELL SPACING:
SUNDAY MONDAY
WEDNESSDAY THURSDAY
SUNDAY MONDAY
WEDNESSDAY THURSDAY
</BODY>
SHTML>
so output dispiayed by browser. is :-
PRGRAMMING LANGUAGE
JAVA
OBJECT ORIENTED LANGUAGE
C++
C
sTRUCTURED LANGUAGE
BASIC
Syntax
<IMG
SRC="location"
ALT="alterntiveText"
ALIGN="alignment"
BORDER="borderWidth"
HEIGHT="height"
WIDTH="width"
HSPACE="horizMargin"
VSPACE="verticalMargin"
>
The SRC attribute is compulsory
SRC="location(URL)"
specifies the URL of the image to
be displayed in the document.
HTML 149
ALT="alternativeText"
specifies text to be displayed if the browser does not support the IMG
tag or if the user has suspended image loading in the browser.
ALIGN
specifies the alignment of the image in relation to the surrounding text. If you do not
specify a value for ALIGN, browser uses BOTTOM as the default LEFT aligns
an
image with the left margin.
RIGHT aligns an image with the right margin.
TOP aligns the top of an image with the top of the tallest item in the
current
line.
text in the
TEXTTOP aligns the top of an image with the top of the tallest
current line.
text in the
MIDDLE aligns the middle of the image with the baseline of the
current line.
text in the
BASELINE aligns the bottom of an image with the baseline of the
current line.
BOTTOM is the same as BASELINE.
BORDER="borderWidth'"
image. The value must
Specifies the width, in pixels, of border around the
a
be an integer.
HEIGHT="'height"
or as a percentage of the
Specifies the height of the image, either in pixels
HTML that contains th image.
height of the window, frame, or positioned block of
value as an integer, for example, "100". To
To indicate a number of pixels specify the
a percentage, specify the value as an integer followed by the percentage sign,
indicate
for example "20%".
WIDTH='"width'"
the width of the image either in pixels or as a percentage of the
Specifies a
or positioned block of HTML containing the image. To indicate a
window, frame,
as an integer, for example, "100". To indicate
number of pixels specify the value
the value as an integer followed by the percentage sign, for
percentage, specify
Cxample, "20%".
HSPACE-"horizMargin"
a margin in pixels between the left and right edges of the image and
Specifies
value as an integer
Surrounding text and images. Give the
150
Dummy Images
an imnage that does not exist, your browser
When an <IMG SRC> tag points to your final review of
software substitutes a dummy image. When this happens during hyperlink
your files, make sure that the referenced image does in fact exist, that the
permission is set
has the correct information in the URL, and that the file
appropriately.
slow down the loading of the main document with large inline images.
To include a reference to an external image:
<A HREF-"ExtImg.gif">text or link<lA>
values in the
you can make a picture larger or smaller changing the
Ihus
HEIGHT"
and "WIDTH"
attributes of the img tag.
152 HTML
>
Image from net...
<IMG SRC="http://www.yah00.com/Logo.gif"
WIDTH="73"
HEIGHT="68">
P>
<BODY>
<HTML>
Image as a link:
You can have image as a link to some
other image or document.
<HTML>
<BODY>
Click on Icon.gif file to get your destination
document.
<A HREF="DestinationPage.htm">
<IMG BORDER"0" SRC="ICONT.GIF"
WIDTH="20" HEIGHT="38">
<JA>
<P>
Click on Logo.gif file to get
resultant image you want......
<A HREF="ResultantImage.jpg">
<IMG BORDER="0" SRC="ICONT.GIF"
WIDTH-"20" HEIGHT="38"'>
JA>
<BODY>
<HTML>
Alternate text:
Text-only browsers will only
"This is Alternative Text".(in display the text in the "alt" attribute,
this example) or Some World which is
as Lynx (text Wide Web browsers such
only browser) cannot
loading even if their software can display images. Some users turn off image
display images (especially
modem or have a slow connection). they are using a
HTML provides a mechanismifto
tell readers what
HTML
153
they are missing on your pages if they can't load images The
ALT attribute lets you
specify text to bc displayed instead of an image. Note that if you hold
the mouse
nointer over the image it will display the text called tool tip.
<HTML>
<BODYS
<IMG SRC="ICON.GIF" ALT=" This Is Alternative Text " WIDTH="30"
HEIGHT="30">
<BODY>
<<HTML>
<HTML>
<BODY
<PALIGN=CENTER>
<IMG SRC = "ICON.GIF" ALT="NOTEXT">
</P>
<BODY>
SHTML>
4.10HTML SCRIPTS
HTML pages with scripts are used to make them more dynamic and interactive.
VBScript
Microsoft Visual Basic Scripting Edition brings active seripting to a wide
variety of environments, including Web client scripting in Microsoft Internet
Service.
Explorer and Web server scripting in Microsoft Internet Information
obtain and call entry points, and manage the namespace avail able to the developer,
With Windows Script, language vendors can create standard language run times for
scripting. Microsoft willprovide run-time support for VBScript
A new browser willunderstand that the script should be executed, even comment
if
tags surTound it.
Seript Tags:
<SCRIPT> Defines A Script
<NOSCRIPT> :- Defines An Alternate Text If The Script Is Not Executed
<OBJECTS Defines An Embedded Object
<PARAM> Defines Run-Time Setings (Parameters) For An Object
<APPLET> Deprecated. Use <object>
Most of your code will appear in either Sub or Function procedures and
witt
be called only when specified by your code. However, you can write VBScript code
outside procedures, but still within a SCRIPT block. This code is executed only once,
when the HTML page loads. This allows you to initialize data or dynamically change
the look of your Web page when it loads.
SOLVED EXAMPLES
1) Write HTMLcode to display a Message using different Font attributes.
<HTML>
<HEAD>
TITLE> HTML Document <TITLE>
</HEAD>
<BODY><FONT SIZE="7" face="Comic Sans MS">This is font size 7 with comic
sans ms font</FONT>
<p><FONT SIZE="5"COLOR="red">This is red colored text with font size
5</FONT><p>
<BODY>
<SHTML>
Output is:
eHTML Document Microsoft Internet Explorer
Eile Edit View Favorites Iools Help
Bedk Fovard Stop Refresh Home Seach Favates History Mal Prnt Discuss
Output is:
Headings Microsoft Internet Explorer
Elle Edit Vew Favorites Iools Help
Faspd Stop
Retesh Home SearchFavontes History Mal Pint Ed Discuss
Address DAONinehin! fleslheadngs.hl
GoLinks
Output is:
lists- Microsoft Internet Explorer
Eile Edit View Favorites Iools Help
Address ] DAONine nm
htnd
lies\ists.htm EGoLinks
Sanple of Unordered lists
ELLO
HIML
HYPER TEXT MARKUP LANGUAGE
URL
UNIFORM RESOURCE LOCATOR
wy Computei
Done
(March 2002)
4) Write HTML code for the following:
YEAR
19981999 2000
UNITS 400 |1000
500
SALES
INCOME|1000|800 2000
<HTMLs
<BODY>
<TABLE BORDER>
<TR> COLSPAN="2">
<TH ROWSPAN="2"
COLSPAN="3">YEAR
<TH
<TR>
<TH>1998
<TH>1999
<TH>2000
STR>
<TR> ROWSPAN="2">SALES
<TH
<TH>UNITS
<TD>500
<TD>400
160 HTML
<TD>1000
<TR>
<TR>
<TH>INCOME
<TD>1000
<TD>800
<TD>2000
<STR>
<TABLE>
</BODY>
</HTML>
A. Microprocessor Programming
B. Networking Essentials
C. Micro Controllers
HTML
161
QUESTIONS
Select the correct alternatives:
1) The tag contains general information,or meta-information,
about the documnent.
a) <HEAD> b) <MARQUEE> c) <TITLE> d)<BODY>
2) The block-level elements contain
tag.
a) <PRE> b)<BODY> c) <MARQUEE> d)<HTML>
Admission data.
Streams capacity
Commerce 150
Science 100
Arts 100
Here Admission data. Should be the scrolling text.
Collge Name:S.P.College should be in bold, italics and in red color.
It should be hyper linked with th page containing college information.
4,
Write HTML COde for following.:-..
Collge Name:Cummins College Of Engg.
CCOEW
as: CCOEW
Where image LOGO.JPG" is shown
Todays Special;--
With toppings Rs.150.
PIZZA Rs.125.
Without toppings
(Domino's) Rs.40.
Mashroom PavBhaji
Cheese PavBhaji Rs.42. (WithButter) Rs.40.
PavBhaji Jain PavBhaji Rs.40.
(Mar.2004)
Write the HTML code for the
following table:
Year
2000 2001
1999
750 1,200
300
Units Rs. 12,0J0
Sales Rs. 3,000 Rs. 7,500
Income
164 HTML
Faculty
8. Write the exact output of the following HTML code with font spcification in
brackets: (Mar.2006)
<HTML>
<TITLE> Introduction </TITLE>
<BODY>
<H> <B> Computer Science </B></H1>
<HR>
<U> EBalaguru Samy </U>
<iHR>
<IA> Achut S Godbole </H4>
<BODY>
SHTML>
9. Write the HTML code for the following table.
(Mar.2008)
Year
2000 2001 2002
Units 500 1000 1500
Sale
Income Rs. 5,000
Rs. 10,000 Rs. 15,000
Answers Q. (1)
1) <HEAD>, 2) <BODY>, 3) VLINK, 4) HSPACE, 5)
UNORDERED,
6)BACKGROUND, 7) HREF,8) Uniform Resource Locator,
9) <UL> 10))<BR> 11) < SRC >12) <BR> 13) HREF
14)<TABLE> 15) <tr>
O00