Web Technology-1
Web Technology-1
Web Technology-1
Unit Description:
This unit specifies competencies required to design a website. It involves gathering data
required, determining website design tool, developing a functional website and host a
website developed.
Page 1 of 145
LEARNING NO. OF
WEEK CONTENT
OUTCOME HOURS
Add interactivity to the website using JS.
Adding Server-Side Interactivity to the website
using Active Server Pages (ASP) and Internet
Information Server (IIS)
o Introduction to Active Server Pages
(ASP)
Develop a
o Setting up IIS to Work in your Machine
functional
7-8 o ASP Basics 6
Dynamic Website
o ASP Data Types and Variables
2
o Control Structures
o Control Structures
o Form Input Data Processing
o ASP procedures
Add interactivity to the website using ASP and IIS.
Adding Database interactivity to the website
using MS Access
o Scope of variables
Develop a
o Redirecting the browser
functional
9 o Cookies and sessions 3
Dynamic Website
o Database connectivity
3
Link database to a database to the website using
ASP, Access and IIS. (Add registration form to add
new members to the database)
Website hosting process
Factors to consider when selecting a host
Legal and regulatory requirements
Host Website
10 Domain name 3
Developed
Uploading website
Security measure.
Host the website.
TOTAL HOURS 30
Resources:
There is no required text for this course. Class handouts and a number of online
resources, including tutorials on http://www.w3schools.com/ will be used.
Page 2 of 145
Industrial visits
Mode of assignment:
Formative Assessments
a) Class Exercises
b) Online CATs
c) Assignments
d) Observation
e) Oral
Summative Assessment
f) Final written examination
Page 3 of 145
INTRODUCTION
Terms
Internet: Wide area network connecting computers and other electronic devices
globally. Also called the Net.
Internet Service Provider (ISP): The ISP is commercial organization that
provides internet connections, along with a set of support services for a fee.
Bandwidth and cost are two considerations when deciding which commercial
ISP service to use. Bandwidth refers to the amount of data that can be
transferred through a communications medium in a fixed amount of time.
Web browsers are software programs that allow users to access the web
content.
URL (Uniform Resource Locator) specifies the address (i.e., location) of the
web page displayed in the browser window. Each web page on the Internet is
associated with a unique URL. URLs usually begin with http://, which stands
for Hypertext Transfer Protocol (HTTP), the standard protocol (or set of
communication rules) for transferring web documents over the Internet. HTTP
is a data communication protocol used to establish communication between
client and server.
Viewing Source Code, or the original code written to create the web page you
are viewing. Source code allows the viewer to understand how the programmer
created the page.
Search Engines
The File Transfer Protocol (FTP) is a set of rules used to transfer data, especially
large files, over the Internet. An FTP site’s URL begins with ftp:// rather than
http://, and can also be accessed either with the web browser or software that
supports FTP. Transferring a file from the local machine to another location on
the Internet is called uploading and can be accomplished using the FTP protocol
A website is a collection of related web pages containing images, videos or
other digital assets. A website is hosted on at least one web server, accessible
via a network such as the Internet or a private local area network through an
Internet address also called Uniform Resource Locator (URL).
A Web Page: a document, written in plain text with formatting instructions of
Hypertext Markup Language (HTML, XHTML). A web page may incorporate
elements from other websites with suitable markup anchors. Web pages are
accessed and transported with the Hypertext Transfer Protocol (HTTP)
A Web Server: A website is hosted on a computer system known as a web
server. It retrieves and delivers the web pages in response to requests from the
website users.
Page 4 of 145
The basic objective of a web server is to store, process and deliver web pages
to the users. This intercommunication is done using HTTP Protocol. A web
server also supports SMTP and FTP protocols for Emailing and for file
transfer and storage.
Apache Web Server, Microsoft's Internet Information Server (IIS), NGINX,
Apache Tomcat, are examples of commonly used web server software
Technologies such as HyperText Markup Language (HTML), JavaScript, CSS
and Extensible Markup Language (XML) are used to build the portions of
web-based applications that reside on the client side (i.e., the portions of
applications that typically run on web browsers such as Firefox or Microsoft’s
Internet Explorer).
Technologies such as web servers, databases, ASP, PHP, Ajax, Ruby on Rails
and Java are used to build the server side of web-based applications. These
parts of applications typically run on “heavy-duty” computer systems on
which organizations’ business-critical websites reside.
A Static Website
Static websites are ones that are fixed and display the same content for every
user, usually written exclusively in HTML and CSS.
The website can look beautiful with multimedia elements and videos but the
page’s source code won’t change, no matter what actions a user takes on it.
Visitors are not able to control what information they receive via a static
website
The only way a user can interact with a static page is by clicking hyperlinks
and filling Forms.
Static website are good for those who want to build informational websites
like company’s brochure site.
They are edited using three broad categories of software:
Text editors, such as (Notepad, Sublime Text, Atom, TextEdit, Visual
Studio Code), where content are manipulated directly within the
editor program. With text based editors, you can’t see live preview of
the site.
WYSIWYG-What you see is what you get. The editors that provide
and editing interface that shows how the code looks on a working web
page.
WYSIWYG offline editors, such as Microsoft FrontPage and
Adobe Dreamweaver, with which the site is edited using a GUI
interface and the final HTML markup is generated
automatically by the editor software
WYSIWYG online editors which create media rich online
presentation like web pages, widgets, intro, blogs, and other
documents.
Page 5 of 145
Template-based editors, such as Rapidweaver and iWeb,
HTML Editors have basic features like syntax highlighting, inserting
common HTML elements, auto completion and intelliSense (Smart
Completions based on your types, functions and modules)
Dynamic Website
A dynamic website is one that can display different content and provide user
interaction, by making use of advanced programming and databases in
addition to HTML.
Compared to static websites, which are purely informational, a dynamic
website is more interactive and functional.
Dynamic websites rely on both client-side and server-side scripting languages
e.g. JavaScript, PHP or ASP. Client side scripting refers to code that is
executed by the browser, usually with JavaScript. Server-side Scripting refers
to code that is executed by the server (before the content is sent to the user’s
browser).
A special editor such as an Integrated Development Environment (IDE) is
required to build dynamic websites, along with strong technical skills in
server-side programming language.
Dynamic websites are easier to maintain, they encourage efficient data
management, and you can expand them with extra functionality in future.
(The downside is that they take longer to build and the initial costs are higher)
A network protocol/communication protocol is a set of rules governing the
communication and transfer of data between two nodes on the network.
A protocol specifies the format and meaning of messages
exchanged between computers across a network.
Format is sometimes called syntax. Meaning is sometimes called
semantics
Protocols are implemented by a protocol software framework that
is part of OS e.g. OSI and TCP/IP
INTERNET APPLICATIONS
An Internet application does something for end users. It is generally not concerned
with how data is actually transmitted between the hosts. Here are some distributed
applications that require well-defined application level protocols:
Sending and receiving email
Searching and browsing information archives
Copying files between computers
Conducting financial transactions
Navigating (in your car, smart scooter, smart bike, or other)
Playing interactive games
Video and music streaming
Chat or voice communication (direct messaging, video conferencing)
In addition, there are a number of network services such as:
Page 6 of 145
Name servers
Configuration servers
Mail gateways, transfer agents, relays
File and print servers
All Internet applications work over the exact same transport layers. The Internet
says nothing about how these application should work. It provides IP and TCP &
UDP and that’s it. You can build anything on top of those.
Applications pretty much just need to know:
i.) the IP address of the other party (what host the other party is running
on—a network layer concept), and
ii.) The port number of the application running at the other end (because
the other machine might be running multiple services—a transport
layer concept).
It passes those two pieces of information to the transport layer to make the
communication happen.
APPLICATION LAYER (HTTP, FTP, SMTP, ...)
TRANSPORT LAYER (TCP, UDP, ...)
NETWORK LAYER (IP)
LINK LAYER (Ethernet, Wifi, ...)
IP Addresses for Hosts
A host address will be 32 bits for IPv4 and 128 bits for IPv6.
Port Numbers
Once packets get to the right machine, they have to get to the right program
running on that machine. The abstraction here is the port number. Port
numbers are in the range 0..65535.
On the Internet, port numbers are partitioned as follows:
i.) Ports, assigned by the IETF Review or IESG Approval procedures
described in RFC 8126.
ii.) 1024...49151 are the User Ports, assigned by IANA using the IETF
Review process, the "IESG Approval" process, or the "Expert
Review" process, as per RFC 6335.
iii.) 49152...65535 are the Dynamic Ports, which are unrestricted, do
with them whatever you want.
Sockets
WEB
A system of Internet Servers that support specially formatted documents in a markup language
called HTML (HyperText Markup Language) that supports links to other documents, as well
as graphics, audio, and video files.
This means you can jump from one document to another simply by clicking on hot spots.
The Web uses HTTP protocol to transmit data and share information. When you type a web
address into your browser and hit enter:
Page 7 of 145
The browser goes to the DNS Server, and finds the real address of the server that the
website lives on.
The browser sends HTTP message to the server, asking it to send a copy of the website
to the client. This message and all other data sent between the client and server, is sent
across the internet using TCP/IP.
If the server approves clients request, the server sends the client “200 OK” message
and then starts sending the websites files to the browser as a series of packets
The browser assembles the packets into a complete web age and displays it to you.
The Web is just one of the ways that information is shared over the Internet; others include
email, instant messaging and File Transfer Protocol (FTP)
Good use of color: an appropriate color scheme will contain 2 or 3 primary colors that
blend well and create a proper mood or tone for the organization. Don't overdo the
color, as it can distract the written content.
Text that is easily read: The most easily read combination is black text on a white
background, but many other color combinations are acceptable if the contrast is within
an
appropriate range. Use fonts that are easy to read and are found on most of today's
computer
systems. Depending on your audience. Keep font size for paragraph text between 10
and 12 pts.
Meaningful graphics: Graphics are important, as they lend visual variety and appeal
to an
otherwise boring page of text. However, don't over-use them, and make sure that they
add meaning or context to your written content. Don’t overload any one page with
more than 3 or 4 images. Quality photography: A simple way to increase visual
appeal is to use high quality photography. High quality product images are especially
important for online retailers.
Simplicity: Keep it simple and allow for adequate white space. Uncluttered layouts
allow
viewers to focus on your message. Don't overload your site with overly complex
design, animation, or other effects just to impress your viewers.
b) Content: Along with style, your site must have substance. Remember that the audience is
looking for information that will help them make a decision, so the website should be
informative and relevant. Use this opportunity to increase visitor confidence in your
organization’s knowledge and competence. Guidelines:
Page 8 of 145
Short and organized copy: Clearly label topics and break your text up into small
paragraphs. Don't bore your visitors with visually overwhelming text. You've got less
than 10 seconds to hook your visitors, so grab their attention by being clear, concise
and compelling.
Update your content regularly: No one likes to read the same thing over and over
again. Dead or static content will not bring visitors back to your site!
Speak to your visitors: Use the word you as much as possible. Minimize the use of I,
we and us.
Consider a pro: Unless you’re an especially good writer, consider using a professional
to write or edit your text content.
c) Functionality: Every component of your site should work quickly and correctly. Broken or
poorly constructed components will leave your visitors frustrated and disillusioned with your
organization. Across the spectrum, everything should work as expected, including hyperlinks,
contact forms, site search, event registration, and so on. Error-free copy: Remember the
exposure your website will get. Double-check your facts and figures, as you don't know who
may be quoting you tomorrow. Nor do you want to be recognized or remembered for typos,
incorrect grammar and punctuation, or misspellings. Spelling mistakes and bad grammar are
as unforgivable on a website as they are in other organization materials.
d) Usability; A critical, but often overlooked component of a successful website is its degree
of usability. Your site must be easy to read, navigate, and understandable. Some key usability
elements include:
Simplicity: The best way to keep visitors glued to your site is through valuable content,
good organization and attractive design. Keep your site simple and well organized.
Fast-loading pages: A page should load in 20 seconds or less via dial-up; at more than
that, you'll lose more than half of your potential visitors.
Minimal scroll: This is particularly important on the first page. Create links from the
main page to read more about a particular topic. Even the Search Engines will reward
you for this behaviour.
Consistent layout: Site layout is extremely important for usability. Use a consistent
layout and repeat certain elements throughout the site.
Prominent, logical navigation: Place your menu items at the top of your site, or above
the fold on either side. Limit your menu items to 10 or fewer. Remember, your visitors
are in a hurry -- don't make them hunt for information.
Descriptive link text: Usability testing shows that long link text makes it much easier
for visitors to find their way around a site. Long, descriptive link text is favored by
Search Engines, too. Back links are important to give users a sense of direction and to
keep them from feeling lost. Use a site map, and breadcrumbs, if necessary.
Cross-platform/browser compatibility: Different browsers often have different rules
for displaying content. At a minimum, you should test your site in the latest versions
of Internet Explorer, as well as Firefox and Safari.
Screen Resolution: Screen resolution for the typical computer monitor continues to
increase. Today, the average web surfer uses a resolution of 1024 x 768 pixels.
However, you need to make sure that what looks good at this setting will also work
nicely for other resolutions.
e) Search Engine Optimized (SEO): Some of the search engine optimization rules includes:
Page 9 of 145
Include plenty of written content in HTML format. Don't use Flash, JavaScript or
image-only objects for your navigational items.
offering quality content, using proper metadata and effective keywords, and having
inbound links from relevant high-quality pages
Use important keywords frequently and appropriately.
Minimize the use of tables and use Cascading Style Sheets for layout and positioning;
keep
your HTML code clutter-free.
Leverage your links -- make them descriptive and use your keywords in the link text
Web Components:
Browser, Web Server, Hypermedia (Text, Images, Selectable pointers to other pages)
Links, Document representation (HTML), Transfer protocol, etc
WEB PROGRAMMING
Web Programming. Writing the necessary source code to create a website.
Web development refers to building, creating and maintaining websites. It
includes aspects such as
Web design
Web publishing\web programming and
Database management
o A web Designer only designs website interfaces using HTML, CSS, etc
o A web Developer maybe involved in designing a website, but also write a
web script in languages such as PHP and ASP. Web Developer may help
maintain and update a database used by dynamic website.
Approaches to Web Programming
o Server-Side Programming
o Client-Side Programming
Web Programming Languages
o Static technologies like HTML, CSS, JavaScript, XML
o Perl, PHP, Python, Ruby on Rails, Script
Page 10 of 145
Inside a Browser. The main Controller:
i) Receives input from user and
ii) Invokes client and interpreter.
Clients are built in the browser and can be HTTP, FTP, Email, etc.
the client uses network to fetch items.
Interpreter is used to display items.
o Common Gateway Interface (CGI)
A standard way for a web server to pass a Web user’s request to an
application program and to receive data back to forward to the user
Page 11 of 145
HTML Coding
Introduction
HTML stands for Hyper Text Markup Language
HTML is used to design web pages using markup language
HTML describes the structure of a Web page
HTML is platform independent
HTML consists of a series of elements
HTML elements tell the browser how to display the content
.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<hr>
</body>
</html>
Note:
There are four tags every HTML document should have. These tags define what
type of document it is, and the major sections. These tags are <HTML>,
<HEAD>, <TITLE>, and <BODY>.
Explanation
The <!DOCTYPE html> declaration tells version of HTML
The <html> </html> Element
The root element of an HTML page. Defines an HTML document
All other HTML elements are encapsulated within the <html> element
The tag lets the browser know it’s a HTML web page. It tells the browser that
the file contains HTML coded information. The file extension .html indicates
that the file is a HTML document.
The <head> </head> element
Contains Meta information about the HTML page. (Meta- data about data)
Meta Data typically define the document title, character set, styles, scripts,
etc.
Statements (or tags) that give information to a person visiting your website, or
information such as those needed for a Search Engine
Page 12 of 145
Provides information about the document. You do not see this information
displayed on the browser screen. It can be seen by choosing View Page
Source
The HTML Elements that can be used inside the head element are <title>,
<base>, <link>, <style>, <script>, <meta> and
<noscript> element.
The <title> </title> element is required.
The element specifies a title for the HTML page (which is shown in the
browser's title bar or in the page's tab).
Also displays a title for the page in search-engine results. Search engine
web crawlers pay particular attention to the words used in the title.
It provides a title for the page when it is added to favorites or book
marked.
<!DOCTYPE html>
<html lang="en">
<head>
<title>A simple HTML document</title>
</head>
<body>
<p>Hello World!</p>
</body>
</html>
The <base> </base> element
Used to define a base URL for all relative links contained in the document.
Set the base URL once at the top of your page, and then all subsequent
relative links will use that as a starting point.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Defining a base URL</title>
<base href="https://www.tutorialrepublic.com/">
</head>
<body>
<p><a href="html-tutorial/html-head.php">HTML
Head</a>.</p>
</body>
</html>
The <link> </link> element defines the relationship between the current
document and the external documents or resources. A common use of link
element is to link to external style sheets.
<head>
<title>Linking Style Sheets</title>
<link rel="stylesheet" href="style.css">
</head>
Page 13 of 145
An HTML document's <head> element may contain any number of <link>
elements. The <link> element has attributes, but no contents.
The <style> </style> element is used to define embedded style information
for an HTML document. The style rules inside the <style> element specify
how HTML elements render in a browser.
<head>
<title>Embedding Style Sheets</title>
<style>
body { background-color: YellowGreen; }
h1 { color: red; }
p { color: green; }
</style>
</head>
The <meta> </meta> element provides metadata about the HTML
document. Metadata is a set of data that describes and gives information about
other data.
The <script> </script> element is used to define client-side script,
such as JavaScript in HTML documents.
<head>
<title>Adding JavaScript</title>
<script>
document.write("<h1>Hello World!</h1>")
</script>
</head>
The <body> </body> element
Defines the document's body, and is a container for all the visible contents,
such as headings, paragraphs, images, hyperlinks, tables, lists, forms, etc.
Only the content inside the <body> section will be displayed in a browser.
The <h1> element defines a large heading
The <p> element defines a paragraph
The above visualizes of an HTML page structure
Page 14 of 145
HTML tags are not case sensitive: <P> means the same as <p>
HTML Attributes
All HTML elements can have attributes
Attributes provide additional information about elements
Attributes are always specified in the start tag
Attributes usually come in name/value pairs like:
name="value"
e.g HTML title Attribute
<p title="Free tutorials">The Easiest One</p>
o The title attribute specifies extra information about an element.
o The information is most often shown as a tooltip text when the mouse
moves over the element.
o The title attribute can be used on any HTML element
The global attributes are attributes that can be used with all HTML elements.
E.g. class, style, lang, tabindex, title, id, hidden
Event attributes have the ability to let events trigger actions in a browser,
like starting a JavaScript when a user clicks on an element. E.g. ononline,
Page 15 of 145
onresize, onunload, onerror, onload, onstorage, onkeyup, onclick, ondrag,
oncopy, onplay
Page 16 of 145
Attribute Value Description
Behavior scroll Defines the type of scrolling.
slide
alternate
Bgcolor rgb(x,x,x) Deprecated − Defines the direction of scrolling
the content.
Direction up Defines the direction of scrolling the content.
down
left
right
Height pixels or % Defines the height of marquee.
Hspace pixels Specifies horizontal space around the marquee.
Loop number Specifies how many times to loop. The default
value is INFINITE, which means that the
marquee loops endlessly.
Scrolldelay seconds Defines how long to delay between each jump.
scrollamount number Defines how far to jump.
Width pixels or % Defines the width of marquee.
Vspace pixels Specifies vertical space around the marquee
Page 17 of 145
<STRONG> is also a logical tag. It is used to strongly emphasize text.
<STRONG> is distinct from <EM>. In most browsers, STRONG is identical
to boldface.
Using <B> for Boldface or <I> for Italics. <STRONG> is accepted by all
browsers as a way of strongly emphasizing text which in most cases is
boldface. Instead of the <STRONG> and </STRONG> tags for strongly
emphasizing text, you will sometimes see <B> and </B> for bolding text.
While <STRONG> is a "Logical Style Command", <B> is a "Physical Style
Command". A physical style command cannot be rendered differently.
Therefore if a browser does not accept the <B> tag, then your text will simply
not be bolded as the browser has no alternative way to display them on the
screen. The same reasoning is also be applied for using the tag <I> to print in
italics instead of the <EM> tag. Now if for some reason you want to ensure
only italics or boldface and nothing else, then use the italic font <I> or the
boldface font <B>.
<Html>
<Head>
<Title>OUTDOOR LIVING - ONTARIO</Title>
</Head>
<Body>
<H2 Align="Center">OUTDOOR LIVING IN
ONTARIO</h2>
<H3>POINTS OF INTEREST</H3>
<HR>
<P>Northern Ontario:
<P> <strong>Five Mile Lake Provincial Park
</strong>
<P> <EM>1.5 square miles.</EM> Camping,
fishing (<EM>walleye, northern pike, brook
trout</EM>), canoeing, self-guided nature
trails.
<P>
<strong><em>Recommended</em></strong>
<hr>
</body>
</html>
The <br>, <p> and <pre> tags
<p> defines a paragraph. A container which marks a block of text as a
paragraph in a webpage and the browser leaves a line between two lines. It
has align attributes that specifies text alignment, align=”center”,
align=”justify”
Page 18 of 145
<br> defines a line break. An empty tag used to break a line and display
proceeding text from the next line, without giving space between two lines.
e.g. <p> This is <br> a paragraph <br> with line breaks</p>
The <pre> tag defines preformatted text. The text inside <pre> element is
displayed in a fixed-width font (usually Courier), and it preserves both spaces
and line breaks.
E.g.
<pre>
My Bonnie lies over the Ocean
My Bonnie lies over the sea
Oh, bring back my Bonnie to me.
</pre>
Page 19 of 145
<dd>Cascading Style Sheets, the language for defining the
styles and presentation of an HTML document. CSS describes
how HTML elements should be displayed. There are three ways
you can use to implement CSS: internal, external, and inline
styles</dd>
<dt> JavaScript</dt>
<dd>JavaScript ("JS" for short) is a full-fledged dynamic
programming language that can add interactivity to a
website. avaScript adds behavior to web pages. A
scripting language built-in to most browsers and designed
to be used with web documents. </dd>
<dt> ASP and ASP.NET</dt>
<dd>Active Server Pages. ASP is a development framework for
building web pages. ASP supports many different
development models:Classic ASP, ASP.NET Web Forms, ASP.NET
MVC, ASP.NET Web Pages, ASP.NET API, ASP.NET Core. a
server side Web building scripting engine. </dd>
</dl>
HTML Definition element (<dfn>) is used to indicate the term being defined
within the context of a definition phrase or sentence. E.g.
<p>A <dfn>validator</dfn> is a program that checks
for syntax errors in code or documents.</p>
<abbr> Defines an abbreviation or acronym
<address> Defines contact information for the author/owner of a document
<blockquote> Defines a section that is quoted from another source
<cite> Defines the title of a work
<q> Defines a short inline quotation
HTML Subscript and Superscript Tags
The <sub> tag is used to add a subscript text to the HTML document.
The <sup> tag is used to add a superscript text to the HTML document
<p>Testing <sub>subscript text</sub></p>
<p>Testing <sup>superscript text</sup></p>
Page 20 of 145
Char Entity Number Definition
$ $ $ Dollar
% % % Percent
& & & Ampersand
' ' ' single quotation mark (apostrophe)
* * * Asterisk
< < < less than
> > > greater than
@ @ @ At symbol
™ ™ ™ Trademark
∑ ∑ ∑ N-ary Summation
<h1 style="color:blue;text-align:center">This is a
header</h1>
<p style="color:green;">This is a paragraph.</p>
Page 21 of 145
The <div> element is a block-level and is often used as a container for other
HTML elements
The <span> element is an inline container used to mark up a part of a text, or a
part of a document
A block level element has a top and a bottom margin, whereas an inline
element does not.
The <div> element is a block-level element. Other examples are:
<address> <dt> <hr> <section>
<article> <fieldset> <li> <table>
<aside> <figcaption> <main> <tfoot>
<blockquote> <figure> <nav> <ul>
<canvas> <footer> <noscript> <video>
<dd> <form> <ol>
<div> <h1>-<h6> <p>
<dl> <header> <pre>
Page 22 of 145
There are different ways to provide these links. The three most common ones are:
(a) Clicking on a word, phrase or sentence
(b) Clicking on a button
(c) Clicking on an image (that is, a picture or graphic).
download Directs the browser to download the linked resource rather than
opening it.
target _blank Specifies the context in which the linked resource will open.
_parent
_self
Page 23 of 145
_top
frame name
title text Defines the title of a link, which appears to the user as a tooltip.
Value Description
Examples
1. How to create a link to W3Schools.com:
<a href="https://www.w3schools.com/">Visit W3Schools.com!</a>
2. How to use an image as a link:
To use an image as a link, just put the <img> tag inside the <a> tag:
<a href="https://www.w3schools.com">
<img border="0" alt="W3Schools"
src="logo_w3s.gif" width="100" height="100">
</a>
Page 24 of 145
<a href="default.asp">
<img src="smiley.gif" alt="HTML tutorial"
style="width:42px;height:42px;">
</a>
<!--We can also use an image as an anchor element-->
<a><img src="http://example.com/image-file.png" /></a>
Page 25 of 145
_self - Default. Opens the document in the same window/tab/ frame as
it was clicked
_blank - Opens the document in a new window or tab
_parent - Opens the document in the parent frame
_top - Opens the document in the full body of the window
framename Opens the linked document in the named iframe
Examples
1. Use target="_blank" to open the linked document in a new browser window or tab:
<a href="https://www.w3schools.com/" target="_blank">Visit
W3Schools!</a>
2. Download Example
<a href=http://example.com/file.doc
download="Example_File" > download a file </a>, use the
<code>href</code> attribute to identify the file to be downloaded, and the
<code>download</code> attribute to provide a name for the downloaded file
Page 26 of 145
<h2>Relative URLs</h2>
<p><a href="html_images.asp">HTML Images</a></p>
<p><a href="/css/default.asp">CSS Tutorial</a></p>
Note:
1. A Web of Links
The World Wide Web is best described as a massive library of hyperlinked
documents where anchor elements are used to create bridges between related
documents. In this definition, anchor elements occupy their rightful place as the
glue that ties the web together and the bridges that allow web users to move from
one document to a related document.
2. The <link> element is used to define a relationship between an HTML document
and an external resource. This element is most commonly used to define the
relationship between a document and one or more external CSS stylesheets. Some
of the Link Element attributes are href, rel, media, title, type
3. The <a> element, or anchor element, it used to create a hyperlink to another webpage or
another location within the same webpage.
4. The <base> element is used to identify a base URL upon which to build all relative URLs
that appear on a webpage.
More on Links
1. Placing Subject in Emails
You can also add the subject, cc, and bcc lines as part of the mailto: link. For
example, to add a topic (a subject) in the subject line of your e-mail (the most
popular option), the format is:
<A HREF="mailto:[email protected]?subject=topic">Please
send more product information</A>
<HREF="mailto:[email protected]?subject=product
information">Please send more product information</A>
2. If you want to include the e-mail address of the person you also want to receive a
carbon copy of the same e-mail (that is, the person you want to be cc'd), the format is:
<A HREF="[email protected][email protected]">
<A HREF="mailto:[email protected][email protected]">
You can also place a personal message in the body of an email using the? body
attribute as in:
<A HREF="mailto:?body=Don't forget also to send in your
Page 27 of 145
financial statements as soon as possible.">Click here
when ready to send us your email.</A>
4. Links in general
<H4 ALIGN="CENTER">
<A HREF="#links">| Links in general |</A>
<A HREF="#page">| Links within a page - page jump |</A>
<A HREF="another">| Linking to another page in your website|</A>
<A HREF="world">| Linking to another page anywhere in the world
|</A>
<A HREF="button">| Using a link button |</A>
<A HREF="mail">| MAILTO: (sending an e-mail) |</A>
</H4>
(b) This statement is used in linking to another page in your directory (that
is, to another one of your web pages).
<A HREF="index.htm">enclosed text</A>
Page 28 of 145
Suppose you want to link from documentA.html to documentB.html In
documentA.html:
<a href = "documentB.html#linkname"> Text to activate link</a>
In documentB.html:
<a name ="linkname">Text that responds to the link</a>
HTML IMAGES
Images include Pictures, Graphics, Icons, Clip Art, Etc. Images can improve the
design and the appearance of a web page.
Page 29 of 145
While images can really add beauty to a web page, be careful that you do not overuse
them. It takes time for a browser to display an image and so a lot of images can take a
lot of time. Also, the bigger the image, the longer it will take to display. Many viewers
do not want to wait a long time.
1. HTML Images Syntax
The HTML <img> tag is used to embed an image in a web page.
Images are not technically inserted into a web page; images are linked to web
pages. The <img> tag creates a holding space for the referenced image.
The <img> tag is empty, it contains attributes only, and does not have a closing
tag.
The <img> tag has two required attributes:
src - Specifies the path to the image
alt - Specifies an alternate text for the image
Syntax
<img src="url" alt="alternatetext">
2. The src Attribute
The required src attribute specifies the path (URL) to the image.
Note: When a web page loads; it is the browser, at that moment that gets the
image from a web server and inserts it into the page. Therefore, make sure that
the image actually stays in the same spot in relation to the web page,
otherwise your visitors will get a broken link icon. The broken link icon and
the alt text are shown if the browser cannot find the image.
Example
<img src="img_chania.jpg" alt="Flowers in Chania">
3. The alt Attribute
The required alt attribute provides an alternate text for an image, if the user
for some reason cannot view it (because of slow connection, an error in the src
attribute).
The value of the alt attribute should describe the image:
Example
<img src="img_chania.jpg" alt="Flowers in Chania">
<img src="wrongname.gif" alt="Flowers in Chania">
4. Image Size - Width and Height
You can use the style attribute to specify the width and height of an image.
Example
Page 30 of 145
<img src="img_girl.jpg" alt="Girl in a jacket"
style="width:500px;height:600px;">
Alternatively, you can use the width and height attributes:
<img src="img_girl.jpg" alt="Girl in a jacket"
width="500" height="600">
The width and height attributes always define the width and height of the
image in pixels.
<body>
<img src="html5.gif" alt="HTML5 Icon" width="128"
height="128">
<img src="html5.gif" alt="HTML5 Icon"
style="width:128px;height:128px;">
</body>
5. Border and Align Attributes
The BORDER attribute is used to place (or eliminate) a border around the
image.
BORDER="0" turns it off border - that is, no border.
BORDER="0" a border of 10 pixels
The ALIGN attribute is used in conjunction with placing text around the
image. That is, ALIGN controls the alignment of the image with respect to
text.
<HTML>
<HEAD> <TITLE> HALL RENTAL </TITLE> </HEAD>
<BODY>
<H2 ALIGN="CENTER">ABOUT OUR HALL</H2>
<HR>
<H4 ALIGN="LEFT">
<IMG SRC="whechair.gif" BORDER="0"
ALIGN="MIDDLE"> We are wheelchair accessible.
</H4>
Please call for rates
<HR>
</BODY>
</HTML>
Change the ALIGN="MIDDLE" to ALIGN="BOTTOM". Change to
ALIGN="TOP"
The values TOP, MIDDLE and BOTTOM specify where any text following
the image should be placed. Remember that if more than one line follows after
the image, the additional lines will be placed below the image. You can also
Page 31 of 145
force text below such an aligned image by using the BR tag with the CLEAR
attribute as in <BR CLEAR>.
6. HSPACE Attribute
HSPACE and VSPACE indicate the number of pixels that should be left free
around the image
HSPACE used to create horizontal space around the image
VSPACE used to create vertical space around the image
<BODY>
<H2 ALIGN="CENTER">ABOUT OUR HALL</H2>
<HR>
<H4 ALIGN="LEFT">
<IMG SRC="whechair.gif" BORDER="0"
ALIGN="MIDDLE" WIDTH="60" HEIGHT="60" HSPACE="10"
ALT="chair"> We are wheelchair accessible.
</H4>
Please call for rates
<HR>
</BODY>
7. Images in another Folder
If you have your images in a sub-folder, you must include the folder name in
the src attribute:
Example
<img src="/images/html5.gif" alt="HTML5 Icon"
style="width:128px;height:128px;">
8. Images on another Server/Website
To point to an image on another server, you must specify an absolute (full)
URL in the src attribute:
Example
<img
src="https://www.w3schools.com/images/w3schools_gree
n.jpg" alt="W3Schools.com">
9. Image as a Link
To use an image as a link, put the <img> tag inside the <a> tag:
<a href="default.asp">
<img src="smiley.gif" alt="HTML tutorial"
style="width:42px;height:42px;">
</a>
<BODY>
<H4 ALIGN="CENTER">
<A HREF="index.htm">
Page 32 of 145
<IMG SRC="back.gif" WIDTH="40" HEIGHT="40"
HSPACE="10" ALIGN="MIDDLE" ALT="home">
</A>Click on the button to head home
</H4>
<HR>
</BODY>
10. Common Image Formats
Here are the most common image file types, which are supported in all
browsers (Chrome, Edge, Firefox, Safari, Opera):
Page 33 of 145
(b) Place the images into the same folder as the web page. Often if they are not
in the same folder, they do not get displayed. So your best results will occur
if the images are in the same folder as the web page
(c) If your images appear in your browser when you are working off-line, but
they do not appear in your browser after you have uploaded your web page
to the internet (to your host server), then make sure that you have also
uploaded each image to your host server. You not only have to upload your
web pages to your host server, but you also need to upload each individual
image.
12. Background Graphics
Using a feature called tiling, a browser takes the image and repeats it across and
down to fill your browser window.
<BODY BACKGROUND = “filename.gif”>
We can also use the HTML style attribute and the CSS background-image
property:
<div style="background-image: url('img_girl.jpg');">
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<!-- Styles -->
<style>
body {
background-image: url("/pix/samples/bg1.gif");
background-position: 50% 50%;
background-repeat: repeat;
}
</style>
</head>
<body>
<!-- HTML -->
<h3>Whole Page</h3>
<p>This example has a background image applied to the
<code>body</code> element.</p>
</body>
</html>
Page 34 of 145
HTML Lists
HTML lists allow web developers to group a set of related items in lists.
1. Unordered HTML List
An unordered list starts with the <ul> tag. Each list item starts with the <li> tag.
The list items will be marked with bullets (small black circles) by default:
Example
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
2. Ordered HTML List
An ordered list starts with the <ol> tag. Each list item starts with the <li> tag.
The list items will be marked with numbers by default:
Example
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
3. HTML Description Lists
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:
Example
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
Page 35 of 145
<dt> Defines a term in a description list
<dd> Describes the term in a description list
5. HTML Unordered Lists
The HTML <ul> tag defines an unordered (bulleted) list. An unordered list starts
with the <ul> tag. Each list item starts with the <li> tag.
The list items will be marked with bullets (small black circles) by default:
Example
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Example - Circle
<ul style="list-style-type:circle;">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Example - Square
<ul style="list-style-type:square;">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Example - None
<ul style="list-style-type:none;">
<li>Coffee</li>
Page 36 of 145
<li>Tea</li>
<li>Milk</li>
</ul>
7. Nested HTML Lists
Lists can be nested (list inside list):
Example
<ul>
<li>Coffee</li>
<li>Tea
<ul>
<li>Black tea</li>
<li>Green tea</li>
</ul>
</li>
<li>Milk</li>
</ul>
Note: A list item (<li>) can contain a new list, and other HTML elements, like
images and links, etc.
8. Horizontal List with CSS
HTML lists can be styled in many different ways with CSS.
One popular way is to style a list horizontally, to create a navigation menu:
Example
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 16px;
text-decoration: none;
}
li a:hover {
background-color: #111111;
}
Page 37 of 145
</style>
</head>
<body>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#news">News</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#about">About</a></li>
</ul>
</body>
</html>
9. HTML Ordered Lists
An ordered list starts with the <ol> tag. Each list item starts with the <li> tag.
The list items will be marked with numbers by default:
Example
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Uppercase Letters:
<ol type="A">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Lowercase Letters:
Page 38 of 145
<ol type="a">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Note: A list item (<li>) can contain a new list, and other HTML elements, like
images and links, etc.
13. HTML Other Lists
HTML also supports description lists.
14. HTML Description Lists
Page 39 of 145
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:
Example
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
<!DOCTYPE html>
<html>
<head>
<title>HTML Ordered List</title>
</head>
<body>
<ol type = "i">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
You can use start attribute for <ol> tag to specify the starting point of numbering you
need. Following are the possible options −
<ol type = "1" start = "4"> - Numerals starts with 4.
<ol type = "I" start = "4"> - Numerals starts with IV.
<ol type = "i" start = "4"> - Numerals starts with iv.
<ol type = "a" start = "4"> - Letters starts with d.
<ol type = "A" start = "4"> - Letters starts with D.
Example where we used <ol type = "i" start = "4" >
<!DOCTYPE html>
<html>
<head>
<title>HTML Ordered List</title>
</head>
<body>
<ol type = "i" start = "4">
Page 40 of 145
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
Example
<ol reversed>
<li>Item 3</li>
<li>Item 2</li>
<li>Item 1</li>
</ol>
Example
<style>
#nav {
background: lightgray;
overflow: auto;
}
#nav li {
float: left;
list-style-type: none;
padding: 10px;
}
</style>
<body>
<ul id="nav">
<li><a href="#Using_Lists_for_Menus">Home</a></li>
<li><a href="#Using_Lists_for_Menus">About Us</a></li>
<li><a href="#Using_Lists_for_Menus">Contact Us</a></li>
</ul>
Page 41 of 145
HTML Tables
HTML tables allow web developers to arrange data into rows and columns.
Other than arranging data in rows and columns tables can also be used :
1. To divide the page into various sections
2. To create menus
3. To add interactive form fields
4. To create fast loading headers of page
5. To achieve alignment of images
1. Define a HTML Table
The <table> tag defines an HTML table.
Each table row is defined with a <tr> tag.
Each table header is defined with a <th> tag.
By default, the text in <th> elements are bold and centered.
Each table data/cell is defined with a <td> tag.
By default, the text in <td> elements are regular and left-
aligned.
Example
<table border="10" bordercolor="red" bgcolor="yellow" >
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
Note: The <td> elements are the data containers of the table.
They can contain all sorts of HTML elements; text, images, lists, other tables, etc.
WIDTH attribute
Allows designers to set the width of the table using two methods, either as an
explicit value or a percentage value. e.g.
Page 42 of 145
<Table Width="80%"> Forces The Table To Take 90% of The Available Horizontal
Space.
Using CSS <table style="width:60%" >
2. HTML Table - Add a Border
This attribute sets the thickness of the borders surrounding the table. e.g.
<Table Border =”2”>
<table border="10" bordercolor="red" bgcolor="yellow" >
If no border is desired a value of BORDER=0 is given.
<table border="0" bordercolor="red" bgcolor="yellow" >
To add a border to a table, use the CSS border property:
Example
table, th, td {
border: 1px solid black;
}
Page 43 of 145
cell spacing specifies the space between the cells.
<table cellspacing = “20”>
<table border="20" align="center" cellspacing="40"
To set the border spacing for a table, use the CSS border-spacing property:
table {
border-spacing: 5px;
}
6. HTML Table - Cell that Spans Many Columns
To make a cell span more than one column, use the colspan attribute:
Example
<table style="width:100%">
<tr>
<th>Name</th>
<th colspan="2">Telephone</th>
</tr>
<tr>
<td>Bill Gates</td>
<td>55577854</td>
<td>55577855</td>
</tr>
</table>
7. HTML Table - Cell that Spans Many Rows
To make a cell span more than one row, use the rowspan attribute:
Example
<table style="width:100%">
<tr>
<th>Name:</th>
<td>Bill Gates</td>
</tr>
<tr>
<th rowspan="2">Telephone:</th>
<td>55577854</td>
</tr>
<tr>
<td>55577855</td>
</tr>
</table>
8. Row Group Elements
Table rows may be grouped into a table head, table foot and the table body
sections.
This division enables the browser to support scrolling of table body independent
of the table head and foot.
Table head and foot information can be repeated each page that contains table
data.
THEAD
Page 44 of 145
This contains the header information about the columns. This element defines a
group of header rows in a table.
The <thead> element is used in conjunction with the <tbody> and <tfoot>
elements to specify each part of a table (header, body, footer).
The <thead> element must have one or more <tr> tags inside
The <thead> tag must be used in the following context: As a child of a <table>
element, after any <caption> and <colgroup> elements, and before any <tbody>,
<tfoot>, and <tr> elements.
TFOOT
This contains the footer information about the columns. This element defines a
group of footer rows in a table.
TBODY
This defines a group of data rows in a table. A table must have one or more
TBODY element. It contains row groups
<html>
<head>
<style>
thead {color: green;}
tbody {color: blue;}
tfoot {color: red;}
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
</thead>
<tbody>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Sum</td>
<td>$180</td>
</tr>
</tfoot>
</table>
</body>
</html>
Page 45 of 145
9. HTML Table - Add a Caption
This gives the caption for the title of the table. The default position of the title is
centered at the top of the table.
It is only permitted after the TABLE tag.
It has the following align attribute values: ALIGN=BOTTOM, TOP, LEFT,
RIGHT
To add a caption to a table, use the <caption> tag:
Example
<table style="width:100%">
<caption>Monthly savings</caption>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$50</td>
</tr>
</table>
Note: The <caption> tag must be inserted immediately after the <table>
tag.
10. Summary
Use the HTML <table> element to define a table
Use the HTML <tr> element to define a table row
Use the HTML <td> element to define a table data
Use the HTML <th> element to define a table heading
Use the HTML <caption> element to define a table caption
Use the colspan attribute to make a cell span many columns
Use the rowspan attribute to make a cell span many rows
11. HTML Table Tags
Tag Description
<table> Defines a table
<th> Defines a header cell in a table
<tr> Defines a row in a table
<td> Defines a cell in a table
<caption> Defines a table caption
<colgroup> Specifies a group of one or more columns in a table for formatting
<col> Specifies column properties for each column within a <colgroup>
element
<thead> Groups the header content in a table
Page 46 of 145
<tbody> Groups the body content in a table
<tfoot> Groups the footer content in a table
Sample Program 1
<html>
<body text="blue" >
<table border="1" cellspacing="10" >
<tr>
<td bgcolor= "#888888">Column 1</td>
<td bgcolor="#ffff0">Column 2</td>
<td bgcolor="#aaaa">Column 3</td>
</tr>
<tr>
<td rowspan="2">Row 1 Cell 1</td>
<td bgcolor="yellow" >Row 1 Cell 2</td>
<td bgcolor="green" >Row 1 Cell 3</td>
</tr>
<tr>
<td bgcolor= "rgb(255,255,0)" >Row 2 Cell
2</td>
<td bgcolor= "rgb(0,255,0)" >Row 2 Cell
3</td>
</tr>
<tr>
<td colspan="3">Row 3 Cell 1</td>
</tr>
</table>
</body>
</html>
Sample Program 2
<html >
<head>
<title>Tables</title>
</head>
<body>
<h1>Table Example Page</h1>
<table border = "1">
<caption>Here is a sample table.</caption>
<thead>
<tr>
<!-- merge two rows -->
<th rowspan = "2">
<img src = "camel.gif" width = "205" height
=
"167" alt = "Picture of a camel" />
</th>
<!-- merge four columns -->
<th colspan =" 4" >
<h1> Camelid Comparison</h1>
<p> Approximate as of 6/2007</p>
</th>
</tr>
<tr>
Page 47 of 145
<th># of Humps</th>
<th>Indigenous region</th>
<th>Spits?</th>
<th>Produces Wool?</th>
</tr>
</thead>
<tbody>
<tr>
<th>Camels (bactrian)</th>
<td>2</td>
<td>Africa/Asia</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<th>Llamas</th>
<td>1</td>
<td>Andes Mountains</td>
<td>Yes</td>
<td>Yes</td>
</tr>
</tbody>
</table>
<p>
<table border="1">
<tr>
<td width="50%">
<ul>
<li>List Item 1</li>
<li>List Item 2</li>
<li>List Item 3</li>
</ul>
</td>
<td>
<ul>
<li>List Item 4</li>
<li>List Item 5</li>
<li>List Item 6</li>
</ul>
</td>
</tr>
<tr>
<td>
<p>Avoid losing floppy disks with
important school...</p>
</td>
<td>
<a href="http://www.espn.com"
target="_blank" rel="nofollow">
<img
src="http://www.Facebook.com/pics
/htmlT/ahman.gif"/>
</a>
</td>
</tr>
</table>
Page 48 of 145
</body>
</html>
Sample Program 3
<html>
<head>
<title>Lists</title>
</head>
<body>
<h1>The Best Features of the Internet</h1>
<!-- create an unordered list -->
<ul>
<li>You can meet new people from countries around the
world.</li>
<li>You have access to new media as it becomes public:
<ul>
<li>New games</li>
<li>Around the clock news</li>
<li>Search engines</li>
<li>Shopping</li>
</ul> <!-- ends the nested list of line-->
</li>
<li>New applications
<!-- nested ordered list -->
<ol>
<li>For business</li>
<li>For pleasure</li>
</ol>
</li> <!-- ends line 27 new applications li -->
<li>Programming <!-- another nested ordered list -->
<ol>
<li>XML</li>
<li>Java</li>
<li>XHTML</li>
<li>Scripts</li>
<li>New languages</li>
</ol>
</li> <!-- ends programming li of line -->
<li>Links</li>
<li>Keeping in touch with old friends</li>
<li>It is the technology of the future!</li>
</ul> <!-- ends the unordered list of line -->
</body>
</html>
Sample Program 4
<html>
<head>
<title> Navigation Bar</title>
</head>
<body>
<p>
<a href = "list.html">
<img src = "buttons/list.jpg" width = "65" height = "50"
alt = "List Example Page" />
</a>
Page 49 of 145
<a href = "contact.html">
<img src = "buttons/contact.jpg" width = "65" height =
"50" alt = "Contact Page" />
</a>
<a href = "table1.html">
<img src = "buttons/table.jpg" width = "65" height =
"50" alt = "Table Page" />
</a>
<a href = "form.html">
<img src = "buttons/form.jpg" width = "65" height = "50"
alt = "Feedback Form" />
</a>
</p>
<p>if x < 10 then increment x by 1</p>
</body>
</html>
Page 50 of 145
HTML – Frames
1. Introduction to frames
HTML frames are used to divide your browser window into multiple sections
where each section can load a separate HTML document.
Multiple views offer designers a way to keep certain information visible, while other
views are scrolled or replaced. For example, within the same window, one frame
might display a static banner, a second a navigation menu, and a third the main
document that can be scrolled through or replaced by navigating in the second
frame.
A collection of frames in the browser window is known as a frameset.
The window is divided into frames in a similar way the tables are organized: into
rows and columns.
2. Disadvantages of Frames
There are few drawbacks with using frames, so it's never recommended to use
frames in your webpages −
i.) Some smaller devices cannot cope with frames often because their screen is
not big enough to be divided up.
ii.) Sometimes your page will be displayed differently on different computers
due to different screen resolution.
iii.) The browser's back button might not work as the user hopes thus causing
navigational issues to users.
iv.) There are still few browsers that do not support frame technology.
v.) Using HTML frames is not good for SEO (the content of your frame is just
invisible for major search engines);
vi.) You cannot add internal links of the website built with HTML frames to
your favorites
3. Creating Frames
To use frames on a page we use <frameset> tag instead of <body> tag.
The <frameset> tag defines, how to divide the window into frames.
The rows attribute of <frameset> tag defines horizontal frames and cols attribute
defines vertical frames.
Each frame is indicated by <frame> tag and it defines which HTML document
shall open into the frame.
Note − The <frame> tag deprecated in HTML5.
Example
Following is the example to create three horizontal frames −
Page 51 of 145
<!DOCTYPE html>
<html>
<head>
<title>HTML Frames</title>
</head>
<noframes>
<body>Your browser does not support frames.</body>
</noframes>
</frameset>
</html>
Example
This creates three frames vertically −
<!DOCTYPE html>
<html>
<head>
<title>HTML Frames</title>
</head>
<noframes>
<body>Your browser does not support frames.</body>
</noframes>
</frameset>
</html>
4. The <frameset> Tag Attributes
Following are important attributes of the <frameset> tag −
Attribute & Description
cols
Specifies how many columns are contained in the frameset and the size of
each column. You can specify the width of each column in one of the four
ways −
i.) Absolute values in pixels. For example, to create three vertical frames,
use cols = "100, 500, 100".
ii.) A percentage of the browser window. For example, to create three
vertical frames, use cols = "10%, 80%, 10%".
iii.) Using a wildcard symbol. For example, to create three vertical frames,
use cols = "10%, *, 10%". In this case wildcard takes remainder of the
window.
Page 52 of 145
iv.) As relative widths of the browser window. For example, to create three
vertical frames, use cols = "3*, 2*, 1*".
This is an alternative to percentages.
You can use relative widths of the browser window.
Here the window is divided into sixths: the first column takes up half of
the window, the second takes one third, and the third takes one sixth.
rows
This attribute works just like the cols attribute and takes the same values,
but it is used to specify the rows in the frameset.
For example, to create two horizontal frames, use rows = "10%, 90%".
You can specify the height of each row in the same way as explained above
for columns.
border
This attribute specifies the width of the border of each frame in pixels.
For example, border = "5".
A value of zero means no border.
frameborder
This attribute specifies whether a three-dimensional border should be
displayed between frames. This attribute takes value either 1 (yes) or 0
(no). For example frameborder = "0" specifies no border.
framespacing
This attribute specifies the amount of space between frames in a frameset.
This can take any integer value. For example framespacing = "10" means
there should be 10 pixels spacing between each frames.
Page 53 of 145
This attribute allows you to specify the width of the space between the left
and right of the frame's borders and the frame's content.
The value is given in pixels. For example marginwidth = "10".
marginheight
This attribute allows you to specify the height of the space between the top
and bottom of the frame's borders and its contents.
The value is given in pixels. For example marginheight = "10".
noresize
By default, you can resize any frame by clicking and dragging on the
borders of a frame.
The noresize attribute prevents a user from being able to resize the frame.
For example noresize = "noresize".
scrolling
This attribute controls the appearance of the scrollbars that appear on the
frame.
This takes values either "yes", "no" or "auto". For example scrolling = "no"
means it should not have scroll bars.
longdesc
This attribute allows you to provide a link to another page containing a
long description of the contents of the frame.
For example longdesc = "framedescription.htm"
<head>
<title>HTML Target Frames</title>
</head>
Page 54 of 145
<noframes>
<body>Your browser does not support frames.</body>
</noframes>
</frameset>
</html>
Here, we have created two columns to fill with two frames. The first frame is 200
pixels wide and will contain the navigation menu bar implemented by menu.html
file.
The second column fills in remaining space and will contain the main part of the
page and it is implemented by main.html file.
For all the three links available in menu bar, we have mentioned target frame as
main_page, so whenever you click any of the links in menu bar, available link
will open in main page.
Following is the content of menu.htm file
<!DOCTYPE html>
<html>
</html>
<!DOCTYPE html>
<html>
</html>
The target attribute can also take one of the following values −
Page 55 of 145
_self
Loads the page into the current frame.
_blank
Loads a page into a new browser window. Opening a new window.
_parent
Loads the page into the parent window, which in the case of a single
frameset is the main browser window.
_top
Loads the page into the browser window, replacing any current frames.
targetframe
Loads the page into a named targetframe.
HTML - Iframes
You can define an inline frame with HTML tag <iframe>.
The <iframe> tag is not somehow related to <frameset> tag, instead, it can appear
anywhere in your document.
The <iframe> tag defines a rectangular region within the document in which the
browser can display a separate document, including scrollbars and borders.
An inline frame is used to embed another document within the current HTML
document.
An HTML iframe is used to display a web page within a web page.
The src attribute is used to specify the URL of the document that occupies the
inline frame.
Example
Following is the example to show how to use the <iframe> −
<!DOCTYPE html>
<html>
<head>
<title>HTML Iframes</title>
</head>
<body>
<p>Document content goes here...</p>
</html>
Page 56 of 145
Most of the attributes of the <iframe> tag, including name, class, frameborder, id,
longdesc, marginheight, marginwidth, name, scrolling, style, and title behave
exactly like the corresponding attributes for the <frame> tag.
Note − The frameborder, marginwidth, longdesc, scrolling, marginheight
attributes deprecated in HTML5. Do not use these attributes.
Attribute & Description
src
This attribute is used to give the file name that should be loaded in the
frame. Its value can be any URL.
For example, src = "/html/top_frame.htm" will load an HTML file
available in html directory.
name
This attribute allows you to give a name to a frame.
It is used to indicate which frame a document should be loaded into.
This is especially important when you want to create links in one frame
that load pages into an another frame, in which case the second frame
needs a name to identify itself as the target of the link.
frameborder
This attribute specifies whether or not the borders of that frame are
shown; it overrides the value given in the frameborder attribute on the
<frameset> tag if one is given, and this can take values either 1 (yes) or
0 (no).
marginwidth
This attribute allows you to specify the width of the space between the
left and right of the frame's borders and the frame's content.
The value is given in pixels. For example marginwidth = "10".
marginheight
This attribute allows you to specify the height of the space between the
top and bottom of the frame's borders and its contents.
The value is given in pixels. For example marginheight = "10".
height
This attribute specifies the height of <iframe>.
scrolling
This attribute controls the appearance of the scrollbars that appear on
the frame. This takes values either "yes", "no" or "auto".
For example scrolling = "no" means it should not have scroll bars.
longdesc
This attribute allows you to provide a link to another page containing a
long description of the contents of the frame.
For example longdesc = "framedescription.htm"
width
This attribute specifies the width of <iframe>.
Summary
Page 57 of 145
The <frameset> and </frameset> attributes are used instead of the <body>
tag in the HTML document that consists of frames.
The <frame /> attribute contains the name of a frame, the name and id
attributes and the URL of the HTML page that is displayed in this frame.
The <iframe> and </iframe> attributes allow to set a frame in a regular
HTML document.
The <noframes> and </noframes> attributes contain alternative information
for the browsers that do not support frames.
Sample Program 1
<HTML>
<HEAD>
<TITLE>A simple frameset document</TITLE>
</HEAD>
<FRAMESET cols="20%, 80%">
<FRAMESET rows="100, 200">
<FRAME src="contents_of_frame1.html">
<FRAME src="contents_of_frame2.gif">
</FRAMESET>
<FRAME src="contents_of_frame3.html">
<NOFRAMES>
<P>This frameset document contains:
<UL>
<LI><A href="contents_of_frame1.html">Some neat contents</A>
<LI><IMG src="contents_of_frame2.gif" alt="A neat image">
<LI><A href="contents_of_frame3.html">Some other neat
contents</A>
</UL>
</NOFRAMES>
</FRAMESET>
</HTML>
Sample Program 2
<HTML>
<HEAD>
<TITLE>A frameset document</TITLE>
</HEAD>
<FRAMESET cols="33%,33%,33%">
<FRAMESET rows="*,200">
<FRAME src="contents_of_frame1.html">
<FRAME src="contents_of_frame2.gif">
</FRAMESET>
<FRAME src="contents_of_frame3.html">
<FRAME src="contents_of_frame4.html">
</FRAMESET>
</HTML>
Sample Program 3
<HTML>
<HEAD>
Page 58 of 145
<TITLE>A frameset document</TITLE>
</HEAD>
<FRAMESET cols="33%,33%,33%">
<FRAMESET rows="*,200">
<FRAME src="contents_of_frame1.html" scrolling="no">
<FRAME src="contents_of_frame2.gif"
marginwidth="10" marginheight="15" noresize>
</FRAMESET>
<FRAME src="contents_of_frame3.html" frameborder="0">
<FRAME src="contents_of_frame4.html" frameborder="0">
</FRAMESET>
</HTML>
Sample program 4
<HTML>
<HEAD>
<TITLE>A frameset document</TITLE>
</HEAD>
<FRAMESET rows="50%,50%">
<FRAME name="fixed" src="init_fixed.html">
<FRAME name="dynamic" src="init_dynamic.html">
</FRAMESET>
</HTML>
<HTML>
<HEAD>
<TITLE>A document with anchors with specific targets</TITLE>
</HEAD>
<BODY>
...beginning of the document...
<P>Now you may advance to
<A href="slide2.html" target="dynamic">slide 2.</A>
...more document...
<P>You're doing great. Now on to
<A href="slide3.html" target="dynamic">slide 3.</A>
</BODY>
</HTML>
Activating either link opens a new document in the frame named "dynamic" while the
other frame, "fixed", maintains its initial contents.
Note. A frameset definition never changes, but the contents of one of its frames can.
Once the initial contents of a frame change, the frameset definition no longer reflects
the current state of its frames.
There is currently no way to encode the entire state of a frameset in a URI. Therefore,
many user agents do not allow users to assign a bookmark to a frameset.
Framesets may make navigation forward and backward through your user agent's
history more difficult for users.
Page 59 of 145
Sample program 4
Use the <iframe> tag to embed another document within the current HTML
document:
Sample Program 5
Page 60 of 145
HTML <meta> Tag
The <meta> tag defines metadata about an HTML document. Metadata is data
(information) about data.
<meta> tags always go inside the <head> element, and are typically used to specify
character set, page description, keywords, author of the document, and viewport settings.
Metadata will not be displayed on the page, but is machine parsable.
Metadata is used by browsers (how to display content or reload page), search engines
(keywords), and other web services.
It has a method that lets web designers take control over the viewport (the user's visible
area of a web page)
Examples
1. Define keywords for search engines:
<meta name="keywords" content="HTML, CSS, JavaScript">
2. Define a description of your web page:
<meta name="description" content="Free Web tutorials for HTML and CSS">
3. Define the author of a page:
<meta name="author" content="Hudson Wanjau">
4. Refresh document every 30 seconds:
<meta http-equiv="refresh" content="30">
5. Setting the viewport to make your website look good on all devices:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
The viewport is the user's visible area of a web page. It varies with the device - it will
be smaller on a mobile phone than on a computer screen.
You should include the following <meta> element in all your web pages:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
This gives the browser instructions on how to control the page's dimensions and
scaling.
Example:
<head>
<meta charset="UTF-8">
<meta name="description" content="Free Web tutorials">
<meta name="keywords" content="HTML, CSS, JavaScript">
<meta name="author" content="John Doe">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
</head>
HTML Colors
1. Introduction
Page 61 of 145
Colors ca be specified on page level using <body> tag or they can be set colors for
individual tags using bgcolor attribute.
The <body> tag has following attributes which can be used to set different colors −
bgcolor − sets a color for the background of the page.
text − sets a color for the body text.
alink − sets a color for active links or selected links.
link − sets a color for linked text.
vlink − sets a color for visited links − that is, for linked text that you have
already clicked on.
2. HTML Color Coding Methods
There are following three different methods to set colors in your web page −
i) Color names − You can specify color names directly like green, blue or red.
ii) Hex codes − A six-digit code representing the amount of red, green, and blue
that makes up the color.
iii) Color decimal or percentage values − This value is specified using the rgb( )
property.
HTML Colors - Color Names Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Colors by Name</title>
</head>
</html>
<head>
<title>HTML Colors by Hex</title>
Page 62 of 145
</head>
</html>
<head>
<title>HTML Colors by RGB code</title>
</head>
</html>
3. HTML - Backgrounds
By default, your webpage background is white in color. You may not like it, but
no worries. HTML provides you following two good ways to decorate your
webpage background.
HTML Background with Colors
Page 63 of 145
The bgcolor attribute is used to control the background of an HTML
element, specifically page body and table backgrounds.
<table bgcolor = "#6666FF" width = "100%">
<table bgcolor = "yellow" width = "100%">
<table bgcolor = "rgb(255,0,255)" width = "100%">
HTML Background with Images
You can specify an image to set background of your HTML page or table.
<table background = "/images/html.gif" width = "100%"
height = "100">
<table background = "/images/pattern1.gif" width = "100%"
height = "100">
4. HTML - Fonts
Fonts play a very important role in making a website more user friendly and
increasing content readability. Font face and color depends entirely on the
computer and browser that is being used to view your page
HTML <font> tag can be used to add style, size, and color to the text.
You can use a <basefont> tag to set all of your text to the same size, face, and
color.
The font tag is having three attributes called size, color, and face to customize
your fonts.
Note −The font and basefont tags are deprecated , it's suggested to use CSS
styles to manipulate your fonts.
Set Font Size Example
<html>
<head>
<title>Setting Font Size</title>
</head>
<body>
<font size = "1">Font size = "1"</font><br />
<font size = "2">Font size = "2"</font><br />
<font size = "3">Font size = "3"</font><br />
<font size = "4">Font size = "4"</font><br />
<font size = "5">Font size = "5"</font><br />
<font size = "6">Font size = "6"</font><br />
<font size = "7">Font size = "7"</font>
</body>
</html>
Page 64 of 145
<body>
<font face = "Times New Roman" size = "5">Times New
Roman</font><br />
<font face = "Verdana" size = "5">Verdana</font><br />
<font face = "Comic sans MS" size =" 5">Comic Sans
MS</font><br/>
<font face = "WildWest" size = "5">WildWest</font><br
/>
<font face = "Bedrock" size = "5">Bedrock</font><br />
</body>
Setting Font Color Example
<head>
<title>Setting Font Color</title>
</head>
<body>
<font color = "#FF00FF">This text is in
pink</font><br/>
<font color = "red">This text is red</font>
</body>
<head>
<title>Setting Basefont Color</title>
</head>
<body>
<basefont face = "arial, verdana, sans-serif" size = "2"
color = "#ff0000">
<p>This is the page's default font.</p>
<h2>Example of the <basefont> Element</h2>
Page 65 of 145
</html>
Page 66 of 145
Attribute Value Description
with input parameters of the request contained within
the body of the request
name text Specifies the name of a form
novalidate novalidate Specifies that the form should not be validated when
submitted
rel external Specifies the relationship between a linked resource and
help the current document
license
next
nofollow
noopener
noreferrer
opener
prev
search
target _blank Specifies where to display the response that is received
_self after submitting the form
_parent
_top
Page 67 of 145
<form action="/action_page.php" method="get">
<input type="radio" id="male" name="gender" value="male">
<label for="male">Male</label>
<br>
<input type="radio" id="female" name="gender" value="female"
checked="checked">
<label for="female">Female</label>
<br>
<input type="radio" id="other" name="gender" value="other">
<label for="other">Other</label>
<br><br>
<input type="submit" value="Submit">
</form>
a form that includes labels, radio buttons, email, file, & push buttons (reset the
form or submit it):
<form action="http://somesite.com/prog/adduser" method="post">
<p>
<label for="firstname">First name: </label>
<input type="text" id="firstname">
<br>
<label for="lastname">Last name: </label>
<input type="text" id="lastname">
<br>
<label for="email">Email: </label>
<input type="email" id="email" >
<br>
<label for="search">Search: </label>
<input type="search" name="search" >
<br>
<label for="Url">Enter URL Address: </label>
<input type="search" name="url" autofocus >
<br>
Page 68 of 145
<input type="hidden" name="something" value="A line of
content">
<p>
What is your home page URL?<br>
<input type="text" name="url" size="17" maxlength="44">
</p>
<p>
What is your password?<br>
<input type="password" name="P" size="9" maxlength="20">
</p>
<p>
Select one or more colors that you like:<br>
<input type="checkbox" name="c_blue" value="yes">
<input type="checkbox" name="c_red" value="yes" CHECKED>
<input type="checkbox" name="c_pink" value="yes" CHECKED>
<input type="checkbox" name="c_yellow" value="yes">
</p>
<p>
What is your favorite color?<br>
<input type="radio" name="color" value="blue">
<input type="radio" name="color" value="red" CHECKED>
<input type="radio" name="color" value="pink">
</p>
<p>
Upload any type of file:<br>
<input type="file" name="upfile">
</p>
<p>
<input type="button" value="Give me a message" onClick="return
alert('a message')">
<!-- Note: onClick works only with JavaScript enabled browsers. -->
</p>
<p>
Tell me why you are here!<br>
<textarea name="message" cols="20" rows="5"></textarea>
</p>
<p>
What is your most <b><u>un</u></b>favorite color:<br>
<select name="s_unfav">
<option value="green">Green</option>
<option value="red">Red</option>
<option value="blue" SELECTED>Blue</option>
<option value="yellow">Yellow</option>
<option value="pink">Pink</option>
</select>
</p>
<p>
Select one or more colors you do not like:<br>
<select name="s_like" size="4" MULTIPLE>
<option value="green">Green</option>
<option value="red" SELECTED>Red</option>
<option value="blue" SELECTED>Blue</option>
<option value="yellow">Yellow</option>
<option value="pink">Pink</option>
</select>
</p>
<p>
Page 69 of 145
<input type="image" name="imageclick" src="myimage.gif" border="0">
</p>
<p>
<input type="reset" value="Erase Everything!">
</p>
<p>
<input type="submit" name="1" value="This is my first visit">
</p>
<p>
<input type="submit" name="2"value="I've been here before">
</p>
</form>
Another Example
<HTML>
<HEAD>
<TITLE>Land Of Boxes Form</TITLE>
</HEAD>
<BODY>
<H1><FONT SIZE="5" COLOR="coral">Land Of Boxes Order Form</FONT></H1>
<FORM METHOD="post" ACTION="mailto:[email protected]">
<TABLE>
<TR>
<TD ALIGN="right">Name:</TD>
<TD><INPUT TYPE="text" NAME="name" SIZE="35"></TD>
</TR>
<TR>
<TD ALIGN="right">Email:</TD>
<TD><INPUT TYPE="text" NAME="email" SIZE="35" VALUE=""></TD>
</TR>
<TR>
<TD ALIGN="right">Address:</TD>
<TD><TEXTAREA NAME="address" COLS="30" ROWS="5"></TEXTAREA></TD>
</TR>
<TR>
<TD ALIGN="right">Postcode:</TD>
<TD><INPUT TYPE="text" NAME="postcode" SIZE="20"></TD>
</TR>
</TABLE><BR><BR>
<TABLE BORDER=1>
<TR>
<TD><B>Product</B></TD>
<TD><B>Part Number</B></TD>
<TD><B>Quantity</B></TD>
<TD><B>Unit Price</B></TD>
<TD><B>Subtotal</B></TD>
</TR>
<TR>
<TD>EconoBox</TD><TD>LB100</TD>
<TD><INPUT type="text" name="Qlb100" size="8"></TD>
<TD>R5</TD>
<TD><INPUT type="text" name="Sublb100" size="15"
value="R"></TD>
</TR>
<TR>
<TD>Standard Box</TD><TD>LB200</TD>
Page 70 of 145
<TD><INPUT type="text" name="Qlb200" size="8"></TD>
<TD>R10</TD>
<TD><INPUT type="text" name="Sublb200" size="15"
value="R"></TD>
</TR>
<TR>
<TD>Premium Box</TD><TD>LB300</TD>
<TD><INPUT type="text" name="Qlb300"
size="8"></TD><TD>R15</TD>
<TD><INPUT type="text" name="Sublb300" size="15"
value="R"></TD>
</TR>
<TR>
<TD>Deluxe Box</TD><TD>LB400</TD>
<TD><INPUT type="text" name="Qlb400"
size="8"></TD><TD>R20</TD>
<TD><INPUT type="text" name="Sublb400" size="15"
value="R"></TD>
</TR>
<TR>
<TD>Super Deluxe Box</TD><TD>LB500</TD>
<TD><INPUT type="text" name="Qlb500"
size="8"></TD><TD>R30</TD>
<TD><INPUT type="text" name="Sublb500" size="15"
value="R"></TD>
</TR>
<TR>
<TD COLSPAN=5 ALIGN="right">
Total: <INPUT type="text" name="total" size="15"
value="R"></TD>
</TR>
</TABLE><BR><BR>
<B>Credit Card Details</B><BR>
<TABLE>
<TR>
<TD>Card Type:</TD>
</TR>
<TR>
<TD><INPUT type="radio" name="cardmake"
value="master">Mastercard</TD>
<TD>Card Number:</TD>
<TD><INPUT type="text" name="cardnumber"
size="20"></TD>
</TR>
<TR>
<TD><INPUT type="radio" name="cardmake"
value="visa">Visa</TD>
<TD>Expiry date:</TD>
<TD><INPUT type="text" name="expiry" size="10"
maxlength="5" value="mm/yy"></TD
</TR>
<TR>
<TD><INPUT type="radio" name="cardmake"
value="amex">American Express</TD>
</TR>
<TR>
Page 71 of 145
<TD><INPUT type="radio" name="cardmake"
value="diners">Diners Club</TD>
</TR>
</TABLE><BR><BR>
<TABLE>
<TR>
<TD ALIGN="right"><B>Delivery Address:</B></TD>
<TD><TEXTAREA NAME="delivery" COLS="25"
ROWS="5"></TEXTAREA></TD>
</TR>
</TABLE><BR><BR>
<INPUT type="submit" name="submit" value="Send order">
<INPUT type="reset" name="reset" value="Clear form">
</FORM>
</BODY>
</HTML>
4. Control types
Users interact with forms through controls. HTML defines the following control
types:
a) Buttons
Authors may create three types of buttons:
i) Submit buttons: When activated, a submit button submits a form.
ii) Reset buttons: When activated, a reset button resets all controls to their
initial values.
iii) Push buttons: Push buttons have no default behavior. Each push button
may have client-side scripts associated with the element's event
attributes. When an event occurs (e.g., the user presses the button,
releases it, etc.), the associated script is triggered.
b) Checkboxes
Checkboxes (and radio buttons) are on/off switches that may be toggled by the
user. A switch is "on" when the control element's checked attribute is set.
Several checkboxes in a form may share the same control name.
c) Radio Buttons
Radio buttons are like checkboxes except that when several share the same control
name, they are mutually exclusive: when one is switched "on", all others with the
same name are switched "off". The INPUT element is used to create a radio button
control.
At all times, exactly one of the radio buttons in a set is checked.
d) Menus
Menus offer users options from which to choose. The SELECT element
creates a menu, in combination with the OPTGROUP and OPTION elements.
e) Text Input
Page 72 of 145
Authors may create two types of controls that allow users to input text.
The INPUT element creates a single-line input control and
The TEXTAREA element creates a multi-line input control.
f) File select
This control type allows the user to select files so that their contents may be
submitted with a form. The INPUT element is used to create a file select
control.
g) Hidden Controls
Authors may create controls that are not rendered but whose values are submitted
with a form. Authors generally use this control type to store information between
client/server exchanges that would otherwise be lost due to the stateless nature of
HTTP. The INPUT element is used to create a hidden control.
Page 73 of 145
url For web addresses. You can use the multiple attribute to enter
more than one URL
Dates and HTML 5 enables sate pickers.
Times <input id="dob" name="dob" type="date">
<input id="expiry" name="expiry" type="month"
required>
<input id="time" name="time" type="time">
Numbers as HTML5 can create an input field that accepts minimum and
Spinboxes maximum numbers and then you can be able to scroll through the
numbers and pick one.
<input type="number" min="0" max="10" step="1"
value="0">
type="number" means that this is a number field
min="0" specifies the minimum acceptable value for this field.
max="10" is the maximum acceptable value.
step="1", combined with the min value, defines the acceptable
numbers in the range: 0, 1, 2, and so on, up to the maxvalue.
value="0" is the default value that displays before selecting another
number.
Numbers as <input type="range" min="0" max="10" step="1" value="0">
Sliders
Page 74 of 145
7. The SELECT and OPTION elements
The <select> tag is used to construct drop-down list boxes (sometimes called
drop-down menus) and scrolling list boxes (sometimes called scrolling menus)
SELECT Attribute definitions
name = cdata
This attribute assigns the control name.
size = number
If a SELECT element is presented as a scrolled list box, this attribute
specifies the number of rows in the list that should be visible at the same
time.
multiple
If set, this boolean attribute allows multiple selections. If not set, the
SELECT element only permits single selections.
<form method="POST" action="/cgi-bin/handler.cgi">
<select name="myselect" size="4" MULTIPLE>
<option value="1">First</option>
<option value="2" SELECTED>Second</option>
<option value="3">Third</option>
<option value="4" SELECTED>Fourth</option>
<option value="5">Fifth</option>
</select>
<input type="submit">
</form>
OPTION Attribute definitions
selected
When set, this boolean attribute specifies that this option is pre-selected.
value = cdata
This attribute specifies the initial value of the control. If this attribute is
not set, the initial value is set to the contents of the OPTION element.
<FORM action="http://somesite.com/prog/component-select"
method="post">
<P>
<SELECT multiple size="4" name="component-select">
<OPTION selected value="Component_1_a">Component_1</OPTION>
<OPTION selected value="Component_1_b">Component_2</OPTION>
<OPTION>Component_3</OPTION>
<OPTION>Component_4</OPTION>
<OPTION>Component_5</OPTION>
<OPTION>Component_6</OPTION>
<OPTION>Component_7</OPTION>
</SELECT>
<INPUT type="submit" value="Send"><INPUT type="reset">
Page 75 of 145
</P>
</FORM>
9. Labels
Some form controls automatically have labels associated with them (press buttons)
while most do not (text fields, checkboxes and radio buttons, and menus).
For those controls that have implicit labels, user agents should use the value of the
value attribute as the label string.
The LABEL element is used to specify labels for controls that do not have implicit
labels,
Page 76 of 145
The for attribute associates a label with another control explicitly: the value of the for
attribute must be the same as the value of the id attribute of the associated control
element.
The example below has a form that one might fill out at the doctor's office. It is
divided into three sections: personal information, medical history, and current
medication. Each section contains controls for inputting the appropriate information.
Page 77 of 145
type="checkbox"
value="Sneezing" tabindex="23"> Sneezing
...more medical history...
</FIELDSET>
<FIELDSET>
<LEGEND>Current Medication</LEGEND>
Are you currently taking any medication?
<INPUT name="medication_now"
type="radio"
value="Yes" tabindex="35">Yes
<INPUT name="medication_now"
type="radio"
value="No" tabindex="35">No
Similarly, an author may want to include a piece of read-only text that must be
submitted as a value along with the form.
Note. The only way to modify dynamically the value of the disabled attribute is
through a script.
Note. The only way to modify dynamically the value of the readonly attribute is
through a script.
Page 78 of 145
The "get" method should be used when the form is idempotent (i.e., causes no side-
effects). Many database searches have no visible side-effects and make ideal
applications for the "get" method.
If the service associated with the processing of a form causes side effects (for
example, if the form modifies a database or subscription to a service), the "post"
method should be used.
Hidden controls and controls that are not rendered because of style sheet settings may
still be successful.
Page 79 of 145
Step four: Submit the encoded form data set
Finally, the encoded data is sent to the processing agent designated by the action
attribute using the protocol specified by the method attribute.
This specification does not specify all valid submission methods or content types that
may be used with forms. However, HTML 4 user agents must support the established
conventions in the following cases:
If the method is "get" and the action is an HTTP URI, the user agent takes the
value of action, appends a `?' to it, then appends the form data set, encoded
using the "application/x-www-form-urlencoded" content type. The user agent
then traverses the link to this URI. In this scenario, form data are restricted to
ASCII codes.
If the method is "post" and the action is an HTTP URI, the user agent
conducts an HTTP "post" transaction using the value of the action attribute
and a message created according to the content type specified by the enctype
attribute.
For any other value of action or method, behavior is unspecified.
User agents should render the response from the HTTP "get" and "post" transactions.
Processing Forms
HTML forms supply a way for the user to interact with a Web server. The most
widely used method to process the data submitted through a form is to send it to
server-side software typically written in a scripting language. The figure below
outlines the kind of processing that takes place.
5
Web CGI
Server Software
7
1 Server Side
4
Client Side
HTML
Document
with Form 8
2
3 New HTML
9 Document produced
by CGI Script
10
Page 80 of 145
1. The user retrieves a document containing a form from a Web server.
2. The user reads the Web page and interacts with the form it contains.
3. Submitting the form sends the form data to the server for processing.
4. The Web server passes the data to a CGI program.
5. The CGI software may use database information or store data in a server-side database.
6. The CGI software may generate a new Web page for the server to return to the
user.
7. The user reads the new Web document and may interact with it.
Note:
The elements used to create controls generally appear inside a FORM
element, but may also appear outside of a FORM element declaration when
they are used to build user interfaces.
Note that controls outside a form cannot be successful controls.
When a form is submitted for processing, some controls have their name
paired with their current value and these pairs are submitted with the form.
Those controls for which name/value pairs are submitted are called successful
controls.
Assignment
Job Application Form
Create an on-line job application form. The application form is for a computer
company called SpeedyPC who are advertising for computer programmers. Your
form’s action should post the application to the email address:
[email protected].
Page 81 of 145
HTML – HEADER
1. Introduction
The <head> tag is a container of various important tags like <title>, <meta>, <link>,
<base>, <style>, <script>, and <noscript> tags.
2. The HTML <title> Tag
The HTML <title> tag is used for specifying the title of the HTML document.
3. The HTML <meta> Tag
The HTML <meta> tag is used to provide metadata about the HTML document
which includes information about page expiry, page author, list of keywords,
page description etc.
4. The HTML <base> Tag
The HTML <base> tag is used for specifying the base URL for all relative URLs in a
page, which means all the other URLs will be concatenated into base URL while
locating for the given item. For example, all the given pages and images will be
searched after prefixing the given URLs with base URL
http://www.tutorialspoint.com/ directory:
<html>
<head>
<title>HTML Base Tag Example</title>
<base href="http://www.tutorialspoint.com/" />
</head>
<body>
<img src="/images/logo.png" alt="Logo Image"/>
<a href="/html/index.htm" title="HTML Tutorial"/>HTML Tutorial</a>
</body>
</html>
5. The HTML <link> Tag
The HTML <link> tag is used to specify relationships between the current document
and external resource. Following is an example to link an external style sheet
file available in css sub-directory within web root:
<html>
<head>
<title>HTML link Tag Example</title>
<base href="http://www.tutorialspoint.com/" />
<link rel="stylesheet" type="text/css" href="/css/style.css">
</head>
<body>
<p>Hello, World!</p>
</body>
</html>
6. The HTML <style> Tag
The HTML <style> tag is used to specify style sheet for the current HTML
document.
Page 82 of 145
Following is an example to define few style sheet rules inside <style> tag:
<html>
<head>
<title>HTML style Tag Example</title>
<base href="http://www.tutorialspoint.com/" />
<style type="text/css">
.myclass{
background-color: #aaa;
padding: 10px;
}
</style>
</head>
<body>
<p class="myclass">Hello, World!</p>
</body>
</html>
7. The HTML <script> Tag
The HTML <script> tag is used to include either external script file or to define
internal script for the HTML document. Following is an example where we are using
JavaScript to define a JavaScript function
<html>
<head>
<title>HTML script Tag Example</title>
<base href="http://www.tutorialspoint.com/" />
<script type="text/JavaScript">
function Hello(){
alert("Hello, World");
}
</script>
</head>
<body>
<input type="button" onclick="Hello();" name="ok" value="OK"
/>
</body>
</html>
8. HTML <noscript> Tag
The <noscript> tag defines an alternate content to be displayed to users that have
disabled scripts in their browser or have a browser that doesn't support script.
<html>
<head>
<title>HTML noscript Tag</title>
</head>
<body>
<script type = "text/JavaScript">
<!--
document.write("Hello JavaScript!")
-->
</script>
Page 83 of 145
<noscript>
Your browser does not support JavaScript!
</noscript>
</body>
</html>
4. External CSS
With an external style sheet, you can change the look of an entire website by
changing just one file!
External styles are defined within the <link> element, inside the <head> section
of an HTML page:
Example
i) styles.html file
<html>
<head>
<link rel="stylesheet" href="mystyle.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
ii) mystyle.css file
An external style sheet can be written in any text editor, and must be saved
with a .css extension.
body {
background-color: lightblue;
}
Page 84 of 145
h1 {
color: navy;
margin-left: 20px;
}
5. Internal CSS
An internal style sheet may be used if one single HTML page has a unique style.
Internal styles are defined within the <style> element, inside the <head> section
of an HTML page:
<html>
<head>
<style>
body {
background-color: linen;
}
h1 {
color: maroon;
margin-left: 40px;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
6. Inline CSS
An inline style may be used to apply a unique style for a single element.
To use inline styles, add the style attribute to the relevant element. The style
attribute can contain any CSS property.
<html>
<body>
<h1 style="color:blue;text-align:center;">
This is a heading
</h1>
<p style="color:red;">This is a paragraph.</p>
</body>
</html>
An inline style loses many of the advantages of a style sheet (by mixing content
with presentation).
Example
Index.html File
<html>
<head>
<meta charset="UTF-8">
<title>Pure CSS DropDown Menu</title>
<link rel="stylesheet" href="style.css">
Page 85 of 145
</head>
<body>
<div id="container">
<nav>
<ul>
<li><a href="#">Home </a> </li>
<li><a href="#">Web Design </a>
<ul>
<li><a href="#">HTML </a> </li>
<li><a href="#">CSS </a> </li>
<li><a href="#">JavaScript </a> </li>
</ul>
</li>
<li><a href="#">Web Development</a>
<ul>
<li><a href="#">PHP</a></li>
<li><a href="#">Node JS</a></li>
<li><a href="#">Advance JS</a>
<ul>
<li><a href="#">Angular</a></li>
<li><a href="#">VUE</a></li>
<li><a href="#">React</a>
<ul>
<li><a href="#">React Native</a></li>
<li><a href="#">React JS</a></li>
<li><a href="#">Material Design</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#">Graphic Design</a>
<ul>
<li><a href="#">Photoshop</a></li>
<li><a href="#">Illustrator</a></li>
<li><a href="#">Adobe XD</a></li>
</ul>
</li>
<li><a href="#">Contact</a></li>
<li><a href="#">About</a></li>
</ul>
</nav>
<h1>Simple <span>CSS</span> DropDown Menu</h1>
</div>
</body>
</html>
Style.css File
body {
background: #212121;
font-size:22px;
line-height: 32px;
color: #ffffff;
word-wrap:break-word !important;
font-family: 'Quicksand', sans-serif;
margin: 0;
Page 86 of 145
padding: 0;
}
h1 {
font-size: 60px;
text-align: center;
color: #FFF;
margin-top: 150px;
font-family: 'Russo One', sans-serif;
}
h1 span {
color: #FF4649;
}
#container {
margin: 0 auto;
}
nav {
margin: 35px 0;
background-color: #FF4649;
}
nav ul {
padding: 0;
margin: 0;
list-style: none;
position: relative;
}
nav ul li {
display:inline-block;
background-color: #FF4649;
}
nav a {
display:block;
padding:0 10px;
color:#FFF;
font-size:20px;
line-height: 60px;
text-decoration:none;
}
nav a:hover {
background-color: #333;
}
nav ul ul {
display: none;
position: absolute;
top: 60px;
}
nav ul li:hover > ul {
display:inherit;
}
nav ul ul li {
width:230px;
float:none;
display:list-item;
position: relative;
}
nav ul ul ul li {
position: relative;
top:-60px;
Page 87 of 145
left:230px;
}
nav ul ul li {
border: 1px solid white;
}
li > a:after {
content: ' ▼';
}
li > a:only-child:after {
content: '';
}
Page 88 of 145
JAVASCRIPT
Introduction to JavaScript
1. Introduction
JavaScript is a lightweight, interpreted programming language with object-
oriented capabilities. It is designed for creating network-centric applications.
It is open and cross-platform.
It is lightweight and most commonly used as a part of web pages, whose
implementations allow client-side script to interact with the user and make
dynamic pages.
Scripts offer authors a means to extend HTML documents in highly active and
interactive ways.
Page 89 of 145
JavaScript and modify your HTML to change its look and feel based on different
devices and requirements.
User Notifications - You can use JavaScript to raise dynamic pop-ups on the
webpages to give different types of notifications to your website visitors.
Back-end Data Loading - JavaScript provides Ajax library which helps in
loading back-end data while you are doing some other processing. This really
gives an amazing experience to your website visitors.
Presentations - JavaScript also provides the facility of creating presentations
which gives website look and feel. JavaScript provides RevealJS and BespokeJS
libraries to build a web-based slide presentation.
Server Applications - Node JS is built on Chrome's Javascript runtime for
building fast and scalable network applications. This is an event based library
which helps in developing very sophisticated server applications including Web
Servers.
4. Client-Side JavaScript
The script is included in or referenced by an HTML document for the code to be
interpreted by the browser.
It means that a web page need not be a static HTML, but can include programs
that interact with the user, control the browser, and dynamically create HTML
content.
For example, you might use JavaScript to check if the user has entered a valid e-
mail address in a form field. The JavaScript code is executed when the user
submits the form, and only if all the entries are valid, they would be submitted to
the Web Server.
5. Advantages of JavaScript
The merits of using JavaScript are −
Less Server Interaction − You can validate user input before sending the page
off to the server. This saves server traffic, which means less load on your server.
Immediate feedback to the visitors − They don't have to wait for a page reload
to see if they have forgotten to enter something.
Increased Interactivity − You can create interfaces that react when the user
hovers over them with a mouse or activates them via the keyboard.
Richer Interfaces − You can use JavaScript to include such items as drag-and-
drop components and sliders to give a Rich Interface to your site visitors.
Page 90 of 145
Macromedia Dreamweaver MX − It provides several handy prebuilt JavaScript
components, integrates well with databases, and conforms to new standards such
as XHTML and XML.
7. JavaScript - Syntax
JavaScript can be implemented using JavaScript statements that are placed within the
<script>... </script> HTML tags in a web page.
You can place the <script> tags, containing your JavaScript, anywhere within your
web page, but it is normally recommended that you should keep it within the <head>
tags.
Script in <head>...</head> section.
Script in <body>...</body> section.
Script in <body>...</body> and <head>...</head> sections.
Script in an external file and then include in <head>...</head> section.
The <script> tag alerts the browser program to start interpreting all the text between
these tags as a script. A simple syntax of your JavaScript will appear as follows.
<script ...>
JavaScript code
</script>
The script tag can take two attributes−
<script language = "javascript" type = "text/javascript">
JavaScript code
</script>
Type attribute is a must.
Example:
<html>
<body>
<script language = "javascript" type = "text/javascript">
<!--
document.write("Hello World!");
//-->
</script>
</body>
</html>
8. Statements in JavaScript
Statements in JavaScript are generally followed by a semicolon character,
JavaScript can allow you to omit this semicolon if each of your statements are placed
on a separate line:
Page 91 of 145
Example:
<script language = "javascript" type = "text/javascript">
<!--
var1 = 10
var2 = 20
//-->
</script>
9. Case Sensitivity
JavaScript is a case-sensitive language. This means that the language keywords,
variables, function names, and any other identifiers must always be typed with a
consistent capitalization of letters.
So the identifiers Time and TIME will convey different meanings in JavaScript.
NOTE − Care should be taken while writing variable and function names in JavaScript.
10.Comments in JavaScript
Single Line Comment: Any text between a // and the end of a line is treated as a
comment and is ignored by JavaScript.
Multiple Line Comment: Any text between the characters /* and */ is treated as a
comment.
JavaScript also recognizes the HTML comment opening sequence <!--. JavaScript
treats this as a single-line comment, just as it does the // comment.
The HTML comment closing sequence --> is not recognized by JavaScript so it
should be written as //-->.
Example
<script language = "javascript" type = "text/javascript">
<!--
// This is a comment. It is similar to comments in C++
/*
* This is a multi-line comment in JavaScript
* It is very similar to comments in C Programming
*/
//-->
Page 92 of 145
</script>
11.Non-JavaScript Browsers
You can add a noscript block immediately after the script block as follows −
<html>
<body>
<script language = "javascript" type = "text/javascript">
<!--
document.write("Hello World!")
//-->
</script>
<noscript>
Sorry...JavaScript is needed to go ahead.
</noscript>
</body>
</html>
Now, if the user's browser does not support JavaScript or JavaScript is not
enabled, then the message from </noscript> will be displayed on the screen.
12. Examples
Example 1
<html>
<head>
<script type = "text/javascript">
<!--
function sayHello() {
alert("Hello World")
}
//-->
</script>
</head>
<body>
<input type = "button" onclick = "sayHello()" value = "Say Hello" />
</body>
</html>
Example 2
<html>
<head>
</head>
<body>
<script type = "text/javascript">
<!--
Page 93 of 145
document.write("Hello World")
//-->
</script>
Example 3
<html>
<head>
<script type = "text/javascript">
<!--
function sayHello() {
alert("Hello World")
}
//-->
</script>
</head>
<body>
<script type = "text/javascript">
<!--
document.write("Hello World")
//-->
</script>
Example 4
Include the external JavaScript file in your HTML code using script tag and its src
attribute.
<html>
<head>
<script type = "text/javascript" src = "filename.js" ></script>
</head>
<body>
.......
</body>
</html>
Page 94 of 145
function sayHello() {
alert("Hello World")
}
JavaScript - Variables
1. Datatypes
JavaScript allows you to work with three primitive data types −
JavaScript also defines two trivial data types, null and undefined, each of which defines
only a single value.
In addition to these primitive data types, JavaScript supports a composite data type
known as object. We will cover objects in detail in a separate chapter.
2. Variables
Variables are declared with the var keyword as follows.
You can also declare multiple variables with the same var keyword as follows −
Page 95 of 145
</script>
Note − Use the var keyword only for declaration or initialization, once for the life of any
variable name in a document. You should not re-declare same variable twice.
JavaScript is untyped language. This means that a JavaScript variable can hold a value of
any data type. Unlike many other languages, you don't have to tell JavaScript during
variable declaration what type of value the variable will hold. The value type of a
variable can change during the execution of a program and JavaScript takes care of it
automatically.
You should not use any of the JavaScript reserved keywords as a variable name.
These keywords are mentioned in the next section. For example, break or
boolean variable names are not valid.
Page 96 of 145
JavaScript variable names should not start with a numeral (0-9). They must begin
with a letter or an underscore character. For example, 123test is an invalid
variable name but _123test is a valid one.
JavaScript variable names are case-sensitive. For example, Name and name are
two different variables.
6. JavaScript - Operators
i) Arithmetic Operators
2 - (Subtraction) Subtracts the second operand from the first. Eg: A - B will give -10
Note − Addition operator (+) works for Numeric as well as Strings. e.g. "a" + 10 will
give "a10".
Page 97 of 145
Example
<html>
<body>
document.write("a + b = ");
result = a + b;
document.write(result);
document.write(linebreak);
document.write("a - b = ");
result = a - b;
document.write(result);
document.write(linebreak);
document.write("a / b = ");
result = a / b;
document.write(result);
document.write(linebreak);
document.write("a % b = ");
result = a % b;
document.write(result);
document.write(linebreak);
document.write("a + b + c = ");
result = a + b + c;
document.write(result);
document.write(linebreak);
a = ++a;
document.write("++a = ");
result = ++a;
document.write(result);
document.write(linebreak);
b = --b;
document.write("--b = ");
result = --b;
document.write(result);
document.write(linebreak);
//-->
</script>
Page 98 of 145
</body>
</html>
Example
<html>
<body>
<script type = "text/javascript">
<!--
var a = 10;
var b = 20;
var linebreak = "<br />";
Page 99 of 145
document.write(linebreak);
<html>
<body>
<script type = "text/javascript">
<!--
var a = true;
var b = false;
var linebreak = "<br />";
<html>
<body>
<script type = "text/javascript">
<!--
var a = 2; // Bit presentation 10
var b = 3; // Bit presentation 11
var linebreak = "<br />";
v) Assignment Operators
JavaScript supports the following assignment operators −
Sr.No. Operator & Description
1 = (Simple Assignment) Assigns values from the right side operand to
the left side operand
Eg: C += A is equivalent to C = C + A
3 −= (Subtract and Assignment). It subtracts the right operand from the
left operand and assigns the result to the left operand.
Eg: C -= A is equivalent to C = C - A
Ex: C *= A is equivalent to C = C * A
5 /= (Divide and Assignment). It divides the left operand with the right
operand and assigns the result to the left operand.
Ex: C /= A is equivalent to C = C / A
6 %= (Modules and Assignment). It takes modulus using two operands
and assigns the result to the left operand.
Ex: C %= A is equivalent to C = C % A
Note − Same logic applies to Bitwise operators so they will become like <<=, >>=, >>=,
&=, |= and ^=.
<html>
<body>
<script type = "text/javascript">
<!--
var a = 33;
var b = 10;
var linebreak = "<br />";
Conditional Operator (? :)
The conditional operator first evaluates an expression for a true or false value and then
executes one of the two given statements depending upon the result of the evaluation.
Example
Try the following code to understand how the Conditional Operator works in JavaScript.
<html>
<body>
<script type = "text/javascript">
<!--
var a = 10;
var b = 20;
var linebreak = "<br />";
typeof Operator
The typeof operator is a unary operator that is placed before its single operand, which
can be of any type. Its value is a string indicating the data type of the operand.
The typeof operator evaluates to "number", "string", or "boolean" if its operand is a
number, string, or boolean value and returns true or false based on the evaluation.
Here is a list of the return values for the typeof Operator.
The backslash (\) is used to insert apostrophes, new lines, quotes, and other special
characters into a text string.
var txt="We are the so-called \"Vikings\" from the north.";
document.write(txt);
document.write ("You \& I are singing!");
The table below lists other special characters that can be added to a text string with the
backslash sign:
Code Outputs
\' single quote
\" double quote
\& ampersand
\\ backslash
\n new line
\r carriage return
\t tab
\b backspace
\f form feed
if statement
if...else statement
if...else if... statement.
i) if statement
Syntax
if (expression) {
Statement(s) to be executed if expression is true
}
<html>
<body>
<script type = "text/javascript">
<!--
var age = 20;
Syntax
if (expression) {
Statement(s) to be executed if expression is true
} else {
Statement(s) to be executed if expression is false
}
Example
<html>
<body>
<script type = "text/javascript">
<!--
var age = 15;
Syntax
if (expression 1) {
Statement(s) to be executed if expression 1 is true
} else if (expression 2) {
Statement(s) to be executed if expression 2 is true
} else if (expression 3) {
Statement(s) to be executed if expression 3 is true
} else {
Statement(s) to be executed if no expression is true
}
Example
<html>
<body>
<script type = "text/javascript">
<!--
var book = "maths";
if( book == "history" ) {
document.write("<b>History Book</b>");
} else if( book == "maths" ) {
document.write("<b>Maths Book</b>");
} else if( book == "economics" ) {
document.write("<b>Economics Book</b>");
} else {
document.write("<b>Unknown Book</b>");
}
//-->
</script>
<p>Set the variable to different value and then try...</p>
</body>
<html>
default: statement(s)
}
The break statements indicate the end of a particular case. If they were omitted, the
interpreter would continue executing each statement in each of the following cases.
Example
<html>
<body>
<script type = "text/javascript">
<!--
var grade = 'A';
document.write("Entering switch block<br />");
switch (grade) {
case 'A': document.write("Good job<br />");
break;
Example
<script type="text/javascript">
var score=prompt("enter the score");
switch(true){
case ((score>=80)&& (score<=99)):
document.write("Grade = A Excellence Performance");
break;
case ((score>=60) &&(score<=79)):
document.write("Grade = B Above Average");
break;
document.write("Loop stopped!");
//-->
</script>
i) For Loop
The 'for' loop is the most compact form of looping. It includes the following three
important parts −
The loop initialization where we initialize our counter to a starting value. The
initialization statement is executed before the loop begins.
You can put all the three parts in a single line separated by semicolons.
Example
<html>
<body>
<script type = "text/javascript">
<!--
var count;
document.write("Starting Loop" + "<br />");
JavaScript provides full control to handle loops and switch statements. There may be
a situation when you need to come out of a loop without reaching its bottom. There
may also be a situation when you want to skip a part of your code block and start the
next iteration of the loop.
To handle all such situations, JavaScript provides break and continue statements.
These statements are used to immediately come out of any loop or to start the next
iteration of any loop respectively.
The break statement, is used to exit a loop early, breaking out of the enclosing curly
braces.
The following example illustrates the use of a break statement with a while loop.
Notice how the loop breaks out early once x reaches 5 and reaches to
document.write (..) statement just below to the closing curly brace −
<html>
<body>
<script type = "text/javascript">
<!--
var x = 1;
document.write("Entering the loop<br /> ");
The continue statement tells the interpreter to immediately start the next iteration of
the loop and skip the remaining code block. When a continue statement is
encountered, the program flow moves to the loop check expression immediately and
if the condition remains true, then it starts the next iteration, otherwise the control
comes out of the loop.
Example
<html>
<body>
<script type = "text/javascript">
<!--
var x = 1;
document.write("Entering the loop<br /> ");
if (x == 5) {
continue; // skip rest of the loop body
}
document.write( x + "<br />");
2. Function Definition
Before we use a function, we need to define it. The most common way to define a function
in JavaScript is by using the function keyword, followed by a unique function name, a list
of parameters (that might be empty), and a statement block surrounded by curly braces.
Example
3. Calling a Function
To invoke a function somewhere later in the script, you would simply need to write the
name of that function as shown in the following code.
<html>
<head>
<script type = "text/javascript">
function sayHello() {
document.write ("Hello there!");
}
</script>
</head>
4. Function Parameters
A function can take multiple parameters separated by comma.
Example
<html>
<head>
<script type = "text/javascript">
function sayHello(name, age) {
document.write (name + " is " + age + " years old.");
}
</script>
</head>
<body>
<p>Click the following button to call the function</p>
<form>
<input type = "button" onclick = "sayHello('Zara', 7)" value =
"Say Hello">
</form>
<p>Use different parameters inside the function and then
try...</p>
</body>
</html>
Example
<html>
<head>
<script type = "text/javascript">
function concatenate(first, last) {
var full;
full = first + last;
return full;
}
function secondFunction() {
<body>
<p>Click the following button to call the function</p>
<form>
<input type = "button" onclick = "secondFunction()" value =
"Call Function">
</form>
<p>Use different parameters inside the function and then
try...</p>
</body>
</html>
JavaScript - Events
1. Introduction
JavaScript's interaction with HTML is handled through events that occur when the user or
the browser manipulates a page.
When the page loads, it is called an event. When the user clicks a button, that click too is
an event. Other examples include events like pressing any key, closing a window, resizing
a window, etc.
Developers can use these events to execute JavaScript coded responses, which cause
buttons to close windows, messages to be displayed to users, data to be validated, and
virtually any other type of response imaginable.
Events are a part of the Document Object Model (DOM) Level 3 and every HTML element
contains a set of events which can trigger JavaScript Code.
Example
<html>
<head>
<script type = "text/javascript">
<body>
<p>Click the following button and see result</p>
<form>
<input type = "button" onclick = "sayHello()" value = "Say
Hello" />
</form>
</body>
</html>
Example
<br><br>
Example
Example
Example
<html>
<head>
<script type = "text/javascript">
<!--
function validation() {
all validation goes here
.........
return either true or false
}
//-->
</script>
</head>
<body>
<form method = "POST" action = "t.cgi" onsubmit = "return
validate()">
.......
<input type = "submit" value = "Submit" />
</form>
</body>
</html>
<html>
<head>
<script type = "text/javascript">
<!--
function over() {
document.write ("Mouse Over");
}
function out() {
document.write ("Mouse Out");
}
//-->
</script>
</head>
<body>
<p>Bring your mouse inside the division to see the result:</p>
<div onmouseover = "over()" onmouseout = "out()">
<h2> This is inside the division </h2>
</div>
</body>
</html>
An alert dialog box is mostly used to give a warning message to the users. For example,
if one input field requires to enter some text but the user does not provide any input, then
as a part of validation, you can use an alert box to give a warning message.
Nonetheless, an alert box can still be used for friendlier messages. Alert box gives only
one button "OK" to select and proceed.
Example
<html>
<head>
<script type = "text/javascript">
<!--
function Warn() {
alert ("This is a warning message!");
document.write ("This is a warning message!");
}
//-->
</script>
</head>
<body>
<p>Click the following button to see the result: </p>
<form>
<input type = "button" value = "Click Me" onclick = "Warn();" />
</form>
</body>
</html>
If the user clicks on the OK button, the window method confirm() will return true. If the
user clicks on the Cancel button, then confirm() returns false. You can use a
confirmation dialog box as follows.
Example
<html>
<head>
<body>
<p>Click the following button to see the result: </p>
<form>
<input type = "button" value = "Click Me" onclick =
"getConfirmation();" />
</form>
</body>
</html>
This dialog box is displayed using a method called prompt() which takes two
parameters: (i) a label which you want to display in the text box and (ii) a default string to
display in the text box.
This dialog box has two buttons: OK and Cancel. If the user clicks the OK button, the
window method prompt() will return the entered value from the text box. If the user
clicks the Cancel button, the window method prompt() returns null.
Example
<html>
<head>
<script type = "text/javascript">
<!--
function getValue() {
var retVal = prompt("Enter your name : ", "your name here");
document.write("You have entered : " + retVal);
}
//-->
</script>
</head>
<head>
<script type = "text/javascript">
<!--
void func()
javascript:void func()
or:
void(func())
javascript:void(func())
//-->
</script>
</head>
Example 1
The most common use of this operator is in a client-side javascript: URL, where it allows
you to evaluate an expression for its side-effects without the browser displaying the value
of the evaluated expression.
Here the expression alert ('Warning!!!') is evaluated but it is not loaded back into the
current document −
<html>
<head>
<script type = "text/javascript">
<!--
//-->
</script>
</head>
<body>
<p>Click the following, This won't react at all...</p>
<a href = "javascript:void(alert('Warning!!!'))">Click me!</a>
</body>
</html>
Take a look at the following example. The following link does nothing because the
expression "0" has no effect in JavaScript. Here the expression "0" is evaluated, but it is
not loaded back into the current document.
<html>
<head>
<script type = "text/javascript">
<!--
//-->
</script>
</head>
<body>
<p>Click the following, This won't react at all...</p>
<a href = "javascript:void(0)">Click me!</a>
</body>
</html>
Example 3
<html>
<head>
<script type = "text/javascript">
<!--
function getValue() {
var a,b,c;
a = void ( b = 5, c = 7 );
document.write('a = ' + a + ' b = ' + b +' c = ' + c );
}
//-->
</script>
</head>
<body>
<p>Click the following to see the result:</p>
<form>
<input type = "button" value = "Click Me" onclick =
"getValue();" />
</form>
</body>
</html>
Overview
This lesson summarizes the basic features common to most popular web authoring
software programs. It describes the overall working environment, and provides a
summary of the HTML techniques you learned earlier in this course, and how to
implement them using most web authoring tools. Use this handout as a starting point for
exploring the web authoring software used in your class.
Learner Outcomes
have a basic understanding of the features that are common to most web
authoring software programs.
be able to add HTML elements to a web page using web authoring software
rather than writing code.
be able to modify the attributes or properties of HTML elements using web
authoring software.
Standard, normal, or design view - This is typically the default view, which is a
blank screen on which you type, paste, or insert content. This is very similar to a
word processor screen.
Code view - Allows you to view and work directly with the HTML code.
Split - Both of the above views are displayed simultaneously in separate
windows.
Typically you can switch between views by selecting a relevant item from the program's
main menu (usually within the View menu) or by selecting a relevant tab or button.
Activity
Find how to switch between views in your web authoring software. Does the
software provide more than one way to do this? Try typing something on the
screen in Normal or Design View, then switch to Code View to see the HTML that
was generated by the web authoring tool.
Ask your instructor for instructions on how to open and save files with your web
authoring software in your school's computing environment.
Now open your portfolio file tools.html in your web authoring software. At this
point the page should have a "skip to main content" link, banner image, main H1
heading, and a navigation menu. Practice switching between views and exploring
your page using your web authoring tool.
PHP Scripting
• PHP is an open source serverside scripting language
• Provides simple and powerful database access via Apache server
• Good for Rapid Application Development
On the right side of the IIS Manager look under the Browse Website section. Click on
Browse *:80 (http). That will open the default web site in your default web browser.
Before we go into the other two methods of installing IIS, let’s see where the files that
make your website are stored. We’ll also make a very basic web page. Once you know
how to do this, you’ll know the basics to jump into learning web design and
development.
2. Save the file to the wwwroot location. Name it index.asp and change the Save as type:
to All Files. Then click the Save button.
4. Now that it’s saved as the right filetype, let’s put some content in it. Enter the
following HTML code for a very basic web page and save it:
<html>
<head>
<title>My first ASP Page</title>
</head>
<body>
<%
Response.Write "<h1>Hello World!</h1>"
Response.Write Now
%>
</body>
</html>
Because ASP. NET code is executed on the server, you cannot view the code in your
browser. You will only see the output as plain HTML.
Razor is a simple markup syntax for embedding server code (C# or VB) into ASP.NET
web pages.
C# Example
<!-- Single statement block -->
@{ var myMessage = "Hello World"; }
VB Example
<!-- Single statement block -->
@Code dim myMessage = "Hello World" End Code
ASP files can be ordinary HTML files. In addition, ASP files can also contain server
scripts.
!DOCTYPE html>
<html>
<body>
<%
Response.Write("Hello World!")
%>
</body>
</html>
HTML tags can be a part of the output:
Example
<!DOCTYPE html>
<html>
<body>
<%
Response.Write("<h2>You can use HTML tags to format
the text!</h2>")
%>
</body>
</html>
Example
<%@ language="javascript"%>
<!DOCTYPE html>
<html>
<body>
<%
Response.Write("Hello World!")
%>
</body>
</html>
ASP Variables
Variables are "containers" for storing information.
VBScript Variables
As with algebra, VBScript variables are used to hold values or expressions.
A variable can have a short name, like x, or a more descriptive name, like carname.
In VBScript, all variables are of type variant that can store different types of data.
example demonstrates how to declare a variable, assign a value to it, and use the value in
a text.
<!DOCTYPE html>
<html>
<body>
<%
dim name
name="Donald Duck"
response.write("My name is: " & name)
%>
</body>
</html>
You can declare VBScript variables with the Dim, Public or the Private statement. Like
this
Option Explicit statement. This statement forces you to declare all your variables with the
dim, public or private statement.
Option Explicit
Dim carname
carname=some value
Dim names(2)
<html>
<body>
<%
Dim x(2,2)
x(0,0)="Volvo"
x(0,1)="BMW"
x(0,2)="Ford"
x(1,0)="Apple"
x(1,1)="Orange"
x(1,2)="Banana"
x(2,0)="Coke"
x(2,1)="Pepsi"
x(2,2)="Sprite"
for i=0 to 2
response.write("<p>")
for j=0 to 2
response.write(x(i,j) & "<br />")
next
response.write("</p>")
next
%>
</body>
</html>
A variable declared inside a procedure is created and destroyed every time the procedure
is executed. No scripts outside the procedure can access or change the variable.
Session Variables
Session variables are used to store information about ONE single user, and are available
to all pages in one application. Typically information stored in session variables are
name, id, and preferences.
Application Variables
Application variables are also available to all pages in one application. Application
variables are used to store information about ALL users in one specific application.
ASP Procedures
The ASP source code can contain procedures and functions:
<!DOCTYPE html>
<html>
<head>
<%
sub vbproc(num1,num2)
response.write(num1*num2)
end sub
%>
</head>
<body>
</body>
</html>
Insert the <%@ language="language" %> line above the <html> tag to write the
procedure/function in another scripting language:
<p>Result: <%jsproc(3,4)%></p>
</body>
</html>
VBScript Procedures
VBScript has two kinds procedures:
1. Sub procedure
2. Function procedure
Or
Sub mysub(argument1,argument2)
some statements
End Sub
VBScript Looping
Looping Statements
Looping statements are used to run the same block of code a specified number of times.
In VBScript we have four looping statements:
For...Next statement - runs code a specified number of times
For Each...Next statement - runs code for each item in a collection or each element of
an array
Do...Loop statement - loops while or until a condition is true
While...Wend statement - Do not use it - use the Do...Loop statement instead
User Input
The Request object can be used to retrieve user information from forms.
User input can be retrieved with the Request.QueryString or Request.Form command.
Request.QueryString
The Request.QueryString command is used to collect values in a form with
method="get".
Information sent from a form with the GET method is visible to everyone (it will be
displayed in the browser's address bar) and has limits on the amount of information to
send.
<!DOCTYPE html>
<html>
<body>
<form action="demo_reqquery.asp" method="get">
Your name: <input type="text" name="fname" size="20" />
<input type="submit" value="Submit" />
</form>
<%
dim fname
fname=Request.QueryString("fname")
If fname<>"" Then
Response.Write("Hello " & fname & "!<br>")
Response.Write("How are you today?")
End If
%>
</body>
</html>