Ip Chapter 2 HTML
Ip Chapter 2 HTML
HTML
As a web designer, you spend a lot of time creating pages and change them until they
look good in your browser. Before you grow too attached to the way your page looks on
your screen, you should know that it is likely to look different to other people. That’s just
the nature of web design—you can’t guarantee that everyone will see your page the way
you do. The way your site looks and performs is at the mercy of a number of variables
such as browser version, platform, monitor size, and the preferences or special needs of
each individual user. Your page may also be viewed on a mobile device like a cell phone,
or using an assistive device like a screen magnifier or a screen reader.
Browser Versions
One of the biggest challenges in designing for the Web is dealing with the
different browsers
In the past browsers were so incompatible that web authors were forced to
create two separate sites, one for Internet Explorer and one for Netscape.
Things have improved dramatically now that browsers have better support for
web standards established by the World Wide Web Consortium (W3C for short).
After we see a general overview of the web design environment,now it’s time to roll up
our sleeves and start creating a real web page. It will be a simple page, but even the most
complicated pages are based on the principles described here.
Step 1: Start with content. We add raw text content and see what browsers do with it.
Step 2: Give the document structure. We learn about HTML elements and its structure.
Step 3: Identify text elements. You’ll describe the content using the appropriate text
elements and learn about the proper way to use HTML.
Step 4: Add an image. By adding an image to the page, we will learn about attributes.
Step 5: Change the look with a style sheet. We learn formatting content with CSS.
Page 1
Step1. Start with Content
It is important that you follow these rules and conventions when naming your files:
Use proper suffixes for your files._ HTML files must end with .html (some servers
allow .htm). Web graphics must be labeled according to their file format: .gif or .jpg
(.jpeg is also acceptable).
Never use character spaces within filenames. It is common to use an underline
character or dash to visually separate words within filenames, such as robbins_bio.
html or robbins-bio.html.
Avoid special characters such as?, %, #, /, :, ;, •, etc. Limit filenames to letters,
numbers, underscores, hyphens, and periods.
Filenames may be case-sensitive, depending on your server configuration.
Consistently using all lowercase letters in filenames, while not necessary, makes your
filenames easier to manage.
Keep filenames short. Short names keep the character count and file size of your
HTML file in check. If you really must give the file a long, multiword name, you can
separate words with capital letters, such as ALongDocumentTitle.html, or with
underscores, such as a_long_document_title.html, to improve readability. Self-
imposed conventions. It is helpful to develop a consistent naming scheme for huge
sites. For instance, always using lowercase with underscores between words. This
takes some of the guesswork out of remembering what you named a file when you go
to link to it later.
Some information in the source document will be ignored when it is viewed in a browser,
including:
Line breaks (carriage returns)_. Line breaks are ignored. Text and elements will wrap
continuously until a new block element, such as a heading (h1) or paragraph (p), or
the line break (br) element is encountered in the flow of the document text.
Tabs and multiple spaces_. When a browser encounters a tab or more than one
consecutive blank character space, it displays a single space. So if the document
contains: long, long ago the browser displays: long, long ago
Page 2
Unrecognized markup_. A browser simply ignores any tag it doesn’t understand or
that was incorrectly specified. Depending on the element and the browser, this can
have varied results. The browser may display nothing at all, or it may display the
contents of the tag as though it were normal text.
Text in comments_. Browsers will not display text between the special <!--and --
>tags used to denote a comment. See the HTML Comments sidebar.
HTML Comments
You can leave notes in the source document for yourself and others by marking them up
as comments. Anything you put between comment tags (<!-- -->) will not display in the
browser and will not have any effect on the rest of the source.
Elements are identified by tags in the text source. A tag consists of the element name
(usually an abbreviation of a longer descriptive name) within angle brackets (<>). The
browser knows that any text within brackets is hidden and not displayed in the browser
window.
The element name appears in the opening tag (also called a start tag) and again in the
closing (or end) tag preceded by a slash (/). Be careful not to use the similar backslash
character in end tags.
The tags added around content are referred to as the markup. It is important to note that
an element consists of both the content and its markup (the start and end tags). Not all
Page 3
elements have content, however. Some are empty by definition, such as the imgelement
used to add an image to the page.
Introducing...semantic markup
It is not intended to provide instructions for how the content should look (its
presentation).
Your job when marking up content is to choose the (X) HTML element that provides
the most meaningful description of the content at hand. That is semantic markup
we’ll add an image to the page using the img element <img>
Empty elements: are do not have text content because they are used to provide a simple
directive. E.g.image element (img), line break (br),horizontal rule (hr).
Attributes are instructions that clarify or modify an element. For the img element, the src
(short for “source”) attribute is required, and provides the location of the image file via its
URL.The syntax for attributes is as follows:
2. Basics of HTML
Page 4
HTML elements form the building blocks of all websites. HTML allows images and
objects to be embedded and can be used to create interactive forms. It provides a means to
create structured documents by denoting structural semantics for text such as headings,
paragraphs, lists, links, quotes and other items. It can embed scripts in languages such
as JavaScript which affect the behavior of HTML webpage. HTML can also be used to
include Cascading Style Sheets (CSS) to define the appearance and layout of text.
While a web developer, someone like you, uses the HTML tags to create the web page,
software is required to interpret your code and display the information that you are trying
to display: the software could be any web browser software. The purpose of a web
browser is to read HTML documents and display them as web pages. The browser does
not display the HTML tags, but uses the tags to interpret the content of the page.
World Wide Web Consortium (W3C) is the organization that develops guidelines and
specifications for many web technologies including HTML. The W3C website is found
atwww.w3.org.
HTML document is created using a simple text editor like notepad or any other text
editor. Notepad can edit HTML, and at the same time you are able to view what you edit,
in a web browser.
<html>
<head>
<title>Page title here </title>
</head>
<body>
Our body content here
</body>
</html>
Page 5
The total code is divided into two parts and both the parts are kept inside <html> tags.
Our page should start with <html> and should end with </html>. The first part inside this
html tags is the head and it starts with <head> and ends with </head>. The second part
starts with <body> and ends with </body> tag. Inside the <body> tag we keep all our
content which we want to display to our web page users. Whatever we place in <body>
will be displayed by the browser to the web users. Inside the root element the document is
divided in to two.
The <head> element, which contains information about the document such as a title
or a link to a style sheet
The <body> element, which contains the real content of the document that you see.
<HEAD> </HEAD>
The web page should have only one head tag. The head tag starts with <head> and ends
with </head>. The text or tags that are inside the head tag will not be displayed in the
browser window. Inside this tag we keep all the meta keyword tags used for search
engines.
One of the important tags which is put inside <head> is <title></title> tag. Title tags are
used to give title to the browser window and it displayed at the top left side of the
window. Title tags are also important for our search engine point of view. We should
keep most important keywords inside the title tag.
Page 6
Example:
<html><head><title>First Example</title></head>
<body>
Here is the first example for Internet Programming
</body></html>
It is also possible to put JavaScript code and Cascading Style Sheets in head section. If
we are adding any JavaScript code here then that will be loaded when the browser opens
the page.
You should specify a title for every page that you write inside the <title> element. This
element is a child of the <head> element. It is used in several ways:
<head>
<title>HTML Basic tags</title>
</head>
Page 7
The<BODY> Element
This is where we will place our content for our visitors. What we place here will be
displayed to our visitors. A <body> element may contain anything from a couple of
paragraphs under a heading to more complicated layouts containing forms and tables.
<element attribute-name="value">Content</element>
Example: the background color of HTML document can be changed using “bgcolor”
attribute of the <body> tag.
<html> attribute
SettingHTML Language
The HTML lang attribute can be used to declare the language of a Web page or a portion
of a Web page. This is meant to assist search engines and browsers.
According to the W3C recommendation you should declare the primary language for each
Web page with the lang attribute inside the <html> tag, like this:
<html lang="en">
…
</html>
Page 8
ISO 639-1 defines abbreviations for languages. In HTML, they can be used in the lang
attributes.
<body> Attributes
Background Color
You can change background color of your web page by using <BODY> tag attribute
bgcolor
<body bgcolor=”green”>
Color can be specified using color name or RGB value. The following also sets
background color to green:
<body bgcolor=”#00FF00”>
Background Image
We can use a background picture for web page instead of background color. You must
have an image to do this. Then you can use background attribute of <BODY> tag as
follows:
<body background="image1.gif">
Page 9
Text Color
We can also set the text color of the web page just like background color. We use text
attribute of <body> to do this.
Example:
Example:
Page 10
<body alink="blue" link="red" vlink="green">
<a href="first.html">first page</a><br>
<a href="second.html"> second page</a><br>
<a href="third.html">third page</a><br>
<a href="last.html">last page</a><br>
</body></html>
Creating Links
A hyperlink (or link) is a word, group of words, or image that you can click on to jump to
a new document or a new section within the current document. Web pages can contain
links that take you directly to other pages or specific parts of the given page. These links
are known as hyperlinks. Hyperlinks allow visitors to navigate between Web sites by
clicking on words, phrases, and images. Thus you can create hyperlinks using text or
images available on your web page.
Links are specified in HTML using the <a> tag.A link is specified using the <a> element.
This element is called anchor tagas well. Anything between the opening <a> tag and the
closing </a> tag becomes part of the link and a user can click that part to reach to the
linked document.
The <a> tag can be used to create a link to another document, by using the href attribute
The href Attribute: A link in HTML is always composed of two parts, the clickable part
(the link text) and the URL (the destination site, page or resource). The URL is specified
using href attribute. Here is an example:
It is used to specify where to display the contents of a selected hyperlink. If set to:
_blank then a new window will be opened to display the loaded page
_self then loads the new page in current window. By default its _self.
Page 11
Example: a link that opens on a new window
The title attribute is used to type a short description of the link. If you place the cursor
over the link, you will see the text in the title attribute.
Example:
Linking to email
It is also possible to make a link to an e-mail address. It is done in almost the same way as
when you link to a document. The only difference between a link to an e-mail and a link
to a file is that instead of typing the address of a document, you type mailto: followed by
an e-mail address.
Example:
When the link is clicked, the default e-mail program opens with a new blank message
addressed to the specified e-mail address. Remember that this function will only work if
there is an e-mail program installed on your computer.
HTML Comments
Comments are piece of code which is ignored by any web browser. It is good practice to
comment your code, especially in complex documents, to indicate sections of a
document, and any other notes to anyone looking at the code. Comments help you and
others understand your code.
HTML Comment lines are indicated by the special beginning tag <!-- and ending tag -->
placed at the beginning and end of every line to be treated as a comment. You can
comment multiple lines by the special beginning tag <! --and ending tag --> placed before
the first line and end of the last line to be treated as a comment.
Page 12
For example: Given line is a valid comment in HTML
For example:
Red = #FF0000
Green = #00FF00
Blue = #0000FF
Cyan (blue and green) = #00FFFF
Magenta (red and blue) = #FF00FF
Yellow (red and green) = #FFFF00
Both <body bgcolor=”red”> and <body bgcolor=”#FF0000”> will change the
background color in to red.
There are options if one wants to create a text in HTML. Let’s see some of the tags that
can be used to create text information.
HTML Headings
In HTML, you can create different heading levels in your document to help you organize
the document into sections, just as you might do when writing a book. A heading element
briefly describes the topic of the section it introduces. Headings are defined with the <h1>
to <h6> tags. <h1> defines the largest heading and <h6> the smallest heading.
Example:
Page 13
<body>
<h1>this is heading level 1. </h1><h2>this is heading level 2.</h2>
<h3>this is heading level 3. </h3><h4>this is heading level 4. </h4>
<h5>this is heading level 5. </h5><h6>this is heading level 6. </h6>
</body>
Heading tags are block tags, and you must specify opening and closing tags.
HTML Paragraphs
Authors traditionally divide their thoughts and arguments into sequences of paragraphs.
Along with using headings to structure your Web page, you can add structure by grouping
common text into paragraphs.Paragraphs are defined with the <p> tag.
Example:
<p>This is a paragraph</p>
Both of the above tags will enforce a new line whenever you write the tag. The <p>
element is a block element.
Page 14
The align attribute
You can use align attribute to align your paragraphs. Paragraphs can be left aligned,
center aligned, right aligned or justified. You can do this by using align attribute. Align
attribute can be used with other tags like headers, table, etc.
Example:
<html><body>
<h1 align="left"> Heading Aligned Left </h1>
<h2 align="center"> Heading Aligned Center </h2>
<h3 align="right"> Heading Aligned right</h3>
<h3 align="justify"> Heading Aligned Justify</h3>
</body></html>
HTML Fonts
The <font> tag is used to add font type, size, and color to the text on your site. The font
tag is has three attributes called size, color, and face to customize your fonts. To change
any of the font attributes at any time within your page, simply use the <font> tag. The text
that follows will remain changed until you close with the </font> tag. You can change
any or all of the font attributes at the one time, by including all the required changes
within the one <font> tag.
Font Size:
You can set the size of your font with size attribute. The range of accepted values is from
1(smallest) to 7(largest). The default size of a font is 3.
Example:
Page 15
Fig Font size
You can also specify relative font sizes instead of exact font size. This can be done like:
<font size="+n">
<font size="-n">
This specifies how many sizes larger or how many sizes smaller than the preset font size
should be.
Font Face:
You can set any font you like using face attribute but be aware that if the user viewing the
page doesn't have the font installed, they will not be able to see it. Instead they will
default to Times New Roman of your font with size attribute.
Example:
Page 16
Font Color:
You can set any font color you like using color attribute. You can specify the color that
you want by either the color name or hexadecimal code for that color.
Example:
Formatting Tags
In HTML, there are many tags that you can use to enhance and change the look of the
text. You can make text bold, italicized, or underlined.
Anything that appears in a <b>...</b> element is displayed in bold. The <b> tag makes
text to be displayed in bold face.
Example:
<p>The use nuclear energy needs <b> safety caution </b> because of the associated
danger.</p>
The use nuclear energy needs safety caution because of the associated danger.
Example:
Page 17
Anything that appears in a <u>...</u> element is displayed with underline.
Example:
Example
You can use <center> tag to put any content in the center of the page or any table cell.
Example:
The <br> tag inserts a single line break. You can also use <br /> which does the same.
Whenever you use the <br> element, anything following it starts on a new line. This tag
is an example of an emptyelement, where you do not need opening and closing tags, as
there is nothing to go in between them.
The <br /> element has a space between the characters br and the forward slash. If you
omit this space, older browsers will have trouble rendering the line break.
Example
Page 18
Hello<br />
You come most carefully upon your hour.<br>
Thanks<br />
Markan
This will produce following result:
Hello
You come most carefully upon your hour.
Thanks
Markan
Preserve Formatting - The <pre> Element:
Sometimes you want your text to follow the exact format of how it is written in the
HTML document. In those cases, you can use the preformatted tag (<pre>). The <pre>
tag defines preformatted text. Text in a pre-element is displayed in a fixed-width font
(usually Courier), and it preserves both spaces and line breaks.
Example:
<pre>
functiontestFunction( int a, int b ){
int sum = a + b;
alert (sum);
return;
}
</pre>
This produces the following output:
Page 19
Horizontal Rules - The <hr> Element
<hr> stands horizontal rules are used to visually break up sections of a document. The
<hr> tag creates a horizontal line in an HTML page. The hr element can be used to
separate content in an HTML page.
For example you may want to give a line between two paragraphs as follows:
The <sub> tag defines subscript text. Subscript text appears half a character below the
baseline. Subscript text can be used for chemical formulas, like H2O.
The <sup> tag defines superscript text. Superscript text appears half a character above the
baseline. Superscript text can be used for mathematical expressions like 5X2+6X+10.
Example:
<p>The chemical formula for water is H<sub>2</sub>O </p>
<p>Solve 5X<sup>2</sup>+6X+10 </p>
The <big> tag displays texts in big. The content of the <big> element is displayed one
font size larger than the rest of the text surrounding it.
The <small> tag renders a smaller text. The content of the <small> element is displayed
one font size smaller than the rest of the text surrounding it.
Page 20
Example:
<p>The following word uses a <small>small</small> typeface.</p>
<p>The following word uses a <big>big</big> typeface.</p>
bdo stands for bidirectional override. The <bdo> tag allows you to specify the text
direction and override the bidirectional algorithm. This is especially useful for languages
like Hebrew and Arabic where text is written from right to left.
Example:
Special Characters
Characters within HTML documents that are not part of a tag are rendered as-is by the
browser. However, some characters have special meaning and are not directly rendered,
while other characters can't be typed into the source document from a conventional
keyboard. Special characters need either a special name or a numeric character encoding
for inclusion in an HTML document.
Page 21
¦ ¦ ¦ broken vertical bar
§ § § Section
¨ ¨ ¨ spacing diaeresis
© © © Copyright
ª ª ª feminine ordinal indicator
« « « angle quotation mark (left)
¬ ¬ ¬ Negation
® ® ® registered trademark
¯ ¯ ¯ spacing macron
° ° ° Degree
± ± ± plus-or-minus
² ² ² superscript 2
³ ³ ³ superscript 3
´ ´ ´ spacing acute
µ µ µ Micro
¶ ¶ ¶ Paragraph
· · · middle dot
¸ ¸ ¸ spacing cedilla
¹ ¹ ¹ superscript 1
º º º masculine ordinal indicator
» » » angle quotation mark (right)
¼ ¼ ¼ fraction ¼
½ ½ ½ fraction ½
¾ ¾ ¾ fraction ¾
¿ ¿ ¿ inverted question mark
× × × Multiplication
÷ ÷ ÷ Division
Page 22
The required alt attribute specifies an alternate text for an image, if the image cannot be
displayed. The alt attribute provides alternative information for an image if a user for
some reason cannot view it (because of slow connection, an error in the src attribute).
Example:
<imgsrc="boat.gif" alt="Big Boat" />
The width and height attributes
To define the height and width of the image, rather than letting the browser compute the
size, use the height and width attributes.
The attributes:
width: sets width of the image. This can have a value like 10 (pixels) or 20%
(percentage of the available window size) etc.
height: sets height of the image. This can have a value like 10(pixels) or 20%
(percentage of the available window size) etc.
Example:
The border attribute sets a border around the image. This will have a value like 1 or 2 etc.
The align attribute sets horizontal alignment of the image and takes value either left, right
or center.
Example:
<imgsrc="coffee.png" alt="Highland coffee" width="100" height="100" border="2"
align="right" title="HTML Tutorial" />
Page 23
Fig Image insertion
The valign attribute sets vertical alignment of the image and takes value top, bottom or
center.
hspace: sets horizontal space around the image. This will have a value like 10 or 20%
etc.
vspace: sets vertical space around the image. This will have a value like 10 or 20%
etc.
The title attribute specifies a text title. The browser displays the title when the mouse
passes over the link.
Example:
<html><head><title>Testing HTML</title></head>
<body>
Just checking img tag.
<imgsrc="coffee.png" alt="Highland coffee" align="left" hspace="50" vspace="100" />
</body></html>
Page 24
5. Tables in HTML
Creating Tables
Tables are defined with the <table> tag. A table is divided into rows with the <tr> tag, and each
row is divided into data cells with the <td> tag. td stands for "table data," and holds the content of
a data cell. A <td> tag can contain text, links, images, lists, forms, other tables, etc.
Table headers
Headers in a table are defined with the <th> tag. The text in a <th> element will be bold and
centered.
Example:
<table border="1">
<tr>
<th>Header 1</th><th>Header 2</th>
</tr>
<tr>
<td>row 1, cell 1</td><td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td><td>row 2, cell 2</td>
</tr>
</table>
If you do not specify a border attribute, the table will be displayed without borders.
Sometimes this can be useful, but most of the time, we want the borders to show.
Attributes of table:
The attributes of a table will be applied on the whole table element which include one or
more rows (<tr>), header cells (<th>) or data cells (<td>).
Page 25
Table 3 attributes of table
Example:
Page 26
<tr><td colspan="3">Row 3 Cell 1</td></tr>
</table>
This produces the following output:
There are two attribiutes called cellpadding and cellspacing which you will use to adjust
the white space in your table cell. Cellspacing defines the width of the border, while
cellpadding represents the distance between cell borders and the content within.
Example:
<tr><th>Name</th><th>Salary</th></tr>
<tr><td>Ramesh Raman</td><td>5000</td></tr>
<tr><td>Shabbir Hussein</td><td>7000</td></tr></table>
Fig Table with cellpadding 15 and cellspacing 10 and table with no values set
Attributes of rows and cells: this attributes will be applicable only to the header cell or
the data cell if it is used with <th> or <td> tag while it will affect the whole content of the
row if it is used by the <tr> tag.
Page 27
Table 2.2 attributes of rows and cells
It’s sometimes necessary for data to span multiple rows or columns. This is achieved via
the rowspan and colspan attributes, respectively.
Page 28
Vertical alignment of cell content
If you set your table’s width to a small value, or if you have a lot of content in one cell
and relatively little in an adjacent one, something else becomes apparent: web browsers
vertically align content in the middle of cells.
You can use the valign attribute to set where the text is displayed vertically. The attribute
can be added to a row or cell start tag, and set to the desired value.
Tables can be divided into three portions: a header, a body, and a foot. The head and foot
are rather similar to headers and footers in a word-processed document that remain the
same for every page, while the body is the main content of the table.
The three elements for separating the head, body, and foot of a table are:
Example:
Page 29
<tbody><tr><td>Cell 1</td><td>Cell 2</td><td>Cell 3</td></tr>
Practice 2.1
1. Create a table that displays an exam schedule for your department?
Unordered List
An unordered list starts with the <ul> tag. Each list item starts with the <li> tag.
The list items are marked with bullets (typically small black circles). The “type” attribute
can be used to specifies the style of the bullet points of the list items, its value includes
disc, square and circle.
Example:
<ul>
<li>Banana</li>
<li>Orange</li>
</ul>
Banana
Orange
Page 30
<ul> attributes:
Type disc Specifies the style of the bullet points of the list
items
square
circle
Ordered List
An ordered list starts with the <ol> tag. Each list item starts with the <li> tag. The list
items are marked with numbers.
Example:
<ol>
<li>Banana</li>
<li>Orange</li>
<li>Apple</li>
</ol>
How the HTML code above looks in a browser:
1. Banana
2. Orange
3. Apple
If you want a numbered list to start at a number other than “1,” you can use the start
attribute to specify another starting number.
Example
<ol start="17">
Page 31
<li>Select the Character tab.</li>
The resulting list items would be numbered 17, 18, and 19, consecutively.
Start number Specifies the start point for the list items
Example:
<ol type=”I”>
<li>Banana</li>
<li>Orange</li>
<li>Apple</li>
</ol>
I. Banana
II. Orange
III. Apple
Page 32
Nesting Lists
Example:
<ol>Types of Computer:
<li>Super computer</li>
<li>Mainframe computer</li>
<li>Mini computer</li>
<li>Micro computer</li>
<ul><li>Desktop computer</li>
<li>Laptop Computer</li>
<li>Palmtop computer</li></ul></ol>
HTML also supports description lists. A description list is a list of terms, with a
description of each term.The <dl> tag defines the description list, the <dt> tag defines the
term (name), and the <dd> tag describes each term:
<dl>
<dt>Coffee</dt> <dd>- black hot drink</dd>
<dt>Milk</dt> <dd>- white cold drink</dd>
</dl>
Page 33
HTML Block and Inline Elements
Every HTML element has a default display value depending on what type of element it is.
The default display value for most elements is block or inline.
Block-level Elements
A block-level element always starts on a new line and takes up the full width available
(stretches out to the left and right as far as it can).The <div> element is a block-level
element.
Example<div>Hello</div<div>World</div>
Inline Elements
An inline element does not start on a new line and only takes up as much width as
necessary.
Example
<span>Hello</span>
<span>World</span>
Practice 2.2
Page 34
1. Write a code that displays the courses that you are currently taking (use unordered
list)?
2. Write a code that displays your favorite books in order list?
When a frameset page is loaded, the browser automatically loads each of the pages
associated with the frames. Each HTML document is called a frame, and each frame is
independent of the others.
In the example below we have a frameset with two columns. The first column is set to
25% of the width of the browser window. The second column is set to 75% of the width
of the browser window. The document "frame_a.htm" is put into the first column, and the
document "frame_b.htm" is put into the second column:
Page 35
Note:
The frameset column size can also be set in pixels (cols="200,500"), and one of the
columns can be set to use the remaining space, with an asterisk (cols="25%,*").
You cannot use the body element together with the frameset element. However, if you
add a <noframes> tag containing some text for browsers that do not support frames,
you will have to enclose the text in a body element.
Attributes of frameset
Example:
<frameset cols="30%,*">
<frame src="frame-one.html" /><frame src="frame-two.html" />
</frameset>
This produces the following output:
Fig Frameset
Attributes of frame
Page 36
Scrolling Yes Specifies whether or not to display scrollbars in a
frame
no
auto
Src URL Specifies the URL of the document to show in a frame
You can also nest framesets, to create a combination of columns and rows:
<frameset rows="120,*">
<frame noresize=”noresize” src="frame-one.html">
<frameset cols="150,*">
<frame src="frame-two.html">
<frame src="frame-three.html">
</frameset>
</frameset>
Practice 2.3
Page 37
Nested Frames
Framesets may be nested to any level. In the following example, the
outer FRAMESET divides the available space into three equal columns. The
inner FRAMESET then divides the second area into two rows of unequal height.
Example:
7. Forms in HTML
HTML forms are used to pass data to a server. Users generally "fill" a form by modifying
its controls (entering text, selecting list items, etc.) before submitting the form for further
processing by server (e.g., to a Web server, to a mail server, etc.). Forms are a vital tool
for the webmaster to receive information from the web surfer, such as: their name, email
Page 38
address, credit card, etc. A form will take input from the viewer and depending on your
needs; you may store that data into a file, place an order, gather user statistics, register the
person to your web forum, or maybe subscribe them to your weekly newsletter.
A form will take input from the site visitor and then will post to your back-end
application such as CGI, ASP, PHP script etc. Then your back-end application will do
required processing on that data in whatever way you like.
<form>
input elements
</form>
The most important element inside form element is the input element. The input element
is used to accept user information. An input element can vary in many ways, depending
on the type attribute. An input element can be of type text field, checkbox, password,
radio button, submit button, and more. The most used input types are described in the
next subsections.
Text Field
<input type="text">
This defines a one-line input field that a user can enter text into.
Text fields have two important attributes: name and value. The name attribute gives name
to the text field for identification purpose and to make it easily accessible. The value
attributes sets content of the text field.
<form>
First name: <input type="text" name="firstname" /><br />
Last name: <input type="text" name="lastname" />
</form>
Page 39
How the HTML code above looks in a browser:
Selam
First name:
Tola
Last name:
name: The name attribute is required for identifying the input field name.
value : The value attribute specifies default text that appears in the field when the
form is loaded. When you reset a form, it returns to this value.
size: By default, browsers display a text-entry box that is 20 characters wide, but you
can change the number of characters using the size attribute.
maxlength: By default, users can type an unlimited number of characters in a text
field regardless of its size. You can set a maximum character limit using the
maxlength attribute if the forms processing program you are using requires it.
Example:
Practice 2.4
1. Create a web page that has a form for course registration; use your registration slip as
a guide.
2. Create a web page that has a form for signing in to an email.
Password
A password field works just like a text entry field, except the characters are obscured
from view using asterisk (*) or bullet (•) characters, or another character determined by
the browser.
Page 40
<form>
Password: <input type="password" name="pwd">
</form>
*********
Password:
Text Area
At times, you may want your users to be able enter multiple line of text. For these
instances, use the <textarea> element that is replaced by a multi-line, scrollable text entry
box when displayed by the browser.
Example:
<textarea name="comment"> Tell us what you feel about our tutorial with 50 words or
less. </textarea>
Example:
<textarea name="comment" rows="5" cols="100"> Tell us what you feel about our
tutorial with 50 words or less. </textarea>
Page 41
Fig Text field and text area
Radio Buttons
Radio buttons are a popular form of interaction. You may have seen them on quizzes,
questionnaires, and other web sites that give the user a multiple choice question. Below
are a couple attributes you should know that relate to the radio button.
value: specifies what will be sent if the user chooses this radio button. Only one value will be
sent for a given group of radio buttons.
name: defines which set of radio buttons that it is a part of.
<input type="radio"> defines a radio button. Radio buttons let a user select ONLY ONE
of a limited number of choices:
<form>
<input type="radio" name="sex" value="male" /> Male<br />
<input type="radio" name="sex" value="female" /> Female
</form>
Page 42
Radio button attributes are:
Example:
</form>
Practice 2.5
1. Create a web page that let students choose their department; use the list of department
in your faculty as a guideline.
2. Use a checkbox to create a web page that will enable students to select a subjects they
enjoy most (more than one selection is possible).
Checkboxes
Check boxes allow for multiple items to be selected for a certain group of choices. The
check box's name and value attributes behave the same as a radio button.
<input type="checkbox" /> defines a checkbox. Checkboxes let a user select ONE or
MORE options of a limited number of choices.
<form>
<input type="checkbox" name="vehicle" value="Bike" /> I have a bike<br />
Page 43
<input type="checkbox" name="vehicle" value="Car" /> I have a car
</form>
Example:
What type of food do you like?
<ul>
<li><input type="checkbox" name="genre" value=" spaghetti " checked="checked">
Spaghetti</li>
<li><input type="checkbox" name="genre" value="pizza" checked="checked">
Pizza</li>
<li><input type="checkbox" name="genre" value="sandwich">Sandwich </li>
<li><input type="checkbox" name="genre" value="Burger">Burger</li>
</ul>
This produces the following output
Selection lists
Drop down menus are created with the <select> and <option> tags. <select> is the list
itself and each <option> is an available choice for the user.
Page 44
<option>Choose One</option>
<option>Some High School</option>
<option>High School Degree</option>
<option>Some College</option>
<option>Bachelor's Degree</option>
<option>Doctorate</option>
</select>
This produces the following output
Attributes of select
Attribute of option
Page 45
Scrolling Lists
To make the menu display as a scrolling list, simply specify the number of lines you’d
like to be visible using the size attribute.
Example:
Page 46
<option>vanilla</option>
<option>chocolate</option>
</optgroup>
<optgroup label="fancy">
<option>Super praline</option>
<option>Nut surprise</option>
<option>Candy corn</option>
</optgroup>
</select>
Button
There are a number of different kinds of buttons that can be added to web forms. Some
are: submit button, reset button, and client side button.
Submit Button
When clicked, the submit button immediately sends the collected data in the form to the
server for processing.
<input type="submit">
Example:
Page 47
<input type=”submit” name=”info” value=”Send”>
Reset Button
The reset button returns the form controls to the state they were in when the form loaded.
This clears the text users typed into text fields, and removes selections made.
<input type="reset">
Image Button
This type of inputcontrol allows you to replace the submit button with an image of your
choice. The image will appear flat, not like a 3-D button.
<input type="image">
Example:
The button element is a flexible element for creating custom buttons similar to those
created with the input element. The content of the button element (text and/or images) is
what gets displayed on the button. In this example, a button element is used as a submit
button. The button includes a label and a small image.
Page 48
<imgsrc="thumbs-up.gif" alt=""> Ready to go.
</button>
Web forms can collect more than just data. They can also be used to transmit external
documents from a user’s hard drive. For example, a printing company could use a web
form to receive artwork for a business card order. A magazine could use a form on their
site to collect digital photos for a photo contest.
The file selection control makes it possible for users to select a document from the hard
drive to be submitted with the form data. It is added to the form using our old friend the
input element with its type set to file.
Example:
<input type="file">
The browser displays a “file” input as a text field with a button that allows the user to
navigate the hard drive and select the file for upload.
Example:
It is important to note that when a form contains a file selection input element, you must
specify the encoding type (enctype) of the form as multipart/form-data and use the
POST method.
Example:
</form>
Page 49
Example: a form that combines the above input fields
<html><head><title>Form Elements</title></head><body>
<form name="test" method="post">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
Sex: <input type="radio" name="sex" value="male" checked> Male
<input type="radio" name="sex" value="female"> Female <br>
Educational level: <br>
<select name="education" size="6">
<option>Primary School</option>
<option>Secondary School</option>
<option>College Diploma</option>
<option>First Degree</option>
<option>Masters Degree</option>
<option>PhD</option></select><br>
Which fields are you interested in? <br>
<input type="checkbox" name="" value="Electronics"> Electronics <br>
<input type="checkbox" name="" value="Software Engineering"> Software Engineering
<br>
<input type="checkbox" name="" value="Computer Engineering"> Computer
Engineering <br>
<input type="checkbox" name="" value="Networking"> Networking <br><br>
Tell us what you feel about our tutorial with 50 words or less. <br>
<textarea name="comment" rows="10" cols="50"></textarea><br>
<input type="submit" name="submit">
</form></body></html>
Page 50
Fig Example form with input fields
<html>
<head>
<title> forms</title>
</head>
<body>
value="Aster"><br />
Page 51
size="8" maxlength="12" /><br>
<br>
<br><br>
Radio Button<br>
Checkbox<br>
I have a car
<ul>
value="sandwich">Sandwich </li>
value="Burger">Burger</li></ul>
Selection List<br>
<option>Choose One</option>
<option>Some College</option>
Page 52
<option>Bachelor's Degree</option>
<option>Doctorate</option>
</select><br><br>
Scrolling List<br>
<option>Orange</option>
<option>Apple</option>
<option selected="selected">Banana</option>
<option selected="selected">Mango</option>
<option> Avocado</option>
<option>Pineapple</option>
<option>Papaya</option>
<option>Strawberry</option>
</select><br><br>
Grouping<br>
<optgroup label="traditional">
<option>vanilla</option>
<option>chocolate</option>
</optgroup>
<optgroup label="fancy">
<option>Super praline</option>
<option>Nut surprise</option>
<option>Candy corn</option>
</optgroup></select><br><br>
width="320" height="250"
Page 53
CONTROLLER="false" loop="false" name="IBM Video">
</embed>
width="320" height="250"
</embed></form></body></html>
Page 54
1.1 Linking HTML Forms with PHP Scripts
To create a link between PHP scripts and HTML forms, we need to use the functionalities
of buttons, and the attribute of the <form tag>, specifically “action” and “method”.
Submit buttons:When activated, a submit button submits a form. A form may contain more than
one submit button.
A submit button is used to send form data to a server. The data is sent to the page
specified in the form's action attribute (how to write scripts will be discussed in the
coming chapters). The file defined in the action attribute usually does something with the
received input:
If you would like to provide your web site visitors with a simple way to contact you from
your web site, but really don't want to display your email address, this HTML form code
may be what you're looking for. You can create a simple form, as displayed below, to
enable your visitors to send you comments, questions, product support requests, or
whatever you'd like.
Page 55
1.12 Inserting Multimedia
You can add music or video into your web page. The easiest way to add video or sound to
your web site is to use <embed> tag. The src attribute of <embed> tag defines what
video/audio file to embed into the page. This tag causes the browser itself to include
controls for the multimedia automatically.
Example:
<embed src="example.mpeg" autostart="false" />
Example:
<embed src="http://www.computerhope.com/issues/ibm-linux.mov"
Page 56
Pluginspage="http://www.apple.com/quicktime/" width="320" height="250"
</embed>
File types that are supported by the embed tag are Flash movies (.swf), mpeg(.mpg
or .mpeg), AVI's (.avi), and MOV's (.mov).
.swf files - are the file types created by Adobe Flash program.
.wmv files - are Microsoft's Window's Media Video file types.
.mov files - are Apple's Quick Time Movie format.
.mpeg files - are movie files created by the Moving Pictures Expert Group.
Macromedia's .swf and .mpeg formats may be the best options for use with the web
because the high compression rate of these file types reduces file size and expedites the
download/buffering periods for your page visitors.
Page 57