Module-2: Web Programming
Module-2: Web Programming
Programming
MODULE-2: HTML5 Page layout , Page Navigation, Tables, Forms and Media
Vidyalankar School of
Information Technology
Wadala (E), Mumbai
www.vsit.edu.in
Compiled by: Prof. Pallavi Tawde
pallavi.sawant@vsit.edu.in
Certificate
This is to certify that the e-book titled “WEB programming”
comprises all elementary learning tools for a better understating of the relevant
concepts. This e-book is comprehensively compiled as per the predefined eight
parameters and guidelines.
DISCLAIMER: The information contained in this e-book is compiled and distributed for
educational purposes only. This e-book has been designed to help learners understand
relevant concepts with a more dynamic interface. The compiler of this e-book and
Vidyalankar Institute of Technology give full and due credit to the authors of the contents,
developers and all websites from wherever information has been sourced. We acknowledge
our gratitude towards the websites YouTube, Wikipedia, and Google search engine. No
commercial benefits are being drawn from this project.
Unit I Internet and the World Wide Web, HTML 5
Recommended Books :
Prerequisites
Unit II Pre- Sem. II Sem. III Sem. IV Sem. V Sem. VI
requisites
HTML5 Page Advanced
layout, navigation, Web Projects
HTML5 Tables, Programming
Forms and Media
HTML5 Page layout and navigation
Navigation.html
<nav>
<hr>
<p style="margin:0px">
<a href="index.htm">Home</a>
<a href="tips.htm">Tips and Tricks</a>
<a href="problems.htm">Problem-Solving</a>
<a href="products.htm">Products</a>
<a href="about.htm">About Our Store</a>
<a href="contact.htm">Contact Us</a></p>
<hr>
</nav>
Output:
Creating a Graphical Navigation Bar
To create graphical navigation bar use <img> tag within the <a> tag, like this:
<a href="product.htm"><img src="product_button.gif"></a>
The example below adds a graphic-based navigation bar to the html page
In Notepad, in the upper navigation bar, change the hyperlinks so that they reference the button
graphics in the /images folder rather than displaying text.
<nav>
<hr>
<p style="margin:0px">
<a href="index.htm"><img src="images/btn_home.gif" style="border:none"></a>
<a href="tips.htm"><img src="images/btn_tips.gif" style="border:none"></a>
<a href="problems.htm"><img src="images/btn_problem.gif" style="border:none"></a>
<a href="products.htm"><img src="images/btn_products.gif" style="border:none"></a>
<a href="about.htm"><img src="images/btn_about.gif" style="border:none"></a>
<a href="contact.htm"><img src="images/btn_contact.gif" style="border:none">
</a></p>
<hr>
</nav>
The above code reference the button graphics in the /images folder rather than displaying text.
Output:
Attribute Description
src Defines the name of the image file or complete path if images not in the
same folder
Mapping :
There are two types of mapping :
i) Client side mapping (all the pages that are to be opened are at the client side terminal.)
ii) Server Side mapping (all the pages are to be connected through the server.)
The regions that are selected for hyperlinks in an image is called as Hot Spot or Hot Region.
The <map> tag is used to define a client-side image-map. An image-map is an image with clickable areas.
The name attribute is required in the map element. This attribute is associated with the <img>'s usemap
attribute and creates a relationship between the image and the map.
The map element contains a number of area elements, that defines the clickable areas in the image map.
Example :
<map name="planetmap">
</map>
HTML <area> tag
Definition and Usage
The <area> tag defines an area inside an image-map (an image-map is an image with clickable areas).
href url Specifies the page that will be displayed on the click of that area
Source: https://www.youtube.com/watch?v=ljPSQHyk_XI
Redirecting to Another URL
To redirect to the new page use a <meta> tag in the <head> section of the
page.
For example, to redirect to the page support.microsoft.com after a five-second
delay, use the following:
<meta http-equiv="refresh" content="5; url=http://support.microsoft.com">
Be sure to use a semicolon (not a comma) between the delay (the content
attribute) and the url attribute.
Attribute Description
Name Name for the property. Can be anything. Examples include, keywords, description,
author, revised, generator etc.
Content Specifies the property's value.
Scheme Specifies a scheme to interpret the property's value (as declared in the content
attribute).
http-equiv Used for http response message headers. For example http-equiv can be used to
refresh the page or to set a cookie. Values include content-type, expires, refresh and
set-cookie.
Tag Description
<header> Defines the masthead or other header information on the page. Typically
the header is repeated on every page of a site, although that is not required.
<footer> Defines the text at the bottom of a page, such as the copyright or contact
information. Again, it is typically repeated on every page of the site.
<article> Defines a block of text that represents a single article, story, or message.
An article can be distinguished from other text in that it can logically stand alone. For
example, on a news site, each news story is an article.
<aside> Defines a block of text that is tangential to the main discussion, such as a note, tip, or
caution. An aside can be distinguished from other text in that it could be pulled out and
discarded without disrupting the main document in which it appears.
<section> Defines a generic content or application section. Examples of sections would be book
chapters or the numbered sections of a thesis; a site’s home page could be split into
sections such as Introduction, News, and Contact Information. A section begins with a
heading such as <h1> followed by other content.
Creating Divisions
Use <div> tag with id attribute to create divisions.
Eg:
<div id="masthead">
Each ID must be unique within the document, but multiple documents can use
the same division names.
2. Enclose the top navigation bar in a <div> tag, and name the tag topnav.
<div id="topnav">
<hr>
<a href="index.htm"><img src="images/btn_home.gif" style="border:none"></a>
<a href="tips.htm"><img src="images/btn_tips.gif" style="border:none"></a>
<a href="problems.htm"><img src="images/btn_problem.gif" style="border:none"></a>
</hr>
</div>
3. Enclose the body paragraphs in a <div> tag, and name the tag main.
<div id="main">
<p><b>Fruit trees are now in stock! </b>We have just received a large shipment of peach,
pear, apple, and plum trees with sturdy root systems and healthy foliage, with prices as low
as $29.99. Visit the <a href="products.htm">Products</a> page for details.</p>
</div>
4. Enclose the bottom navigation bar in a <div> tag, and name the tag bottomnav.
<div id="bottomnav">
<hr>
<p style="margin:0px; text-align: center">
<a href="index.htm">Home</a>
<a href="tips.htm">Tips and Tricks</a>
<a href="problems.htm">Problem-Solving</a>
</div>
5. Enclose the copyright notice in a <div> tag, and name the tag copy.
<div id="copy">
<p>Copyright © 2012 The Garden Company™<br>
No material may be reproduced without written permission<br>
<a href="mailto:webmaster@contoso.com?subject=Question/Comment" title=
"webmaster@contoso.com">Contact the Webmaster</a></p>
</div>
1. Replace the <div id ”masthead”> tag with <header>, and change its closing
</div> tag to </header>.
<body>
<header>
<a href="http://www.contoso.com" title="Home page">
<img src="images/leaf.gif class="logo""></a>
<h1 class="pagetitle">The Garden Company</h1>
<h5 class="tagline"><i>Helping you help your gardens grow since
1975</i></h5>
</header>
2. Replace the <div id ”topnav”> tag with <nav>, and change its closing </div> tag
to </nav>.
<nav>
<hr>
<a href="index.htm"><img src="images/btn_home.gif"
style="border:none"></a>
<a href="tips.htm"><img src="images/btn_tips.gif" style="border:none"></a>
<a href="problems.htm"><img src="images/btn_problem.gif"
style="border:none"></a>
<hr>
</nav>
3. Delete the <div id ”main”> tag and its closing </div> tag.
4. Enclose the first paragraph of the body text with an <article> tag.
<article>
<p><b>Fruit trees are now in stock! </b>We have just received a large
shipment of peach, pear, apple, and plum trees with sturdy root systems
and healthy foliage, with prices as low as $29.99. Visit the <a href=
"products.htm">Products</a> page for details.</p>
</article>
Attribute Description
position: absolute This value specifies a fixed position with respect to the parent element. Unless
the element is within some other tag, the parent element is generally the <body>
tag; in this case, the element would have a fixed position relative to
the upper-left corner of the page.
position: relative This value specifies an offset from the element’s natural position.
Other elements on the page are not affected, even if the new position causes
elements to overlap.
position: fixed This value specifies a fixed position within the browser window that
doesn’t change even when the display is scrolled up or down. Internet Explorer
does not support this setting.
For example, to position a division called main exactly 100 pixels from the top of the page and 200 pixels
from the left side, create this style rule in the style sheet:
#main {position: absolute; top: 100px; left: 200px}
Formatting Divisions
You can use styles to specify the font family, font style, font weight, alignment, color.
For example, to add a khaki-colored background to the navigation bar, use the following:
nav {float: left; width: 150px; padding-top: 15px; background-color: khaki}
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). The letters td stands for "table data," which is the content of a data
cell. Table row can also contain <th> tag i.e. table heading. A data cell can contain text, images, lists,
paragraphs, forms, horizontal rules, tables, etc.
The <caption> tag is used to specify a description table and allows you to place caption above and
below tables.
Border Number Specifies the width of the border of the table. If the value
of the attribute is not set, then the table will have no
border.
Cellspacing Pixel Specifies the width of the border between individual cells
of a table and the border of the table itself.
Border Number Specifies the width of the border of the table row.
Border Number Specifies the width of the border of the table. If the
value of the attribute is not set, then the table will have
no border.
Rowspan number This will merge the current cell with a specified number
of its adjacent cells on the same column. It should have
the value larger than one.
Colspan Number This will merge the current cell with a specified number
of its adjacent cells on the same row. It should have the
value larger than one.
Example:
<table border="1">
<caption>Table Caption</caption>
<tr>
<th>Heading</th>
<th>Another Heading</th>
</tr>
<tr>
</tr>
<tr>
</tr>
</table>
Table Caption
This example demonstrates how to define table cells that span more than one row or one column.
<html>
<body>
<table border="1">
<tr>
<th>Name</th>
<th colspan="2">Telephone</th>
</tr>
<tr>
<td>Vidyalankar</td>
<td>42324232</td>
<td>42321160</td>
</tr>
</table>
<tr>
<th>First Name:</th>
<td>Vidyalankar</td>
</tr>
<tr>
<th rowspan="2">Telephone:</th>
<td>42324232</td>
</tr>
<tr>
<td>42321160</td>
</tr>
</table>
</body>
</html>
Name Telephone
42324232
Telephone
42321160
Cell padding
This example demonstrates how to use cellpadding to create more white space between the cell content and
its borders.
<html>
<body>
<h4>Without cellpadding:</h4>
<table border="1">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
<h4>With cellpadding:</h4>
<table border="1"
cellpadding="10">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
</body>
</html>
Cell spacing
This example demonstrates how to use cellspacing to increase the distance between the cells.
<html>
<body>
<h4>Without cellspacing:</h4>
<table border="1">
<tr>
<td>First</td> <td>Row</td></tr>
<tr>
<td>Second</td> <td>Row</td>
</tr>
</table>
<h4>With cellspacing:</h4>
<table border="1"
cellspacing="10">
<tr>
<td>First</td>
<td>Row</td>
</tr> <tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
</body>
</html>
Source:- https://www.youtube.com/watch?v=4Us2q5eSWNc
Forms and Input
A form is an area that can contain form elements.
Form elements are elements that allow user to enter information (like text fields, textarea fields, dropdown
menus, radio buttons, checkboxes, etc.) in a form. A form is defined with the <form> tag.
<form>
<input>
<input>
< /form>
Action page url Specifies the url of the page that should be called when
user clicks the submit button
Input
The most used form tag is the <input> tag. The type of input is specified with the type attribute. The most
commonly used input types are explained below.
submit,Reset,hidden,file,email,url
Required NA If this attribute is set for textbox then entry in the textbox
is must.
A. Text Fields
Text fields are used when you want user to type letters, numbers etc. in a form.
<form>
First name :
Last name :
Password:
< /form>
The output on previous page shows how it looks in a browser. Note that the form itself is not visible. Also
note that in most browsers, the width of the text field is 20 characters by default.
B. Radio Buttons
Radio Buttons are used when you want the user to select one of a limited number of choices. Note that
only one option can be chosen.
<form>
< /form>
C. Checkboxes
Checkboxes are used when you want the user to select one or more options of a limited number of
choices.
<form>
< /form>
The difference between the Text Box (above) and the Text Area is that the Text Box only allows for one
line. The Text Area, however, is much larger and will allow for as many words as you want.
Please note that the <textarea> requires a </textarea> command, whereas the TEXT BOX command above
did not.
textarea (all one word): This yells to the form command above that here will sit another form item.
This one will be a text area box.
name is the same as before. The information the reader puts in this box will arrive in your email box
denoted by whatever name you use. In this case, what is written in this box will arrive in your email box
with the words, “comment=”.
rows tells the computer how many rows of text it will accept, and…
cols tells the computer how many characters will be in each row. This text box will accept 6 rows of text
each being 40 characters long.
The PopUp box, unless clicked on, only shows one item. Click on it to see all the choices. The below
PopUp box is for people to choose their favorite color :
Here are the commands that placed the PopUp box on the page:
<option selected>Blue
<option>Red
<option>Yellow
<option>Green
<option>Black
<option>Orange
<option>Purple
< /select>
select tells the computer another form is going here. This time it’s a SELECT or PopUp form.
name: Same as above. This is the heading of the form item. It denotes how the results of the reader will
arrive at your email box. In this case it will say; “Favorite_Color=” and then the reader’s choice.
size:- denotes the size of the box. Here, 1 means one line or item is shown.
option selected denotes which option will appear in the box. Note on the page that “Blue” is visible.
option denotes another choice that will be visible when clicked on item.
If the list’s choices fall into categories, you might want to break them up into sections.
To format a list as shown in the previous example, surround the groups of options with
an <optiongroup> tag. Include a label attribute that specifies the heading text for each
option group. Here’s the code for the preceding example:
Tags Description
More Examples
<html><body>
<html><body>
<form>Male:
<form>
<input type= “radio” checked name= “Sex”
I have a bike :
value= “male”><br>
<input type = “checkbox” name= “Bike” >
<br> Female: <input type= “radio”
< /body></html>
Simple drop down box This example Another drop down box This example
demonstrates how to create a simple demonstrates how to create a simple
dropdown box on a HTML page. A dropdown box with a preselected value.
dropdown box is a selectable list.
<html><body>
<html><body>
<form>
<form>
<select name= “cars”>
<select name= “cars”>
<option value= “Volvo”>Volvo
<option value= “volvo”>Volvo
<option value= “saab”>Saab
<option value= “saab”>Saab
<option value= “fiat”>Fiat
<option value= “fiat” selected>Fiat
<option value= “audi”>Audi
<option value= “audi”>Audi
< /select>
< /select>
< /form>
< /form>
< /body>< /html>
< /body>< /html>
Textarea This example demonstrates Create a button This example
how to create a textarea (a multiline text demonstrates how to create a button. On
input control). A user can write text in the the button you can define your own text.
textarea. In a textarea you can write an
<html><body>
unlimited number of characters.
<form><input type= “button”
Health information:
< /legend>
< /body></html>
Source:- https://www.youtube.com/watch?v=tbw_d6QEcIc
Q. Write HTML code to design the following page : [M-09]
Semester
Subjects
Teacher
Not clear
Solution :
<html>
<head>
</head>
<body bgcolor=yellow>
<form>
Login ID :
Password:
<input type="sword" name="password" size="40"> <br>
Name :
Last Name :
Address :
Country :
<option> Pakistan
<option> England
<option> Australia
<option> Nepal
<option> Bangladesh
</select> <br>
Handicapped :
Languages Known :
Education :
</body>
</html>
HTML5 provides several other field types that can add that extra bit of polish to
your forms. If the user’s browser doesn’t support them, it renders and treats them as
text fields, so you can use them freely without worrying about backward
compatibility.
1. Spin boxes are used to increment numeric values.
The preceding spin box was created by using the following code:
<input type="number" name="copies" min="0"max="100" step="1"
value="1">
The min and max attributes control the minimum and maximum values,
respectively.
The step attribute specifies how much the value increments or decrements when
you click the up or down arrow buttons.
The value attribute specifies the default value.
2. A slider is a sliding bar that you can drag from side to side. Its type is range,
and its attributes are nearly identical to those for a spin box.
3. A date picker pops up a calendar on which the user can click and select a date.
Use the date type to get a date picker in HTML5-compliant browsers, as
follows:
<input type="date">
For a standard date, use type ”date”. This enables the user to select a specific date
from a calendar. You can also use any of the following types for other date and time-
related selections:
● Type ”month” selects an entire month
● Type ”week” selects an entire week
● Type ”time” selects a time only (no date)
● Type ”datetime” select both a date and a time
● Type ”datetime-local” selects both a date and time using the user’s local time zone
Incorporating Sound and Video
<video> tag
The <video> tag specifies video, such as a movie clip or other video streams.
Currently, there are 3 supported video formats for the <video> element: MP4, WebM, and Ogg:
MP4 = MPEG 4 files with H264 video codec and AAC audio codec
WebM = WebM files with VP8 video codec and Vorbis audio codec
Ogg = Ogg files with Theora video codec and Vorbis audio codec
Example
<html>
<body>
<video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
<p><strong>Note:</strong> The video tag is not supported in Internet Explorer 8 and earlier
versions.</p>
</body>
</html>
Output:
<embed> tag
The <embed> element creates an embedded panel in which a third-party application, such as
a Flash-based object, can run.
Example:
<html>
<body>
<embed src="helloworld.swf">
</body>
</html>
<audio> tag
The <audio> tag defines sound, such as music or other audio streams.
Currently, there are 3 supported file formats for the <audio> element: MP3, Wav, and Ogg:
Example
<html>
<body>
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<p><strong>Note:</strong> The audio tag is not supported in Internet Explorer 8 and earlier
versions.</p>
</body>
</html>
Output:
Questions:
MCQ
4. To create a combo box (drop down box) which tag will you use?
a. <select>
b. <list>
c. <input type="dropdown">
d. all of above
5. Which attribute you’ll use with TD tag to merge two cells horizontally?
a. merge=colspan2
b. rowspan=2
c. colspan=2
d. merge=row2
6. Which of the following is an attribute of <Table> tag?
a. SRC
b. LINK
c. CELLPADDING
d. BOLD
7. HTML5 features, include native audio and video support without the need for.
a. Flash
b. Canvas
c. Svg
d. None of the above
8. Which boolean attribute if specified, will allow video automatically seek back to the start
after reaching at the end.
a. autoplay
b. autobuffer
c. loop
d. controls
9. Which boolean attribute if specified, the audio will automatically begin to play back as soon
as it can do so without stopping to finish loading the data.
a. autobuffer
b. loop
c. autoplay
d. preload