2017intro To Web Development
2017intro To Web Development
The Allama Iqbal Open University (AIOU) is a fully fledged, autonomous and accredited public
University. It offers its certificate, diploma, degree and postgraduate courses through the open and
distance learning system which includes various means of communication such as face-to-face,
broadcasting, telecasting, correspondence, seminars, e-learning as well as a blended mode.
© 2017 by the Commonwealth of Learning and Allama Iqbal Open University (AIOU). Except where
otherwise noted, Introduction to Web development made available under Creative Commons
Attribution-Share Alike 4.0 International (CC BY-SA 4.0) License:
https://creativecommons.org/licenses/by-sa/4.0/legalcode.
For the avoidance of doubt, by applying this licence the Commonwealth of Learning does not waive
any privileges or immunities from claims that it may be entitled to assert, nor does the
Commonwealth of Learning submit itself to the jurisdiction, courts, legal processes or laws of any
jurisdiction. The ideas and opinions expressed in this publication are those of the author/s; they are
not necessarily those of Commonwealth of Learning and do not commit the organisation.
Authors
Dr. Amjad Mahmood (Department of Computer Science, University of Bahrain, Bahrain)
Dr. Moiz Uddin Ahmed (Department of Computer Science, AIOU, Pakistan)
Mr. Hanaan Sadeed Ahmad (Department of Computer Science, AIOU, Pakistan)
Reviewer
Mr. Khalid Iqbal (Islamabad College for Boys, Islamabad, Pakistan)
Copy Editor
Mr. Naveed Anjum (Islamabad College for Boys, Islamabad, Pakistan)
Layout Design
Mr. Mushtaq Hussain (PPU, AIOU)
Video Production
Dr. Amjad Mahmood (Department of Computer Science, University of Bahrain, Bahrain)
Dr. Moiz Uddin Ahmed (Department of Computer Science, AIOU, Pakistan)
Mr. Ghulam Umer Abbasi (Producer, Institute of Educational Technology, AIOU)
Mr. Muhammad Younis (Senior Cameraman, Institute of Educational Technology, AIOU)
Mr. Raheel Tahir (Associate Engineer, Institute of Educational Technology, AIOU)
Mr. Ahsan Farooq (Department of Computer Science, AIOU, Pakistan)
Research Associates
Mr. Muhammad Aquil (Department of Computer Science, AIOU, Pakistan)
Ms. Reeba Raynah (Department of Computer Science, AIOU, Pakistan)
Mr. Hussnain Tariq (Department of Computer Science, AIOU, Pakistan)
Project Director
Dr. Moiz Uddin Ahmed (Department of Computer Science, AIOU, Pakistan)
Co-Project Director
Dr. Zahid Majeed (International Collaboration & Exchange Office, AIOU, Pakistan)
This course has been developed with the support of the Commonwealth of Learning, Canada.
Contents
Contents
Course overview
Welcome to Introduction to Web Development ................................................................... 3
Introduction to Web Development – is this course for you ?................................................ 3
Course outcomes.................................................................................................................... 5
Timeframe .............................................................................................................................. 5
Study skills .............................................................................................................................. 6
Need help? ............................................................................................................................. 7
Assessments ........................................................................................................................... 7
Unit 1
Introduction to Web Development ........................................................................................ 9
Introduction ................................................................................................................... 10
Unit outcomes................................................................................................................ 10
Terminologies................................................................................................................. 10
1.1. Internet .................................................................................................................. 11
1.1.1. IP Addresses ................................................................................................. 11
1.2. TCP/IP Protocol Suits.............................................................................................. 12
1.3. ISP and its Working ................................................................................................ 13
1.4. World Wide Web (WWW)...................................................................................... 13
1.5. Website and Domain Names ................................................................................. 14
1.5.1. Domain Names ............................................................................................ 14
1.6. Web Hosting .......................................................................................................... 15
1.6.1. Types of Web Hosting ................................................................................. 15
1.7. Website Development Process ............................................................................. 16
1.8. Static vs Dynamic Web pages ................................................................................ 18
1.9. Web Development Technologies ........................................................................... 18
1.10. Client Side vs Server Side Scripting ...................................................................... 19
1.10.1. Client Side Scripting ................................................................................ 19
1.10.2. Server Side Scripting ............................................................................... 20
1.10.3. Common Gateway Interface .................................................................... 20
1.11. Hypertext, Hypermedia Tools and IDEs ................................................................ 20
ii Introduction to Web Development
Unit 2
HTML Basics.......................................................................................................................... 25
Introduction ................................................................................................................... 26
Unit Outcomes ............................................................................................................... 26
Terminologies................................................................................................................. 27
2.1. Developing Your First Web page ............................................................................ 28
2.2. HTML Document Structure .................................................................................... 29
2.3. HTML Tags .............................................................................................................. 30
2.4. Basic HTML Tags ..................................................................................................... 31
2.5. Comments ............................................................................................................. 38
2.6. Formatting Tags ..................................................................................................... 39
2.6.1. Content Based Tags .................................................................................... 39
2.6.2. Physical Style Tags ...................................................................................... 41
2.7. Lists......................................................................................................................... 43
2.7.1. Ordered List ................................................................................................ 44
2.7.2. Unordered List ........................................................................................... 45
2.7.3. Nesting of List ............................................................................................. 46
Unit Summary....................................................................................................................... 48
Self Assessment Questions................................................................................................... 49
References and Further Reading .......................................................................................... 51
Unit 3
HTML Links, Images and Tables ........................................................................................... 53
Introduction ................................................................................................................... 54
Unit Outcomes ............................................................................................................... 54
Terminologies................................................................................................................. 54
3.1. Images and Sounds ................................................................................................ 55
3.2. Adding Images in a Web page ................................................................................ 56
3.2.1. Set Images Width and Height ..................................................................... 57
3.3. HTML Links ............................................................................................................. 58
3.3.1. Hyperlink ..................................................................................................... 59
3.3.2. The Name Attribute .................................................................................... 60
3.3.3. Images as Hyperlink .................................................................................... 61
3.3.4. Link Tag ....................................................................................................... 61
3.3.5. <nav></nav> ............................................................................................... 62
3.4. Tables ..................................................................................................................... 62
3.4.1. Adding Table Caption .................................................................................. 65
Contents
Unit 4
Marquee, Form and Input types ......................................................................................... 73
Introduction ................................................................................................................... 74
Unit Outcomes ............................................................................................................... 74
Terminologies................................................................................................................. 74
4.1. Marquee ................................................................................................................. 75
4.2. Form ....................................................................................................................... 77
4.2.1. <form>......................................................................................................... 77
4.2.2. <input> ........................................................................................................ 78
4.2.3. <text area> .................................................................................................. 85
4.2.4. <select> ....................................................................................................... 86
4.2.5. <datalist>..................................................................................................... 87
4.2.6. Complete Example of Input types and forms ............................................. 88
4.3. iframes ................................................................................................................... 90
Unit Summary....................................................................................................................... 91
Self Assessment Questions................................................................................................... 92
References and Further Reading .......................................................................................... 93
Unit 5
Cascading Style Sheet .......................................................................................................... 95
Introduction ................................................................................................................... 96
Unit Outcomes ............................................................................................................... 96
Terminologies................................................................................................................. 96
5.1. Advantages of CSS .................................................................................................. 97
5.2. Your First Experience with Style ............................................................................ 97
5.3. Methods of Writing CSS ......................................................................................... 99
5.3.1. External Style Sheet ..................................................................................... 99
5.3.2. Internal Style Sheet .................................................................................... 100
5.3.3. Inline Style.................................................................................................. 101
5.4. CSS Syntax ............................................................................................................ 102
5.4.1. Element Selector ........................................................................................ 103
5.4.2. ID Selector .................................................................................................. 104
5.4.3. Class Selector ............................................................................................. 105
5.5. CSS Comments .................................................................................................... 106
5.6. Basic Properties of CSS ........................................................................................ 107
5.6.1. Background Properties in CSS .................................................................... 108
iv Introduction to Web Development
Unit 6
Text, Border and Table Properties in CSS .......................................................................... 119
Introduction ................................................................................................................. 120
Unit Outcomes ............................................................................................................. 120
Terminologies............................................................................................................... 120
6.1. Text Properties in CSS ........................................................................................ 121
6.2. Border Properties ................................................................................................ 123
6.3. Margin Properties ............................................................................................... 125
6.4. Padding Properties in CSS .................................................................................. 127
6.5. Table Properties ................................................................................................. 128
6.6. Position Properties in CSS .................................................................................. 131
Unit Summary..................................................................................................................... 136
Self Assessment Questions................................................................................................. 137
References and Further Reading ........................................................................................ 140
Unit 7
Client Side Scripting - I........................................................................................................ 141
Introduction ................................................................................................................. 142
Unit Outcomes ............................................................................................................. 142
Terminologies............................................................................................................... 142
7.1. JavaScript ............................................................................................................. 143
7.1.1. Advantages and Limitations of JavaScript ................................................. 144
7.2. First JavaScript Program ....................................................................................... 144
7.2.1. Where to put JavaScript code .................................................................... 146
7.2.2. JavaScript in Body Section ......................................................................... 146
7.2.3. JavaScript in Head Section ......................................................................... 148
7.3. External JavaScript ............................................................................................... 150
7.4. JavaScript Basics ................................................................................................... 152
7.5. JavaScript Variables ............................................................................................. 152
7.5.1. Declaring Variables .................................................................................... 153
7.6. JavaScript Comments .......................................................................................... 154
7.6.1. Single line Comments ................................................................................. 154
7.6.2. Multi line Comments .................................................................................. 155
Unit Summary..................................................................................................................... 156
Self Assessment Questions................................................................................................. 157
References and Further Reading ........................................................................................ 159
Contents
Unit 8
Client Side Scripting - II....................................................................................................... 161
Introduction ................................................................................................................. 162
Unit Outcomes ............................................................................................................. 162
Terminologies............................................................................................................... 162
8.1. JavaScript Operators ........................................................................................... 163
8.1.1. Arithmetic Operators ................................................................................. 163
8.1.2. Comparison Operators............................................................................... 164
8.1.3. Logical Operators ....................................................................................... 164
8.1.4. Assignment Operators ............................................................................... 165
8.2. JavaScript Conditional Statements ...................................................................... 166
8.2.1. if Statement ............................................................................................... 166
8.2.2. if-else Statement ........................................................................................ 168
8.2.3. if-else-if Statement .................................................................................... 169
8.2.4. switch Statement ....................................................................................... 171
8.3. JavaScript Loops ................................................................................................... 173
8.3.1. for Loop ...................................................................................................... 173
8.3.2. while Loop .................................................................................................. 175
8.3.3. do while Loop ............................................................................................. 176
8.3.4. break Statement ........................................................................................ 178
8.3.5. continue Statement ................................................................................... 180
8.4. JavaScript Objects ................................................................................................ 181
8.4.1. Object Properties ....................................................................................... 181
8.4.2. Object Methods ......................................................................................... 181
8.4.3. Object Constructor..................................................................................... 182
8.5. JavaScript and HTML Forms ................................................................................. 183
8.6. JavaScript Events .................................................................................................. 185
Unit Summary..................................................................................................................... 189
Self Assessment Questions................................................................................................. 190
References and Further Reading ........................................................................................ 192
Unit 9
Website Hosting ................................................................................................................. 193
Introduction ................................................................................................................. 194
Unit Outcomes ............................................................................................................. 194
Terminologies............................................................................................................... 194
9.1. Web Servers ......................................................................................................... 195
9.1.1. Types of Web Server .................................................................................. 195
9.2. Web Hosting ......................................................................................................... 196
9.2.1. Types of Web Hosting ................................................................................ 196
9.3. Domain Name ...................................................................................................... 197
9.3.1. Sub Domain ............................................................................................... 197
9.4. File Transfer Protocol ........................................................................................... 198
vi Introduction to Web Development
We strongly recommend that you read the overview carefully before starting.
Links to video lectures for each unit are provided in the relevant section of the course material.
1
About this Course Material
Resources
For those interested in learning more on this subject, we provide you with a list of additional
resources at the end of each unit. The additional resources include books, articles and websites.
Your Comments
After completing Introduction to Web Development, we would appreciate it if you could take a few
moments to give us your feedback on any aspect of this course. Your feedback might include
comments on
▪ Course content and structure
▪ Course reading materials and resources
▪ Course activities
▪ Video lectures
▪ Course review questions
▪ Course duration
▪ Course support (assigned tutors, technical help, etc.)
Your constructive feedback will help us to improve and enhance this course in future.
2
Introduction to Web Development
Course Overview
3
About this Course Material
4
Introduction to Web Development
Course Outcomes
Timeframe
5
About this Course Material
Study Skills
▪ http://www.how-to-study.com/
The “How to study” website is dedicated to study skills resources.
You will find links to study preparation (a list of nine essentials for a
good study place), taking notes, strategies for reading text books,
using reference sources, test anxiety.
▪ http://www.ucc.vt.edu/stdysk/stdyhlp.html
This is the website of the Virginia Tech, Division of Student Affairs.
You will find links to time scheduling (including a “where does time
go?” link), a study skill checklist, basic concentration techniques,
control of the study environment, note taking, how to read essays for
analysis, memory skills (“remembering”).
▪ http://www.howtostudy.org/resources.php
Another “How to study” website with useful links to time
management, efficient reading, questioning/listening/observing skills,
getting the most out of doing (“hands-on” learning), memory
building, tips for staying motivated, developing a learning plan.
The above links are our suggestions to start you on your way. At the time
of writing these web links were active. If you want to look for more go to
www.google.com and type “self-study basics”, “self-study tips”, “self-
study skills” or similar.
6
Introduction to Web Development
Need Help?
Course Coordinator
Department of Computer Science
Allama Iqbal Open University
Sector H-8,
Islamabad,
Pakistan
Phone: +92-51-9250091
Fax: +92-51-9250092
Email: [email protected]
Website: www.aiou.edu.pk
Assessment
The performance of the learners is accessed through assignments,
practical and written examination.
7
About this Course Material
</>
Unit Summary Terminology Code Study skills
8
Introduction to Web Development
UNIT 1
Introduction to
Web Development
9
Introduction to Web Development
Introduction
Though the focus of this course is on how to create websites using HTML, CSS, JavaScript and other
technologies, but mastery of HTML, CSS and other technologies should not be confused with the
understanding of the web development process. A web developer should also have basic knowledge
about the working of the Internet, TCP/IP protocol suit and concepts related to them. Furthermore,
developing large and complex websites require a careful planning and use of a suitable development
process. This unit provides an introduction to the basics of Internet and various web development
technologies. It provides web development process and various phases involved in website
development. Website development process is followed through guidelines and documentation in
the systematic way by the developer.
Unit Outcomes
Upon completion of this unit you should be able to:
1. Describe the working of Internet and how services provided on it can be accessed.
2. Differentiate between static and dynamic web pages.
3. Explain web development process and activities carried out during each phase.
4. Explain various technologies used to develop a website.
Terminologies
IP: Internet Protocol (IP) is a communication protocol that provides rules for
exchanging data among computers.
TCP: Transmission Control Protocol (TCP) maintains data flow during end to end
communication.
ISP: Internet Service Provider is a company that provides Internet services.
WWW: World Wide Web is a collection of resources over the Internet.
Domain Name: Domain name is used to identify a website on the Internet.
10
Introduction to Web Development
1.1. Internet
Internet, sometimes called simply "the Net," is collections of standalone computers (and computer
networks in companies and organizations) that are linked together, using communication networks.
It connects millions of computers around the world to exchange data. The connections between the
computers are made using fiber-optic cables, copper cables, wireless radio connections
and satellite links. Internet can handle different kinds of information enabling people to do different
tasks such as sending/receiving emails, searching web, online chatting and many more. All the
information is handled on the Internet exactly in the same way because of the flexible design of the
Internet.
1.1.1. IP Addresses
As we mentioned that Internet is global network of computers, the question then arises how each
computer is uniquely identified which is required for transmitting data from one computer (sources)
to another one (destination). The answer is simple as every computer that connects to the Internet
is given a unique address, called IP address (Internet Protocol address, to be more specific). The IP
(IPv4) standards specify that each host is assigned a unique 32-bit IP address. However, because of
the growth of Internet and the predicted depletion of available addresses, a new version of IP (IPv6),
was developed that uses 128 bits address.
IP addresses are usually written and displayed in human-readable notations, called the dotted-
decimal notation such as 172.16.254.1. (IPv4), and 2001:db8:0:1234:0:567:8:1 (IPv6). Figure 1.1
shows two computers with their IP addresses connected to the Internet.
If you are connected to the Internet through an Internet Service Provider (ISP), ISP assigns a
temporary IP address to your computer or device over a period of a session. In case of connection
through Local Area Network (LAN), a temporary or permanent IP address obtained from DHCP
(Dynamic Host Configuration Protocol) server is assigned to your computer.
11
Introduction to Web Development
Activity 1
1. Find the IP address of your computer.
2. Disconnect your computer from Internet and reconnect it again after some time. Check its
IP address. Is it the same or different from the previous IP address?
3. Explore the concepts of LAN and DHCP.
4. Explore the concept of 32 and 128 bit addresses?
TCP TCP
IP IP
Hardware Hardware
Internet
Figure 1.2: TCP/IP protocol layers
TCP/IP protocol suite specifies how to transmit and receive data on a network.
Each layer of the TCP/IP has a particular function to perform as described in table 1.1.
12
Introduction to Web Development
Activity 2
Explore TCP/IP protocol and functions performed at each layer.
Activity 3
List at least 4 Internet Service Providers in your country/city.
1. __________________________________________________
2. __________________________________________________
3. __________________________________________________
4. __________________________________________________
The Web or World Wide Web (WWW) is a huge collection of electronic documents stored on many
computers called servers around the world. The documents are formatted in a markup language
called HTML that links documents so that you can jump from one document to another by simply
clicking on the links or hot spots.
In WWW, documents are interlinked by hypertext links and can be accessed via
Internet.
13
Introduction to Web Development
A computer, a modem (or some other connection device), a phone line, a software called a
“browser” and an account with ISP are needed to connect with World Wide Web (WWW). A browser
interprets HTML code to display text, images, sound and runs animation.
A browser is a software that can be used to access the Internet and view web
pages on a computer.
The linked documents are available at different Internet sites. The World-Wide Web also provides
access to many other tools which are widely used as the major means of accessing Internet
resources.
Activity 4
List three web browsers that you are familiar with.
1. _________________________________________________
2. _________________________________________________
3._________________________________________________
A website has a collection of related web pages that you can access over
Internet.
Any business, government, or person can create a website on the Internet. Today, the Internet
consists of millions of websites created by different people and organizations.
14
Introduction to Web Development
URLs to identify specific web pages. For example, in the URL http://www.microsoft.com, the domain
name is microsoft.com.
Activity 5
List domain names of some popular websites.
1. _________________________________________________
2. _________________________________________________
3._________________________________________________
A web hosting service provider provides you space to store your web pages on
its server and charges you for the service.
Activity 6
Name a few companies in your area that provide web hosting services.
1. _________________________________________________
2. _________________________________________________
3._________________________________________________
15
Introduction to Web Development
The web developer use a development process to develop large and complex
website in a systematic way.
1. Information gathering
2. Planning
3. Design
4. Development
5. Testing and delivery
6. Maintenance
• Purpose: What is the purpose of the site? For example, the purpose of a website may be to
provide information, promote a business or sell a product?
• Goals: What do we want to accomplish by the website? Two of the more common goals are
either to promote business or share information.
• Target Audience: Determine a group of people who are likely to visit and use the website.
The interest of the target audience helps us to determine the best design for the website.
• Content: Determine what kind of information will the target audience be looking for on the
site?
Phase 2: Planning
After information gathering phase, it is time to put a plan for the website as a site map. A site map
consists of all main topical as well as sub topical areas of the site. This helps to determine what
content will be on the site and how they will be organized. During this phase, we also decide which
technology is to be used for the development of this specific website.
16
Introduction to Web Development
Phase 3: Design
After the planning phase, it is time to determine the look and feel of the website to presents the
content and services to the target audiences as determined in the information gathering phase. As a
part of the design phase, it is important to develop basic elements of website such as the company
logo. A prototype for the website may also be developed to see what the final design will look like.
Phase 4: Development
Development stage is the point where a web designer takes all of the individual graphic element
from the prototype and develops the actual functional website. This is typically done by first
developing the home page. The home page serves as a template for the content pages of a website
and it contains the main navigational structure of the website. Once the homepage is created, the
contents can be distributed to a number of web pages as specified in the site map. Other elements
such as contact form and shopping carts are also implemented and made functional.
Phase 6: Maintenance
Once a website goes online, a number of errors and performance issues may be reported to the
development team. During the maintenance phase, we resolve not only the reported issues but also
improve the website by possibly, adding, updating contents and services.
Activity 7
Your friend requested you to develop a personal website for him. Do the following:
1. Get his requirements and document them
2. Propose an initial design of the website.
17
Introduction to Web Development
Video Lecture
https://youtu.be/TjhPmC1h1cI
On the other hand, the content of a dynamic web page are not fixed but they are generated
dynamically on the fly when requested by user. That is, the content of a dynamic page may be
different from different user depending upon his request. For each request, the web page is
constructed from information stored in databases and programming logic.
Activity 8
Give an example of a static website and a dynamic website that you have visited.
1. HTML
2. CSS
3. JavaScript
4. Databases
18
Introduction to Web Development
HTML
HTML is a Hyper Text Markup Language used to develop a web page. It provides a set of tags that
are used to structure the content of web pages and create links with other pages. We will learn more
about HTML in Unit 2, 3 and 4.
CSS
Cascading style sheets (CSS) is a language that is used to define styles for a web page or web pages.
CSS describes how elements of a web page are to be displayed on screen. CSS handles the look and
feel of a web page. Using CSS, we can control the color of the text, the style of fonts, the spacing
between paragraphs, columns sized and layout, background images or colors, layout designs, and so
on. We will learn more about HTML in Unit 5 and 6.
JavaScript
Javascript is a light weight programming language which is commonly used in developing dynamic
web pages. We will learn more about HTML in Unit 7 and 8.
Databases
A database is a collection of logical related data that can be easily accessed, managed, and updated.
A database management system (DBMS) is a software for creating and managing databases.
Activity 9
Give example of some programming languages which are used for client -side scripting.
19
Introduction to Web Development
Activity 10
Give examples of some programming languages which are used for server-side scripting.
In order to deliver dynamic content, we need to extend the abilities of the web server so that it can
do more than merely sending static web pages in response to the client requests. The common
gateway interface (CGI) provides a mechanism to do this. The server is normally asked for a file that
has a .htm or .html extension for static web pages. The extension would be different for dynamic
web pages, for example .cgi or .php. If a request comes in with one of these extensions, the web
server passes the request to the CGI which interprets it correctly and executes the server side script
to generate a web page that is sent to the client’s browser.
20
Introduction to Web Development
develop stand-alone hypermedia applications, with emphasis on educational and business content
management.
Documentation software such as the Microsoft Office Suite and Office allow for hypertext links to
other content within the same file, other external files, and URL links to files on external file servers.
Any text editor may be used to build HTML files, accessible by any web browser. CD/DVD authoring
tools such as DVD Studio Pro may be used to hyperlink the content of DVDs for DVD players or web
links when the disc is played on a personal computer connected to the Internet. There are some
HTML editors which are based on WYSIWYG (What You See Is What You Get). These editors provide
rich text editing tools for developing web pages. Some of the important tools include Dreamweaver,
Notepad ++, Sublime Text 3 etc.
Unit Summary
In this unit, we learned about the concept and working of Internet and its services. We also learned
the differences between static and dynamic web pages. We have explored web development
process and its associated activities during each phase. We also learned about hypertext and
hypermedia tools.
21
Introduction to Web Development
1. An Internet is -----
A. a single network
B. a vast collection of different networks
C. interconnection of local area networks
D. none of the mentioned
6. Computer that requests the resources or data from another computer is called as ________
computer.
A. Client
B. Server
7. Software which allows user to view the web page is called as __________.
A. Interpreter
B. Internet Browser
C. Website
D. Operating System
8. When a user opens a website, the first page that is displayed is called ________.
A. Backend Page
B. Dead End
C. Home Page
D. None of these
22
Introduction to Web Development
10. Computer which stores the different web pages is called as ________.
A. Web Server
B. Web Browser
C. Service Provider
D. None of these
12. A company that provides Internet access to individuals and other companies is called
A. Web server
B. Telephone
C. Internet Service Provider
D. None of the above
13. In which of the phase of the web development process, we determine the purpose of the
site?
A. Planning
B. Information gathering
C. Design
D. Development
14. Cascading Style Sheets (CSS) is a language that is used to define styles for a web page or web
pages.
A. True
B. False
Answer Key:
1. B 2. C 3. C 4. B 5. A 6. A 7. B 8. C 9. D 10. A
23
Introduction to Web Development
Review Questions
Write short answers of the following questions.
24
Introduction to Web Development
UNIT 2
HTML Basics
25
HTML Basics
Introduction
When we look at web pages in a Web browser, most of the time we see they contain styled text
(rather than plain text), images, video clips, and background music. They include drop-down menus,
search boxes, or links that can be followed to access other pages. Usually, a web page designer may
use several technologies (such as CSS, JavaScript, AJAX, JSON) to control the user interface but most
fundamentally, developers write web pages in HTML, without it no web page can be developed.
Web pages may contain styled text, images, video clips and links to other pages.
The Hyper Text Markup Language (HTML) is a document-layout and hyperlink specification language.
It is a simple, yet powerful, platform independent language for creating web pages. HTML defines a
set of commands (called tags) that are placed around objects (i.e. text, pictures, sounds, table, forms
etc.) to control their appearance in a browser. It also specifies how to create links to other
documents.
The World Wide Web Consortium (W3C) and the Web Hypertext Application Technology Working
Group (WHATWG) define and maintain the HTML standards and specifications worldwide. The HTML
specification defines a single language that can be written either with the relaxed HTML syntax or
the stricter XML syntax (Extensible Markup Language). HTML only describes the meaning of the
content, not style and formatting.
This unit provides an Introduction to HTML 5. As mentioned before, HTML is a markup language. The
word markup was used by editors who marked up manuscripts when giving instructions for
revisions. "Markup" now means something slightly different: a language with specific syntax
instructs a web browser how to display a page. HTML uses a pre-defined set of elements to define
content types. Elements contain one or more "tags" to express content.
Unit Outcomes
Upon completion of this unit, you should be able to:
1. Use a text editor (such as notepad) to type and save your HTML code and view its output in a
browser.
2. Develop web pages using basic HTML tags to format text
3. Create ordered and unordered lists.
26
Introduction to Web Development
Terminologies
27
HTML Basics
Web pages may contain styled text, images, video clips and links to other
pages.
While not needed to create an HTML document, having a latest version of a World Wide Web
browser such as Netscape Navigator or Microsoft Internet Explorer on your computer to view your
work is necessary. However, you do not need an Internet connection to view your own HTML
documents.
To create our first web page with Notepad, follow these four steps.
Step 3: Save your document on your computer by selecting File > Save As (go to the menu bar and
click File and then click on Save As). You will see the following screen:
28
Introduction to Web Development
Select the folder in which you want to save the file, enter file name (such as new.html) and set the
encoding to UTF-8 and click on Save button. Note that your file name should have extension .html.
Step 4: View the HTML Page in Your Browser. Open the saved HTML file by double clicking on the
file, or right-click and choose "Open with" and select your browser.
If everything goes as planned, your browser should display something similar to the following figure
2.2.
Video Lecture
https://youtu.be/iBKj3UzOeng
29
HTML Basics
contain images, links to other resources, lists, menus, entry fields, and plain text. The body of a
document is enclosed between a <body> and a </body> tags.
HTML provides a number of tags to organize and structure a web page. Tags
are written inside <>.
Most of the tags are written in pairs: a start tag (e.g. <HTML>) and an end tag (e.g. </HTML>). There
are only a few tags that do not have an end tag.
Most of the tags appear in pairs: an opening tag <> and a closing tag </>.
The HTML tags can be classified into the following categories for our convenience:
• Basic tags
• Formatting tags
• Lists
30
Introduction to Web Development
• Tables
• Images
• Links
• Forms and Input
• Frames
We will discuss basic tags, formatting tags and lists tags in this unit. The remaining tags will be
discussed in the coming units.
All HTML documents have a required structure that includes the following
declaration and elements: <! DOCTYPE html>, <html>, <head>, and <body>
We will now discuss each of the basic tag in a little more detail.
31
HTML Basics
HTML5 document starts with <! DOCTYPE html>. It does not have an end tag.
<html></html>
The <html> tag is placed right below the <! DOCTYPE html>. It tells the browser that this is an HTML
document and represents the root of an HTML document. This tag is considered to be the container
of all the other HTML elements. It has a closing tag, </html>, which is placed at the very bottom of
the HTML code as shown in the following figure2.3.
<html> tag comes immediately after <! DOCTYPE html>. Your HTML document
ends with </html>.
<head></head>
The <head> tag is the container that holds all the <head> elements. The <head> tag has no attributes
and serves only to encapsulate other tags such as <title> of the HTML document, meta data that are
used to provide information about a web page, keywords that are used for search engine and the
tags that are used to include external documents such as JavaScript and CSS files.
<title></title>
The <title> and </title> pair contains the title of the document. The title of a web page is displayed in
the browser’s title bar and the user’s bookmark. It must be carefully chosen in order to give good
estimation about the subject of the web page.
<meta>
The <meta> tag provides metadata about the HTML document. We typically use metadata elements
to specify page description, keywords, author of the document, last modified, and other metadata.
The metadata can be used by browsers (how to display content or reload page), search engines
(keywords), or other web services.
We can include one or more <meta> tags in your document based on what information you want to
keep in our document. Metadata is always passed as name/value pairs. Let us see how to specify
some important information about a document using <meta> tag.
32
Introduction to Web Development
Specifying keywords: We can use <meta name="keywords content" = "list of keywords"> to specify
important keywords related to the document. These keywords are used by the search engines while
indexing a web page for searching purpose. This is how you specify important keywords
Providing document description: We can use <meta> tag to give a short description about the
document as
Specifying the document author: We can set an author name in a web page as shown below:
Specifying document revision date: We can use <meta> tag to give information about when last
time the document was updated as the following code illustrates.
Specifying document refreshing duration: We can also use <meta> tag to specify a duration after
which a web page will keep refreshing automatically. The following code can be used to refresh a
page after every 5 seconds.
Have a look at the following code to see various tags that are used in <head> section.
<body></body>
The <body> and </body> container contains the part of a page that will actually be displayed. This
tag defines the HTML document’s body, where it contains all the contents and tags of the HTML
document, such as texts, hyperlinks, images, tables, lists, paragraphs and so on. Any HTML code that
decides how the HTML file looks like, and how it behaves must be written in the opening and closing
<body> tag.
33
HTML Basics
Activity 1
Write a text “HTML Intro” in <title></title>tag and “HI I am new to Html” in <body></body>tag and
see how text is displayed in a web browser.
Let us now look at some of the tags that can be used between <body></body> tag pair.
The text written within a heading tag rendered by the browser depends on the available display
technology. The browser may choose to center, embolden, enlarge, italicize, underline, or change
the color of headings to make a heading stand out within the document. However, most browsers
use a diminishing character size for the sequence of headers. Another important point to note is that
headings always reside on their own line when displayed in a browser.
Most of the browsers display the heading left-aligned. We can alter this with ALIGN attribute with
one of these values: left, center and right. For example, to display the heading of level 1 in the
center, we write
Here is an example of HTML code for all the different heading levels and the resulting output in a
browser.
34
Introduction to Web Development
<title>Paragraphs In HTML</title>
</head>
<body>
<h1>First Heading </h1>
<h2>Second Heading </h2>
<h3>Third Heading </h3>
<h4>Fourth Heading </h4>
<h5>Fifth Heading </h5>
<h6>Sixth Heading </h6>
</body>
</html>
Output of <h1>
Output of <h6>
Paragraphs: <p></p>
The paragraph tag, <p>, defines a paragraph. The paragraphs of a document are separated by
inserting a blank line between them. When a browser encounters a new paragraph tag, <p>, it
typically inserts one blank line plus some extra vertical spaces into the document before starting a
new paragraph.
Paragraph tag <p> is used to insert paragraph. By default, paragraphs are left
justified.
Carefully look at the output of the following HTML code (Figure: 2.4) and see how paragraphs are
displayed in a browser.
35
HTML Basics
<body>
<p>This is first paragraph </p>
<p>This is second paragraph </p>
<p>This is third paragraph </p>
</body>
</html>
It can be observed in the above code that there are three paragraphs in the documents, each one
starting with a <p> and ending with </p> tag. Paragraphs are, by default, left justified.
You can change the alignment of paragraph by using style attribute in <p> tag.
However, we can change paragraphs alignment by using style attribute of <p> tag as following
example demonstrates (we will learn more about it in Unit 5).
36
Introduction to Web Development
</html>
The output of above code is shown in figure 2.6.
Activity 2
Write HTML code to display the following text. Use appropriate heading and paragraph tags.
CREATING A WEB PAGE
Creating a web page is very simple. It does not need any prior knowledge of computing and the
Internet.
What is important to learn is your commitment. The best way to learn is to start developing your
pages starting with a simple one.
TIPS
Learn by doing it.
HTML is not case sensitive. So don’t worry how you type it. Learn at your own pace.
Practice, Practice and Practice.
Break line tag <br> is used to give a line break. <br> does not have an end tag.
See the output of the following code to see how <br>tag forces a line break.
37
HTML Basics
Activity 3
Write HTML code to display the following text. Use appropriate tags.
This is my favorite poem
Be Glad Your Nose is on Your Face
By Jack Prelutsky
Be glad your nose is on your face,
not pasted on some other place,
for if it were where it is not,
You might dislike your nose a lot.
2.5. Comments
It is a good practice to use comments to organize your code in a way that is readable to others who
check and modify your code. You can write a comment where ever you like within the HTML code. A
comment is written between <!-- -->.
38
Introduction to Web Development
Here is the example that clearly shows how comments are used. Note that the lines of code that are
commented are not displayed in the browser.
Formatting tags are used to give appropriate font style to the specific text.
39
HTML Basics
Different content based tags are used to choose appropriate style that are
consistent with that specific usage.
Some of the common content-based tags with a brief description are given the following table.
Carefully observe the following code and its output to see how these tags change the appearance of
text when displayed by a browser.
40
Introduction to Web Development
Output of cite
Output of code
Activity 4
o Write a text "My name is Ali and I live in Lahore" in <p> tag, use font style <strong> to
represent this text and show output on web browser.
o Write a text "I am 15 years old" in <p> tag, use font style <em> to represent this text and
show output on web browser.
41
HTML Basics
Bold: <b></b>
The <b> tag is the physical equivalent of <strong> content-based tag. The <b> tag explicitly boldfaces
a character, a word or a segment of text enclosed between <b> and </b>.
Blockquote: <blockquote></blockquote>
The <blockquote> and </blockquote> tag pair defines a section that is quoted from another source.
Italic: <i></i>
The <i> tag is like <em> content-based style tag. The text written between <i> and </i> is displayed in
italic.
Underline: <u></u>
The <u> tag tells the browser to underline the text written between <u> and </u> tag pair.
Typeface: <tt></tt>
The <tt></tt> tag pair directs the browser to display the enclosed text in a monospaced typeface.
The tags discussed above can also be embedded, that is, if we want to make a text both italic and
bold, we need two tags as the following example shows.
Here is an example of HTML code and its output to change the appearance of text in a browser. Try
it yourself as well.
42
Introduction to Web Development
Video Lecture
https://youtu.be/8GLNpyonDAU
Activity 5
Write a text that uses all the physical style tags and show output on web browser.
2.7. Lists
A list is a collection of related items written in some special order or sequence. HTML provides a set
of tags that helps us to organize contents into lists. There are two major types of HTML lists:
unordered lists and ordered lists.
43
HTML Basics
The HTML tags that are used to create lists are given in table 2.4.
Let us see how these tags are used to create ordered and unordered lists.
We use <ol> tag for ordered list. Each list element starts with <li> tag.
The items of the ordered list are enclosed in <ol> and </ol> tags. Each element of the list is tagged
with <li>, which does not have an ending tag. For example, we can create an ordered list of favorite
drinks by using the following piece of code.
The following HTML code illustrates how ordered lists are created using <ol> and <li> tags. Items in
each ordered list are numbered automatically starting with 1.
44
Introduction to Web Development
For example, the following code creates an unordered list of my favorite drinks.
Unordered lists are created with <ul> tag. Each item in the list is preceded with
a bullet symbol in a browser.
The following complete HTML code shows the use of <ul> tag.
45
HTML Basics
An unordered list
Activity 6
Create an unordered list of car manufacturers (Honda, Toyota, Mercedes, Ford, and Suzuki).
46
Introduction to Web Development
<ul>
<li>Saturday</li>
<li>Sunday</li>
<li>Monday</li>
<li>Tuesday</li>
<li>Wednesday</li>
<li>Thursday</li>
</ul>
<li>Off day:</li>
<ul>
<li>Friday</li>
</ul>
</ol>
</body>
</html>
The output of above code is given in figure 2.13. The output clearly shows the difference between
ordered and unordered list.
Ordered list
Video Lecture
https://youtu.be/5yKteejDGZM
47
HTML Basics
Activity 7
Write HTML code to create the following lists:
1. Subjects in Secondary School
• English
• Mathematics
2. Subjects in Bachelor
• Mathematics
• Physics
• Chemistry
• English
Unit Summary
In this unit, we learned how to use a text editor (such as notepad) to type and save HTML code and
view its output in a browser. We have also learned how to use basic HTML tags with the help of
examples.
48
Introduction to Web Development
2. What are the two things you need to create and view web pages?
A. A text editor and a compiler
B. A text editor and a web browser
C. A compiler and a web browser
D. A compiler and interpreter
3. Should <! DOCTYPE > declaration be the first thing in an HTML document?
A. Yes, always
B. Yes, but only when the Strict version is used
C. No
D. Both A and B
49
HTML Basics
D. <b>
Answer Key:
1. B 2. B 3. D 4. B 5. C 6. A 7. B 8. A 9. C
Review Questions
Write short answers of the following questions.
50
Introduction to Web Development
51
HTML Basics
52
Introduction to Web Development
UNIT 3
53
HTML Links, Images and Tables
Introduction
In the previous unit, we learnt how to create a web page and see its output in a browser. We also
learnt how we can structure a web page and use a variety of tags to change the physical appearance
of text. In addition to the basic tags that we discussed in Unit2, HTML provides a number of tags that
can be used to make a web page more attractive by adding multimedia elements, such as images. As
we know that a website, generally, has more than one pages which are linked together using
hyperlinks. Sometimes, formatting the text and data in tabular form is the best way to structure a
document and HTML provides a tag that allows us to format the text and data in tabular form. In this
unit, we will learn the HTML tags which are used to add images, links and tables in a web page.
Unit Outcomes
Upon completion of this unit, you should be able to:
1. Embed graphics with suitable size and location in a web page.
2. Create hyperlinks to link web pages together.
3. Use a set of HTML tags to structure data/information in tabular form.
Terminologies
54
Introduction to Web Development
A web page may contain text, images and other multimedia elements.
HTML standards do not prescribe an official format for images and sounds. However, the popular
browsers support many different types of image and sound formats. Some of the popular formats
are:
1. Graphics Interchange Format (GIF) was adapted during 1980s because of its widespread use
on CompuServe. It enables users to exchange images between different platforms. It is now
widely used in applications supporting graphical capabilities.
2. Joint Photographic Experts Group (JPEG) is another popular image format. It has some
advantages over GIF such as it supports millions of colours and is highly compressible.
Therefore, it takes up less space and downloads faster than a GIF image with similar details.
3. Tagged Image File Format (TIFF) was designed by Microsoft and Aldus for use with scanners
and desktop publishing programs.
4. MPEG is an animated video standard format based on the JPEG method. The format
received its name from the group that defined the standard, i.e. Motion Picture Experts
Group. It is the most commonly used movie format for the WWW.
5. PNG format holds special promise as a replacement for the aging GIF standard.
6. AVI is the movie format native to Microsoft Windows.
7. QuickTime is another popular format developed by Apple Computer.
8. WAV is the native sound-file format for Microsoft Windows.
9. MIDI is a popular electronic-music format and is supported by a variety of browsers and
platforms. MIDI files are digitally synthesized directly from a computer rather than recorded.
10. RealAudio format is another popular sound format. Streaming audio (RealAudio) begins to
play as soon as a minimal portion of the file downloads; while that portion is playing, the
next is downloaded.
Multimedia files have standard file extensions depending on the image or sound format used. The
following table gives the extensions for each of the formats.
55
HTML Links, Images and Tables
We use <img> tag to add an image in a web page. <img> tag does not have a
separate end tag.
The following HTML code shows how we can add images in a web page using <img> tag.
56
Introduction to Web Development
When the above HTML document is opened in a browser and we have “tree.png” image on our
computer, the following output will be displayed.
Use width and height attributes to set width and height of an image
respectively.
The following HTML code displays two images with a specified width and height. Look at the output
of the code to see how the browser adjusts the images according to the specified width and height.
57
HTML Links, Images and Tables
Activity 1
Create a web page that provides some basic information about your city. Add some images of your
city to make the page more attractive and informative.
There are a number of tags that can be used to create link, as shown in the following table:
Below we discuss how these tags can be used to link documents together.
58
Introduction to Web Development
<a></a> tag is used to create a link of a web page with another one.
For example, if we want to link a web page to another page (e.g. document2.html), the <a> tag is
written as follows:
Clicking on the text written between > and </a> will make the browser load document2.html.
The following HTML code links our page to “document2.html” using <a> tag.
The output of the above code is shown in figure 3.3. Notice that the browser, generally, displays the
text which comes between <a> and </a> underlined or in a different color. Selecting the link by
making a mouse click on "Click here" will make the browser to open document2.html.
59
HTML Links, Images and Tables
Activity 2
Create a web page that provides some basic information about you. Create a link on this page to
open the page that you have already created in activity 1.
For example, a part of an HTML document can be given a name using the <a> tag as shown below:
The value of the NAME attribute is any character string, enclosed in quotation marks. To jump a
name section of a document, we can use <a> tag as given below
When user clicks on the text “Click here”, he jumps directly to the section named as “section 1”.
Use of NAME attribute is very useful when a web page is quite long and we want to allow the user to
jump to various parts of the same document.
href tag is used to link to a section of the same page, the section name starts
with #.
Have a look at the following HTML code and see how we first name a section of the document and
then created a link to it using href.
60
Introduction to Web Development
Activity 3
Create a multi-section long web page that allows the users to jump to various part of the same
document.
Video Lecture
https://youtu.be/9BqIcMvRDGs
Activity 4
Create a web page, insert some of your favorite images, convert these images as hyperlinks.
61
HTML Links, Images and Tables
Link tag is used to link an HTML document with external CSS and JavaScript
code.
3.3.5. <nav></nav>
The <nav> tag is an HTML5 specific tag that is not supported by older versions of HTML, therefore
old browsers cannot recognize it. <nav> stands for navigation, which defines a menu of different
links that point to other (internal or external) web or documents. Each menu item is a hyperlink
(<a>) that can be clicked to navigate to other resources. The <nav> tag must be written within the
<body> of the HTML document.
62
Introduction to Web Development
3.4. Tables
Tables are used to organize data/information in rows and columns. Table entries can contain images,
paragraph, lists, and even other tables. Furthermore, the border around the table and between cells
can be suppressed so that the reader may be unaware that a table is being used. Basic HTML tags
used in creating tables are summarized below followed by a brief explanation for each of them.
Tables are a useful way of organizing data. Column heading defined with <th>
are automatically displayed as bold.
<table></table>
An HTML table can be created using the <table> tag. This tag must be located within the <body>
section of an HTML document. By default, table does not have border. To give table border, we use
border attribute of <table> tag as shown below.
<table border="1">
<tr></tr>
The <tr> tag with its ending </tr> tag is used to define a row of a table. A table row can either a
column heading or row data. The <th> tag with its ending </th> tag is used to assign headers to the
table columns. Data can be defined using the tags <td> and </td>.
<tr> tag is used to create a table row. A row can be column headings or data.
63
HTML Links, Images and Tables
<th> tag is used to define column headings and <td> tag is used to define data
in each column.
Note that our table has three rows (including row with column headings). To create the column
heading, we need to write the following code:
<tr>
<th>Physics</th>
<th>Chemistry</th>
<th>Maths</th>
</tr>
Note that the column heading is specified as a row of the table. Each column heading is written using
<th></th> tag pair. If a column does not have a heading, we still have to write <th></th> for that
column. To create the second row, we need to write the following code:
<tr>
<td></td>
<td>50</td>
<td>70</td>
<td>65</td>
</tr>
Note that data for each column is written between <td> and </td> tags.
Below is the complete code to create the above table. See how each row and data in each column
has been given using <tr> and <td> tags.
64
Introduction to Web Development
<td>70</td>
<td>65</td>
</tr>
<tr>
<td>Moen</td>
<td>77</td>
<td>82</td>
<td>45</td>
</tr>
</table>
</body>
</html>
You might have noticed that the table, by default, does not have borders. A programmer has to
define borders and lines in the table. To do that, we use BORDER attribute of <table> tag to specify
the width (in pixels) of the border around the table. For example, <table border=”1”> gives a table
border of WIDTH=1.
Activity 5
In the above HTML code, change the <table> to <table border=”1”> and see the output. Change the
border width by changing the number to 2, 3 and 4 and observe the difference.
The <caption> tag must be the first tag just inside the <table> tag.
65
HTML Links, Images and Tables
Activity 6
Add a caption in your table that you created in the previous activity.
We can merge rows and columns of table using rowspan and colspan attributes
of <td> and <th> tags.
<tr>
<th rowspan ="2">Name</th>
<th colspan ="3">Subjects</th>
<tr>
Now we create the second row of the table that has the subject headings. This can be done as
follows.
<tr>
<th>Physics </th>
<th>Chemistry </th>
<th>Math </th>
<tr>
Note that we do not specify the heading for column 1 (name) of row 2 since it is already merged
with row 1. Complete HTML code for creating table 3.6 is given below:
66
Introduction to Web Development
67
HTML Links, Images and Tables
Video Lecture
https://youtu.be/MEioWGewTkI
Activity 7
Write HTML code to create the following table.
Activity 8
Explore other attributes that can be used with <table>, <tr>, <th> and <td> tags.
Unit Summary
In this unit, we learned how to embed graphics with suitable size and location in a web page. We
also learned how to create hyperlinks to link web pages together. We also discussed how to use a
set of HTML tags to arrange data in tabular form.
68
Introduction to Web Development
3. If the image cannot be displayed in the browser, _______ specifies an alternate text for the
image.
A. value attribute
B. caption attribute
C. alt attribute
D. text attribute
5. The <img> tag automatically inserts a carriage return after displaying its graphics.
A. True
B. False
8. You can set image width and height based on your requirement using width and height
attributes.
A. True
B. False
69
HTML Links, Images and Tables
11. Which tag is used to link a style sheet to your web page?
A. <link>
B. <a>
C. <nav>
D. None of the above
Answer Key:
1. A 2. A 3. C 4. A 5. B 6. A 7. C 8. A 9. B 10. A
70
Introduction to Web Development
Review Questions
Write short answers of the following.
1. What are the two most common graphic formats used on the web?
2. What do you understand by loosy graphic format?
3. What is the purpose of ALT attribute?
4. Is it possible to ALIGN all of the data cells in a particular row using the <tr> tag?
5. What is difference between <a>, <link> and <nav> tags?
6. How do you specify column headings of a table?
7. How can data be specified for a single row of a table?
8. How do we merge two columns of a table together?
9. How do we merge two rows of a table together?
2. Create a website that gives basic information about yourself. You should prepare a separate
page for each of the following: personal information, academic qualification, professional
qualification, job experience, hobbies, and photo gallery. Academic qualification page
should display the information about your degrees and certificates along with the subjects
you studied in each in a tabular form.
3. Prepare multiple web pages with suitable links that provide basic information about a
number of medicines. Add suitable images.
4. Prepare a web page that displays marks obtained by a number of students in 5 different
courses. You should also display student name and his photo alongside the marks obtained.
Use tables.
71
HTML Links, Images and Tables
72
Introduction to Web Development
UNIT4
73
HTML Marquee, Form and Input Types
Introduction
We have so far learnt some important HTML tags to develop a good website. We have learnt how a
document can be structured in sections and paragraphs, how we change physical appearance of our
document and its elements, how we insert multimedia contents and table and links web pages
together. HTML provides a few more tags to the web developers. One such tag is marquee tag which
causes text to scroll up, down, left or right automatically which is, sometime, very useful. Another
important tag is iframe or inline frame which is used to display external objects including other web
pages within a web page.
Last but not the least is a form in an HTML document. HTML Form is one of the main points of
interaction between a user and a website or application. The user uses it to send data to the
website. An HTML Form consists of one or more widgets. These widgets can be text fields (single line
or multiline), select boxes, buttons, checkboxes, or radio buttons. Mostly, these widgets are paired
with a label that describes their purpose.
Unit Outcomes
Upon completion of this unit, you should be able to:
1. Embed a document in your web page using marquee tag.
2. Create a web page with multiple iframes.
3. Create form for getting user data.
Terminologies
Marquee: A scrolling piece of text on a web page.
Form: Allows a user to enter data on a web page.
Textbox: It is a rectangular area for entering text in a web page.
Dropdown list: It is a list of items for selecting a value from pull down menu.
Radio button: It is used to select one option from set of many option
Check box: It is used to select more than one options.
Iframes: HTML document that is embedded inside another HTML document.
74
Introduction to Web Development
4.1. Marquee
A marquee is a scrolling piece of text displayed either horizontally across or vertically down a web
page depending on the settings. It is created by using HTML <marquees> tag. The <marquee> tag
may not be supported by all browsers so it is not recommended to rely on this tag, instead we can
use javascript and CSS to create such effects.
The attributes that can be specified with the marquee tag are given in the following table.
Try the following code and see its effect for yourself.
75
HTML Marquee, Form and Input Types
By default, when we use marquee tag, the text written between the tag moves from left to right. To
change the direction or behavior of text we use “direction” and “behavior” attributes. Below
example will clarify how to change the direction and behavior of text which are written between
marquee tags.
The above code will move the text on right side while the behavior of text is slide. The following
output (figure 4.2) will clearly show you that the text is moving on right side.
76
Introduction to Web Development
</body>
</html>
4.2. Forms
A form is an interface between a user and a browser through which the user can enter the required
information. One of the reasons for having the CGI (Common Gateway Interface) is that two-way
communication is possible with HTML. The client can enter information by selecting buttons, pulling
down or scrolling through menus, and entering text into text boxes. The interactive building blocks
can be brought together and defined as a form. You can see forms when you create a new email, or
send a comment in a forum on a website.
Let us discuss various attributes and tags related to forms in more detail.
4.2.1.<form></form>
A form can be placed anywhere in the body of HTML document with its elements enclosed by the
<form> tag and its ending </form> tag. The <form> tag has two important attributes: action and
method. The action attribute points to the server side script (the ‘back end’) that handles the form
submission. Usually, this will be a script (PHP, ASP, and Perl) or a CGI program. The method attribute
has a value either GET or POST. When sending data, the GET method adds the data to the URL with
77
HTML Marquee, Form and Input Types
maximum URL length of 2048 characters. This method should not be used when sensitive data, such
as user information and passwords are to be sent, because all the information will be available in
clear text form in the URL. The POST submits data from an HTML form to an identified resource and
the data is included in the body of the request. Information sent with post method will not be visible
and therefore it is used to send sensitive information.
Suppose our script to handle the form data is written in php named as formmail.php. The HTML
form tag will be written as given below
4.2.2. <input>
We can have different types of input elements in a form such as check boxes, radio buttons, simple
text boxes etc. The <input> elements are used within a <form> element to declare input controls
that allow users to input data. The table given below describes different input types available in
HTML.
Where type="text" tells the browser that a single line of text input box should be created and
name="First Name" gives a name to the input field. The field name is used to identify the field on the
server and client side.
78
Introduction to Web Development
<input type = "text">is used to create a single line text box in the form in which
user can enter a line of text.
Activity 1
Create a form that has the following two text boxes: Movie Title, Name of Hero.
There are some other attributes that can be used with the text boxes as discussed below:
A text element can be given a default value which will be displayed inside the text box when the
form loads. A default value is specified by using value attribute as shown below
79
HTML Marquee, Form and Input Types
We can also specify maximum number of characters a user can enter in a text box by using
maxlength attribute as:
<input type = "password"> is a single line text box which hides the characters
when entered by a user.
80
Introduction to Web Development
<input type="reset">
When you click on reset button on form, it will reset to the default value.
Activity 2
Add Reset and Submit buttons in the form that you created in activity 1.
<form>
<input type="file" name = "upload" value="upload">
</form>
81
HTML Marquee, Form and Input Types
For example, if we want to create radio buttons that allows a user to select his/her gender, we have
to specify each value separately with <input > tag and the name attribute must have the same value
for each radio button as the following code shows.
The text written after the input tag (i.e. after >) will be displayed after the radio button.
</form>
</body>
</html>
82
Introduction to Web Development
Video Lecture
https://youtu.be/aQM3PTV8r7g
Activity 3
Add a new field "Movie Type" in the form you create in activity 2. You should create the following
three radio buttons from which a user can select an option: Comedy, Horror, Action. This new field
should be added just before Reset and Submit buttons on your form.
83
HTML Marquee, Form and Input Types
A date can be
selected from the
calendar.
84
Introduction to Web Development
Activity 4
Add a new field “Release Date” in your form that you created in activity 3. This new field should be
created after the “Movie Type” field on the form. The user should be able to select a date from the
calendar.
<input type="email">
Input type email is used to get email as input from a user. The code below shows how to get email as
input from a user.
<form>
<input type="email" name = "email" >
</form>
Activity 5
Add a field email address in your form that you created in Activity 4 to read email address of a user.
The following example shows a text area with 4 lines (rows) and 50 characters per line:
85
HTML Marquee, Form and Input Types
Activity 6
Add a multi-line text area “Feedback” in the form that you created in activity 5.
<select name="foods">
<option value="pizza">Pizza</option>
<option value="burger">Burger</option>
</select>
The name attribute in <select> tag gives a name to the drop-down list and value attribute of
<option> tag gives a value to each option. The options that appear on the drop-down list are
specified between <option > and </option>.
Select box also called dropdown list are used to select one option from
dropdown list.
86
Introduction to Web Development
4.2.5. <datalist></datalist>
This tag is similar to <select> tag. However, there are two major differences between <datalist> and
<select>. The first one is that <datalist> tag works only with HTML 5. The second difference is that
the <datalist> tag has a small textbox where the user can type a text to search for an item in the list.
This feature is very important when we have a large list of options to select from.
The following example shows how to create a list of browsers using <datalist> tag.
87
HTML Marquee, Form and Input Types
Activity 7
Create a datalist “Your favorite Movie type” in your form that you created in activity 6. The datalist
should have the following options to choose from: Horror, Action, Comedy, Drama, and Musical.
88
Introduction to Web Development
Video Lecture
https://youtu.be/RtqFjhQsfPA
89
HTML Marquee, Form and Input Types
Activity 8
Create a web page that provides some basic information about your city. Add some images of your
city to make the page more attractive and informative.
4.3. Iframes
Frames are areas (containers) where information from another web page can be displayed within a
web page. For example, to open AIOU website in an iframe, we give link of AIOU website in a href
attribute. The following code shows how to give link attribute in iframe.
We can set width and height of iframe by giving its size in pixels or in percentage. For example, the
following code sets width = "100%" and height = "300px" to iframe and gives it a name "iframe_a".
Now we can open a web page or a different website in the frame using href as shown in the code
below
Note that the value of the target attribute is the name of the iframe in which we want to open a
different page or a website. The website of AIOU will open in the iframe when the user clicks on the
text “AIOU Website”.
90
Introduction to Web Development
Activity 9
Create two web pages and display them using iframes.
Unit Summary
In this unit, we learned about how to embed a document in a web page using marquee tag. We also
learned the development of a web page with multiple iframes. The last section of the unit is focused
on the development of HTML forms and demonstrates, how to get user data using form elements.
91
HTML Marquee, Form and Input Types
1. Which of the following code is used to scroll the text from left to right?
A. <marquee behavior = "slide" direction ="right">
B. <scroll behavior = "slide" direction = "right">
C. <marquee behavior = "slide" direction = "left-to-right">
D. None of the above
2. Which of the following tag is used to specify a multi-line text area in a form?
A. <input type="Multi-text">
B. <textarea> <textarea>
C. <form type="textarea">
D. None of the above
4. Which of the following code is used to create a single-line text box in a form?
A. <input type="text" name="name">
B. <input type="text-box" name="name">
C. <form type="text" name="name">
D. <input type="box" name="name">
92
Introduction to Web Development
Answer Key:
1. A 2. B 3. B 4. A 5. A 6. C 7. B 8. A 9. A 10. C
Review Questions
Write short answers for the following questions.
93
HTML Marquee, Form and Input Types
94
Introduction to Web Development
UNIT5
95
Cascading Style Sheet
Introduction
You might have noticed in the previous three units that HTML is basically a poor language for page
formatting and styling. This is understandable since the scientific environment in which it was
conceived, people were more concerned with the content rather than the presentation. To
overcome stylistic limitations of HTML, the style sheets represent a major breakthrough for Web
page designers, expanding their ability to improve the appearance of their pages. Cascading Style
Sheets (CSS), as we know them, enable designers to add styles to the HTML Document. CSS
describes how elements are to be displayed on screen. It handles the look and feel of a web page.
With the help of CSS, we can control text color, column sizes and layout of tables, text fonts, spacing
between paragraphs, columns size and layout, background images or colors, layout designs, and so
on. Though very powerful, CSS is easy to learn and understand. This unit provides an introduction to
CSS and how we can use them to improve the presentation of our web page.
Unit Outcomes
Upon completion of this unit, you should be able to:
1. Describe use and advantages of Cascading Style Sheets.
2. Describe external style sheet, internal style sheet and inline style.
3. Write suitable CSS code for different HTML elements.
Terminologies
CSS: Cascading Style Sheet is a design language used to give style to a web
page
External Style Sheet: It contains CSS code in the head section of same web page which is linked
to an HTML document.
Internal Style Sheet: It is defined within the same web page. It contains CSS code in the head
section of same web page.
Inline Style Sheet: Inline style is used to give style to a particular tag.
96
Introduction to Web Development
• CSS saves time –We can define a style for each HTML element and apply it to as many web
pages as we want.
• Pages load faster − If we use CSS, web pages can load faster.
• Easy maintenance – To make stylistic changes require only changing CSS file which will affect
all the web pages using that CSS file.
• Superior styles to HTML − CSS has a much wider array of attributes than HTML, so we can give
a far better look to HTML pages as compared to HTML attributes.
• Multiple Device Compatibility − Style sheets allow content to be optimized for different types
of device. By using the same HTML document, different versions of a website can be presented
for handheld devices such as PDAs and cell phones or for printing.
• Global web standards –Since certain HTML attributes are being deprecated therefore it is
recommended to use CSS in all the HTML pages to make them compatible to future browsers.
• Offline Browsing − CSS can store web applications locally with the help of an offline cache. It
allows viewing of websites offline. The cache also ensures faster loading and better overall
performance of a website.
• Platform Independence − The CSS script offers consistent platform independence and can
support latest browsers as well.
Introduction
CSS is amazing. It makes my website look great. Really
loving it.
Let us see, how we can do all of the above by adding a few more lines of code in our HTML
document (don’t worry if you do not understand the code at this time, just do it). Here is the code
that you should type.
97
Cascading Style Sheet
What we have done is a simple thing. We simply told the browser how to format and style a web
page and its various elements such as headings. Have a look at the code written between <style>
and </style>. It is easy and quite self-explanatory. It tells the browser how to display and format two
elements of HTML (body and h1). Now let us get into the details of CSS
Activity 1
Try the above code by changing the font color to blue and font size to 24. See your output in the
browser.
98
Introduction to Web Development
<head>
<link rel= "stylesheet" type= "text/css" href ="mystyle.css">
</head>
In external style sheet, CSS code is stored in a separate file and linked with an
HTML document using <link> tag. CSS files should have .css extension.
For example, to create the web page that we did in our previous example, we first write the
following CSS code in a separate file.
h1
{
font-size: 20px;
color: red;
text-align: center;
}
The above CSS file now can be linked with our main HTML code as shown in the following code.
99
Cascading Style Sheet
Video Lecture
https://youtu.be/Ueqbgb-6cZY
Activity 2
Change the style sheet and set the font color to blue and font size to 24 using external style sheet.
See the output of the HTML file in the browser.
We use internal style sheet to specify style for a specific web page.
100
Introduction to Web Development
</body>
</html>
Video Lecture
https://youtu.be/GBlTN83inGQ
</body>
</html>
Inline style is used to define style for a single HTML tag in the document.
Activity 3
In the above code, add <h2> and some text under it. Display h2 with a font size of 16 and in blue
color. See the output of the HTML file in the browser
101
Cascading Style Sheet
Activity 4
Which style sheet you will use if a website has a single page? Give reasons.
The selector refers to the HTML tag or element that we want to apply the style on. A selector can be
an HTML element name, id, class, or an attribute etc. For example, the above figure defines
properties for <h1> tag. A declaration is a combination of a property name and a value separated by
a colon. Each declaration must end with a semi-colon, even if there is only one declaration. The
declaration set must be included between curly-braces. A CSS rule-set can be written in a single line,
or multiple lines. That is we can define the style for <h1> as
h1
{
font-size: 20px;
color: red;
102
Introduction to Web Development
text-align: center;
}
The above style definition can also be written on a single line as shown below
Each declaration consists of a property name and its value pair and ends with a
";".
We have mentioned above that a selector can be an HTML element name, id, class, or an attribute.
Let us see how they are different from each other.
Element selector can be used to define the style for HTML element name.
Once the style is defined, it will be applied to all paragraphs (tag <p>) automatically by the browser.
A complete example of HTML code is given below. Note that we are using internal style sheets in our
example. You can use external style sheets, if you like.
103
Cascading Style Sheet
</html>
Activity 5
1. Create the above web page by removing the style from the HTML document and store it in a
CSS file instead. Link your document with the style sheet.
2. Repeat the above activity by using inline style.
5.4.2. ID Selector
The ID selector is used to select a specific HTML element. The ID of an element must be unique. To
select an element with a specific ID, (#) character is used with ID name. Suppose we want to apply a
style to one or more specific paragraphs (but not to all), then we should define the style as:
#p1
{
font-size: 25px;
color: white;
text-align: center;
}
Now, we can use the above style with a paragraph by specifying the above style as shown below:
Note that the element selector applies to all whereas an ID selector is applied to the selected
elements. We can define multiple styles for a single element. Try the following example and observe
the output. We notice that style is applied to the second paragraph only.
104
Introduction to Web Development
105
Cascading Style Sheet
/* A comment */
106
Introduction to Web Development
Comments are written within /* and */. Comments are not executed by the
browser.
The following code shows how useful comments can be written in an HTML document. See the code
below how we can write useful comments in an HTML document.
1. Background property
2. Border, margin & padding properties
3. Height / width property
4. Text
5. Fonts
6. links
7. Lists
8. Tables
We will discuss how to set the above properties in this and the next unit. Let us start with the
background property.
107
Cascading Style Sheet
background-color
This property defines the background color of an HTML element or a document. The background-
color property is defined as:
background-color: color;
For example, to set background color of an HTML document, we specify the background-color
property as:
body
{
background-color: lightblue;
}
The following example shows how to set background color for a paragraph
p
{
background-color: yellow;
}
Similarly, the following code can be used to set the background-color for <h1>.
h1
{
background-color: yellow;
}
See the HTML code below that sets the background color for the whole document to blue.
108
Introduction to Web Development
Activity 6
1. Change the background color of the document to red and background color of heading h1 to
white.
2. Repeat the above activity by storing the style in a CSS file and linking it to your HTML
document.
background-image
We can use an image as a background of an HTML document to make it look like a wallpaper. The
following example illustrates how to use background-image property:
body
{
background-image: url("paper.gif");
}
By default, the image is repeated on the screen to cover the whole document. Try the following code
and see the output in the browser.
109
Cascading Style Sheet
p
{
color: white;
text-align: center;
}
</style>
</head>
<body>
<p>This is Paragraph 1 </p>
<p>This is Paragraph 2</p>
</body>
</html>
Activity 7
Change the background image in the above code to one of your favorite images.
background-repeat
Some images are designed in a way that they can be attached to each other, either horizontally or
vertically, to form a certain design. By default, background-image property repeats the images both
vertically and horizontally. To set the repeat direction of a background image, we use background-
repeat property that accepts one of two values: repeat-x or repeat-y. To prevent the image from
being repeated, we use the value no-repeat.
The following example shows how to use background-repeat property. Keep in mind that
background-repeat must be used along with background-image property and not by itself.
body
{
background-image: url("tree.png");
background-repeat: repeat-x;
110
Introduction to Web Development
The following code displays an image in the background with repeat property. The output is
amazing.
111
Cascading Style Sheet
Video Lecture
https://youtu.be/oKK9IjKweqs
Activity 8
1. Change the repeat property in the above code to repeat-x, repeat-y and no-repeat. What do
you notice in the output?
2. Repeat the above activity by storing the style sheet in a CSS file and linking it to HTML
document.
background-attachment
This property determines whether that background image will scroll or not when the content with
which it is associated scrolls. This can be specified by background-attachment property as shown in
the following code.
body
{
background-image: url("img_tree.png");
background-repeat: no-repeat;
background-attachment: fixed;
}
In the above code, we set the background-attachment to “fixed” which allow us to scroll up and
down in the document without moving the background image.
background-position
This property determines the position of the background image within the canvas space used by its
element. The background position can be set to "left top", "left center", "left bottom", "right top",
"right center", "right bottom", "center top", "center center". If we specify only one value only, the
second value is taken as center.
112
Introduction to Web Development
The following example defines the position of the background image as top right side of the
document.
body
{
background-image: url("tree.png");
background-repeat: no-repeat;
background-position: right top;
background-attachment: fixed;
}
The following code displays an image on the top right side of the web page. We can see in the
output that the image is displayed on the top right side of the web page, while “background-
attachment” is used to fix the background image so that image will not scroll.
113
Cascading Style Sheet
Activity 9
Use different values for background-position property in the above code and observe its effect in the
output.
Unit Summary
In this unit, we learned about advantages and the use of Cascading Style Sheet in web page
development. We discussed how CSS code can be written to style different HTML elements. We
have also discussed the differences and usage of external, internal and inline style sheets.
114
Introduction to Web Development
2. Which of the following property is used to set the background image of an element?
A. background-color
B. background-image
C. background-repeat
D. background-position
4. Where in an HTML document is the correct place to refer to an external style sheet?
A. At the end of the document
B. In the <head> section
C. At the top of the document
D. In the <body> section
115
Cascading Style Sheet
8. What is the correct CSS syntax for making all the <p> elements bold?
A. <p style = "text-size:bold">
B. p {font-weight:bold}
C. p {text-size:bold}
D. <p style = "font-size:bold">
10. Which CSS property is used to specify position of the background image?
A. background-position
B. image-position
C. background-image-position
D. None of the above
Answer Key:
1. D 2. B 3. C 4. B 5. A 6. A 7. C 8. B 9. A 10. A
Review Questions
Write short answers of the following questions.
116
Introduction to Web Development
117
Cascading Style Sheet
118
Introduction to Web Development
UNIT 6
119
Text, Border and Table Properties in CSS
Introduction
In the previous unit, we discussed some basic concepts of CSS and how we can enhance the
appearance of our web pages by specifying various properties of HTML document and its elements.
We continue to explore CSS in this unit as well to see how we specify some other documents, texts
and table properties.
Unit Outcomes
Upon completion of this unit, you should be able to:
1. Specify and use various text properties.
2. Specify and use various table properties.
3. Specify and use various document properties.
4. Develop a web page that use CSS.
Terminologies
Text properties: It is used to change the presentation and layout of text.
Border properties: It allows to customize border in an HTML document.
Margin properties: It is used to set spaces around the elements.
Table properties: It allows to set presentation and layout of table elements.
120
Introduction to Web Development
Text properties can be used to change the appearance and layout of text.
For example, the following CSS code sets properties of <h1> to red color, center and underline.
h1
{
color: red;
text-align: center;
text-decoration: underline;
}
If we want that each sentence of a document starts with a capital letter, we will specify it as
body
{
text-transform: capitalize;
}
The following code can be used to set the indent and text align properties of a paragraph to 12pt
and justify.
121
Text, Border and Table Properties in CSS
Below is a complete HTML and CSS code that specifies various properties for the document and <h2>
tag.
122
Introduction to Web Development
Video Lecture
https://youtu.be/IgsTOtqGOhA
Activity 1
Specify the following properties for the above document: Heading should be red, 20 points, centered
and underlined. Paragraph text should be in blue, left justified and indented by 20 point.
Border properties can be used to specify border style, width and color.
123
Text, Border and Table Properties in CSS
We can define different border types for different elements of a web page. We can also set border
width by using border-width property. For example, to specify a thick border for a paragraph, we use
the following code
The following brief example shows how we can define different types of borders for different
paragraphs of a document.
We can set border style as well as its thickness using border properties. Explore
other possible values for the border-width property.
</head>
<body>
124
Introduction to Web Development
Video Lecture
https://youtu.be/YMiyQxjQ-fk
Activity 2
Write a small document that gives some information about 3 different cities. The information for
each city should be written in different types of borders having different thicknesses.
125
Text, Border and Table Properties in CSS
Margin properties can be used to specify the margin around HTML document.
In the following example we give margin to the all four sides of <div> element. See the effect of it in
the output.
The following output shows that how spaces are created through margin.
126
Introduction to Web Development
127
Text, Border and Table Properties in CSS
The following output shows that how padding property adds spaces around the text.
Activity 3
Change the top and bottom heading to 100px and see its output.
128
Introduction to Web Development
border property
The border property can be used to different properties in the following order. The general format
of border property is
The border-width property sets the width of an element's four borders. The value of border-width
property can be thin, medium or thick. We can also specify the thickness in number of pixels.
The border-style property can have one of these values: none, hidden, dotted, dashed, solid, double,
groove, ridge, inset, outset. The border-color property can be used to set the color of the four
borders. For example, the following code sets table border having thick border width, double line
style and red color
<style>
table
{
border: thick double red;
}
</style>
Similarly, we can set properties of <tr>, <th> and <td> tags as well. The following CSS code sets the
background color of <th> to green and text color to white.
th
{
background-color:green;
color:white;
}
Below is complete HTML and CSS code that sets various properties of whole document body as well
as of the table.
table
{
border-collapse: collapse;
129
Text, Border and Table Properties in CSS
table, th, td
{
border: 1px solid black;
}
h2
{
text-align: center;
font-size: 25px;
}
</style>
</head>
<body>
<h2> Table Properties in CSS</h2>
<table>
<tr>
<th>First name</th>
<th>Last name</th>
</tr>
<tr>
<td>Ali</td>
<td>Ahmad</td>
</tr>
<tr>
<td>Zahid</td>
<td>Ahmad</td>
</tr>
<table>
</body>
</html>
border collapse
130
Introduction to Web Development
By default, table as well as columns of a table have their separate borders. The border-collapse
property can be used to have a single border for table as well as for the columns. This property is
specified as
table
{
border-collapse: collapse;
}
caption side
The caption-side property specifies the placement of caption of a table. Its default value is top which
can be changed to bottom using the following code
caption
{
caption-side: bottom;
}
Activity 4
Create a table given in figure 6.5 with suitable caption at the bottom. Also use the border-collapse
property to collapse the border of a table.
Position is the property that tells the browser how to position the element.
Position property specifies the type of position method used for an element. There
are four different position values.
• Static
• Relative
• Fixed
• Absolute
Static Positioning
This is the default way HTML elements are positioned. Static position elements are not affected with
top, bottom, left and right properties. The element with static position is not specifically positioned,
they always positioned as normal flow on the page.
131
Text, Border and Table Properties in CSS
Absolute Positioning
Absolute position places the HTML element on the page at precise position. We can place elements
anywhere in the web page by simply giving values to the properties top, down, left and right. With
the help of following example you can easily understand the working of an absolute position in a
web page.
With the help of absolute positioning, you can place your element anywhere in
your web page.
132
Introduction to Web Development
Relative Positioning
Relative position means "relative to itself". For example, if we set position relative to an element but
not giving any attributes (top, left, bottom, right), the position of an element will be considered as
static. But if we give some position attributes, let us say top = "10px", it will shift position 10 pixels
down where it would normally be. With the help of following code, you can easily understand the
working of relative position.
133
Text, Border and Table Properties in CSS
Fixed Positioning
Fixed position is the positioned relative to viewport which means it always stays in the same place
even if page is scrolled. You can use properties top, left, right and bottom to position the element.
134
Introduction to Web Development
In fixed position, your element position is fixed whether you can scrolldown
your page.
135
Text, Border and Table Properties in CSS
Unit Summary
In this unit, we learned about the use of various text, table and document properties. We have also
discussed how to make attractive web pages with the help of CSS.
136
Introduction to Web Development
137
Text, Border and Table Properties in CSS
8. Which of the following property is used to increase or decrease the size of a font?
A. font-size
B. font
C. font-variant
D. font-weight
9. ____________ property can be used to increase or decrease the space between the words?
A. word-spacing
B. word-space
C. space
D. both b and c above
10. The _____________ property is mostly used to remove underline from links?
A. text- trans
B. text-deco
C. text-transformation
D. text-decoration
14. Which of the following property specifies the bottom padding of an element?
A. padding-bottom
B. padding-left
C. padding-right
D. padding-top
Answer Key:
1. B 2. D 3. B 4. C 5. A 6. C 7. B 8. B 9. A 10. D
138
Introduction to Web Development
Review Questions
Write short answers of the following questions.
1. Build the following resume design with the help of following CSS properties:
• Background
• Margin
• Border
• Headings
• Links
• Lists
• Positions
2. Repeat coding exercise by improving your CSS code by including background, margin,
table, border, headings, link and position properties, as appropriate.
139
Text, Border and Table Properties in CSS
140
Introduction to Web Development
UNIT 7
141
Client Side Scripting - I
Introduction
By now, we have learnt how to develop web pages using HTML. We added style into our web pages
using CSS to make them more attractive and lively. We noticed that HTML and CSS do not provide
any programming capabilities and therefore, the web pages were kind of static in nature. It is time
to go a step further and explore how we can make our web pages more interactive and responsive
to user input. Javascript is there to help us in this process. JavaScript is one of the programming
languages that provide us to embed our programming logic into HTML code to make a web page
more integrative and responsive. The javascript code that we embed in HTML document is called a
script. This unit and the next unit will equip you with the basics of javascript. The purpose is to
familiarize you with what you can establish with it and how you can embed javascript in your HTML
code.
Unit Outcomes
At the completion of this unit, you will be able to:
1. To describe difference between client side and server side scripting.
2. Discuss limitations of javascript.
3. Writing java script in body and head section in an HTML document.
4. Linking external java script with HTML document.
5. Understand basic javascript concepts such as variables and comments.
Terminologies
Javascript: It is a scripting language that adds interactivity to the websites.
Client side script: It is a script that runs on the user computer using web browser.
Server side script: It is a script that runs on web server.
Internal javascript: It allows to place javascript code within the same HTML document.
External javascript: It allows to place javascript code in a separate file and link with HTML
document.
Variable: It is used to store information.
142
Introduction to Web Development
7.1. JavaScript
The program code that we embed in an HTML page is called a script. The phrase ‘script’ generally
refers to small programs. The set of instructions are either to the (client-side scripting) or to the
(server server-side scripting). Traditionally, client-side scripting is used for page navigation, data
validation and formatting.
The client-side script runs in a browser. The code is transferred to the user’s computer from server
over the Internet and runs directly in the browser. A server side script, on either hand, runs on the
server which hosts web pages. Script directly runs on the web server to generate dynamic HTML web
pages to fulfill the requirement of end user. These dynamically generated HTML pages are sent to
the client browser.
As we mentioned before that a client-side script runs on the user computer and not on the web
server. What really happens is as follows:
• A user requests a Web page from the server by either entering its URL or clicking on a link.
• After receiving the page request, web server sends the requested page to the user on the
Internet.
• The page is displayed in the browser. If the web page has some script in it, the browser runs
it.
On the other hand, if a page has a server-side script, what really happens is as follows
• The user requests a web page from the server by either entering its URL or clicking on a link.
• If the web page has some script in it, it is interpreted by the server to create or change the
content of the page.
• Finally, the web page in its final form is sent to the end user which is then displayed by a
browser.
Activity 1
Do a web search and prepare a list of languages that are used for client-side and server-side
scripting.
143
Client Side Scripting - I
• JavaScript is executed on the client side to save bandwidth and avoid load on the web
server.
• JavaScript is relatively easy to learn and comprises of syntax that is close to C/C++ and Java.
• It provides plenty of prewritten functionality.
• JavaScript plays nicely with other languages and can be used in a huge variety of
applications.
JavaScript is executed on the client side, easy to learn, faster, works well with
other languages.
• has some security problem as the code execute on the users' computer, and exploited for
some malicious activities.
• does not have multithreading abilities.
• cannot access web pages hosted on different areas.
• cannot directly write to a file on the server side without sending an AJAX request that runs a
server side script.
JavaScript has security Issues, does not support multithreading, cannot access
files and databases.
144
Introduction to Web Development
</body>
</html>
Step 3: Save your document on your computer by selecting File > Save As (go to the menu bar and
click File and then click on Save As). Select the folder in which you want to save the file, enter file
name (such as new.html) and set the encoding to UTF-8 and click on Save button. Note that your file
name should have extension .html.
Step 4: View the HTML document. By double clicking on the HTML file or right-click and choose
"Open with" and select browser to see the output of HTML page.
The output of
javascript code.
Understanding the code is quite easy as far as the HTML tags are concerned. Let us go through the
code that is new for us.
Activity 2
Write a web page that displays your name and address (use JavaScript method document.write).
Display "MY BIO" on the top and at the bottom of the page using HTML tags.
145
Client Side Scripting - I
JavaScript can be written in head and body section of a document. It can also
be in a separate .js file.
Events basically happen as a result of a user action (e.g. clicking a button, pressing a key etc.) or an
external action such as loading a page. HTML provides a way to bind a script to an event. That is, the
script will execute in response to that event. Binding of script to an event is done through an event
handler attributes. It is the name of the event which is prefixed by "on", for example onclick.
Let us say we first want to display “Script demo” when a page is loaded. This can be done by writing
the following code
<scripttype="text/javascript">
document.write ("Script demo");
</script>
Then we want to display a button (a form element). When the user clicks on the button, we want to
display the message ‘You clicked on the button’ as an alert (an alert is displayed in a pop-up
window). To do this, we have to bind our script with the event ‘onclick’. We can use the following
code to do it
<form>
<input type="button" value="click" onclick="alert ('You clicked
on the button');">
</form>
Let us now put the things together and write our complete code.
146
Introduction to Web Development
</head>
<body>
<p>Example: Our first JavaScript</p>
<hr>
<script type="text/javascript">
document.write("Script demo");
</script>
<form>
<input type="button" value="click" onclick="alert('You
clicked on the button');">
</form>
</body>
</html>
Upon clicking on the button ‘click’ an alert will be popup as shown in the figure 7.3.
.
Figure 7.3: Output of javascript popup
147
Client Side Scripting - I
Video Lecture
https://youtu.be/BFONuBSiHcM
Activity 3
Change the alert message to "Hello User" in code 7.2.
Let us now write the same HTML document that we wrote in our previous example, but this time
putting our script in the head section that will execute when the users click on the button. We will
write the code as a function (more about function later)
<script type="text/javascript">
function msg ()
{
alert ('You clicked on the button');
}
</script>
The function has been given the name msg. Now we can call this function in the body of the
document when needed. In our case, we want this code to execute when the user clicks on the
button. This can be specified using the following code;
<form>
<input type="button" value ="click" onclick="msg();">
</form>
Putting the pieces together gives us the following code. Note that we still have some JavaScript in
the body as well and it will execute as usual. Try it and see how it works.
148
Introduction to Web Development
.
Figure 7.4: Output of code 7.3
Upon clicking on the above button ‘click’ an alert will be popup as shown in the following figure.
149
Client Side Scripting - I
Activity 4
Repeat the activity 3 but write the event handler in the head section of the document.
function msg()
{
alert ('You clicked on the button');
}
• Now add a link to this code in the HTML document using the following code
<script src="message.js"></script>
150
Introduction to Web Development
When a user clicks on the button, the javascript executes and displays the alert as shown in the
following figure.
Popup/alert,
which is used to
show a message
to the user.
Video Lecture
https://youtu.be/_aaPbUXpSnY
151
Client Side Scripting - I
Activity 5
Repeat activity 4 by writing a code in a separate file and linking it to HTML document.
• Java script is case-sensitive. This means that capital letters are distinct from their lowercase
counterparts. For JavaScript, this, This and THIS are three distinct identifiers.
• JavaScript code found in HTML document is interpreted line by line and it is read from top to
bottom.
• Any use of excessive whitespace characters (e.g. spaces, tabs, line breaks) are ignored by
JavaScript. For example,
x=5;
Is same as
x = 5;
• JavaScript is written as a sequence of statements. A statement is an instruction to the
interpreter to carry out a specific action.
• A semicolon (;) indicates end of a statement. This allows us to write on or more statement
on the same line separated by ‘;’.
For example,
x=5; y=4;
Is same as
x=5;
y=4;
The general rules for constructing names for variables (unique identifiers) are:
1. Names can contain letters, digits, underscores, and dollar signs.
2. Names must begin with a letter
152
Introduction to Web Development
var x;
var x=5;
In addition, multiple variables can be declared with one var statement but we have to separate each
variable by a comma as shown below.
var x, y, z=15;
153
Client Side Scripting - I
Activity 6
Change the javascript code 7.5 to display average of all the variables.
<script type="text/javascript">
// Declaring variables
var math = 300;
var eng = 400;
var total = math + eng; // it adds up two numbers
document.write(total);
</script>
154
Introduction to Web Development
</body>
</html>
155
Client Side Scripting - I
Activity 7
Add some suitable single and multiline comments in code 7.7.
Unit Summary
In this unit, we learned about the concept of client side and server side scripting and basics of
javascript as client side scripting language. We also learned how to write basic code of javascript in
body and head section in an HTML document. We have also discussed the syntax of variables and
comments in javascript.
156
Introduction to Web Development
1. ______ tag is an extension to HTML that can enclose any number of JavaScript statements.
A. <SCRIPT>
B. <BODY>
C. <HEAD>
D. <TITLE>
4. ___________ is the correct code for referring to an external script called " abc.js".
A. <script href=" abc.js">
B. <script name=" abc.js">
C. <script src=" abc.js">
D. None of the above
6. Which of the following tag is used to indicate the end of javascript code?
A. </script>
B. <script>
C. <END>
D. None of the above
157
Client Side Scripting - I
Answer Key:
1. A 2. C 3. C 4. C 5. A 6. A 7. A 8. B 9. D 10. B
Review Questions
Write short answers of the following.
1. What is a script?
2. Differentiate between client-side and server-side scripting?
3. Inlist the advantages and disadvantages of using javascript in your web pages?
4. How is javascript case sensitive?
5. Name some of the javascript features.
6. What are the valid scopes of a variable in javascript?
7. What data types are available in javascript?
8. How do we write single line and multi-line comments?
9. How do you link a JavaScript to a HTML document?
10. In which parts of HTML document can a javascript code be written?
158
Introduction to Web Development
159
Client Side Scripting - I
160
Introduction to Web Development
UNIT 8
161
Client Side Scripting - II
Introduction
We introduced in the previous unit that how javascript can be embedded in HTML code to make a
web page more interactive and responsive. We also discussed some basic features of JavaScript and
some of its basic constructs. In this unit, we continue our discussion on JavaScript and presents some
of its core constructs such as expressions, assignment statements, selection statements, loops and
manipulation of form elements.
Unit Outcomes
Upon completion of this unit, you will be able to:
1. Write JavaScript programs with selection statements.
2. Write JavaScript programs with loops.
3. Write JavaScript programs to manipulate form elements.
4. Develop interactive and responsive web pages by using JavaScript
Terminologies
Operator: It is a character symbol or sign which is used to perform some mathematical
calculations or carry out logical functions.
Logical operators: They are used to combine and compare Boolean expressions
Comparison operators: They are used to compare two or more expressions.
Conditional Statement: It is a set of statements executed when the condition is true.
loop: It is a set of instructions that are continuously repeated until condition is true.
Object: An object is a collection of variables and related methods.
Event: An event is a result of user action.
162
Introduction to Web Development
Arithmetic expressions can be constructed by combing arithmetic operators and operands. Some
examples of arithmetic are:
2 + 4 * 5
2 + x * y – 6/2
When an expression has more than one operator in an expression, JavaScript uses operator
precedence rules to evaluate the expression. According to the precedence rules, *, / and % have
higher precedence than + and – (that is *, / % are evaluated before + and -). If an expression has
operators at the same level of precedence, evaluation is done from left-to-right. For example, the
expression 5+6/3 will be evaluated as follows. First, we will divide 6 by 3 (since / has higher
precedence than +) which give 2; adding 2 to 5 will give us the result 7. Note that the precedence
can be changed by using ( ) which is evaluated first.
163
Client Side Scripting - II
Activity 1
• Write JavaScript code that prints sum, difference, product and average of two numbers.
• Write java script that calculates the area of a triangle.
• What will be the value of expression 6 + 2 * 6 /3 – 4
164
Introduction to Web Development
Variable=expression;
x = 5;
x = 4 * 5 / x -7;
JavaScript also has shorthand assignment operators that combine an arithmetic operator with
assignment operator. These shorthand forms let us express common assignment statements
precisely but are otherwise equivalent to their expanded form. The following table summarizes
these operators.
165
Client Side Scripting - II
Video Lecture
https://youtu.be/D9zzr7kNsx4
Activity 2
Write the following using shorthand assignment.
1. i=i+7;
2. p=p/x
3. g=g*(x+y)
8.2.1. if Statement
The syntax of basic if statement is
if (Condition)
statement;
In the if statement, if the condition evaluates to true then the statement is executed. For example,
the following code displays “Congratulation...” message if marks are 90 or more. Otherwise, the
message will not be displayed.
marks = 95;
if (marks >= 90)
alert ("Congratulation..");
166
Introduction to Web Development
If we want to execute more than one statements when a condition is true, then we have to
put all those statements in a block (inside { } ) as shown in the following code.
marks = 95;
if (marks >= 90)
{
alert ("Congratulation..");
alert ("You got A Grade");
}
167
Client Side Scripting - II
Activity 3
Write JavaScript that prints a message if you fail a course. That is "you obtained less than 50 marks"
if(Condition)
statement1;
else
statement2;
If the condition is true, then the statement1 is executed otherwise statement2 is executed.
If we want to execute multiple statements when given condition is true or false, we will
make a block of the statement by writing them in { }. The following code segment prints
whether a number is even or odd using if-else statement.
var n = 10;
if (n%2==0)
alert("It is even");
else
alert("It is odd");
168
Introduction to Web Development
Activity 4
Write JavaScript code that checks whether a number is positive or negative.
if (Condition1)
statement1
else if (Condition2)
statement2
else if (Condition3)
statement3
…
else
//statement to be evaluated if no condition is true
if (n < 0 )
alert ("-ve number");
else if (x==0)
alert("It is zero");
else
alert("+ve number");
169
Client Side Scripting - II
Following is a complete HTML code with javascript that prints grade of a student based on the makes
he obtained.
170
Introduction to Web Development
Video Lecture
https://youtu.be/tI-OXBbLKGg
Activity 5
To find position of an employee based on his salary. Write a code in which you have to find a senior
programmer’s post through his salary. Manager’s salary is 100,000, assistant manager’s salary is
80,000, senior programmer’s salary is 60,000 and junior programmer salary is 40,000.
switch (expression)
{
The break statement is a reserved word that indicates the end of that particular
case.
171
Client Side Scripting - II
When break statement is reached, the switch terminates, and the flow of
control jumps to the next line following the switch statement.
172
Introduction to Web Development
Video Lecture
https://youtu.be/hcuRnVGRrlo
Activity 6
Write a switch statement that displays the name of the month given the month’s number i.e. If the
month number is one then January is displayed, if the month number is two February is displayed
and so on. For an incorrect value of month number, the program should display "Incorrect month
number".
A for loop executes as follows: First the initial expression is evaluated and then the condition is
checked. If the condition is true, then the statement or block of statements (called the body of the
loop) is executed. After completing the body of the loop, the increment expression is evaluated and
the loop continues executing until condition becomes false.
173
Client Side Scripting - II
1. Initial expression (var i=0), declares variable i and assigns 0 as its value.
2. Condition ( i<= 5) is checked. If the condition evaluate to true,
i. Statement (document.write(“Iteration# “+i+”br>”) is executed
ii. The increment expression (i++) is executed.
3. Repeat step 2 until the condition becomes false.
The javascript in the following HTML document prints first 5 positive integers as can be seen in the
output given after the code.
174
Introduction to Web Development
Video Lecture
https://youtu.be/2cYexKjbbFU
Activity 7
1. Modify the code 8.5 to print even numbers from 1 to 20.
2. Modify the code 8.5 to print odd numbers from 1 to 20.
while (condition)
statement or statement-block
Let us see how a while loop executes with the help of following code
var i= 0;
while (i<5)
{
document.write ("Iteration# "+i+"br>");
i++;
}
To avoid infinite loops, make sure the condition in a loop eventually becomes false; otherwise, the
loop will never get terminated.
The while loop written in following code iterates as long as i is less than or equal to fifteen.
175
Client Side Scripting - II
Activity 8
1. Modify the code 8.6 to execute the loop for 10 times.
2. Write javascript code to print even numbers from 1 to 20.
do
{
Statement(s)
176
Introduction to Web Development
} while (condition);
In a do-while loop, the statement or statements are executed first and then the condition is
evaluated. If condition is true, the statement(s) executes again. When the condition becomes false,
execution of the loop statement stops and control passes to the statement following the do…. while
statement.
var i = 0;
do
{
document.write ("Iteration# "+i+"br>");
i++;
} while (i<10);
177
Client Side Scripting - II
Video Lecture
https://youtu.be/8dube0Veurs
Activity 9
1. Modify the code 8.7 to execute the loop for 10 times using do while loop.
2. Modify the code 8.7 to print even numbers from 1 to 20 using do while loop.
var x=1;
var sum=0;
while (x<=10)
{
Sum+=x;
document.write ("The Sum= "+sum+"<br>");
178
Introduction to Web Development
if (sum>=20) break;
x=x+1;
}
document.write ("Loop Done.");
The break statement ends execution of the loop or the conditional statement
in which it appears.
The following code illustrates that the inner while loop will end when the value of z becomes equal
to 3 and the outer while loop will end when the value of x becomes equal to 3.
179
Client Side Scripting - II
Activity 10
Write a program that calculates the sum of first 20 integers starting from 1. The loop should
terminate early if the sum becomes greater than 40.
n += i;
document.write ("n=" + n + ", i=" + i + "<br>");
}
</script>
</body>
</html>
180
Introduction to Web Development
Activity 11
Write a program that calculates the sum of first 10 even numbers, negative numbers are skipped
from calculation.
Similarly, the following line of code invokes write() method of Document object.
181
Client Side Scripting - II
Activity 12
Modify the code 8.10 to create two objects and assign different properties to each object and
display the object properties.
182
Introduction to Web Development
Then we can access the value from the text box using the text box id (i.e. inputName) using the
following JavaScript code
iName = document.getElementById("inputName").value
The value stored in a variable (iName) can be manipulated. For example, if we want to display an
error message if the user does not enter the name, we can use the following code
if (iName == "")
The JavaScript code can be bound to events such as onClick. The following code shows how we can
validate data entered in a text box.
else
alert('Please enter name.');
}
</script>
</head>
<body>
<p>Example: JavaScript &HTML Form</p><br>
<form name="htmlForm" action="" method="post">
Enter Name:
<input type="text" name="name" id="inputName" value=""/>
<br>
<br><input type="button" name="btnClear" value="Clear Name"
onclick="clearName()"/>
<input type="button" name="btnGet" value="Get Name"
onclick="getName()"/>
183
Client Side Scripting - II
</form>
</body>
</html>
Activity 13
Create student registration form and perform input validation using JavaScript before submit, also
place reset button to clear all input fields of registration form.
184
Introduction to Web Development
onclick event
This event occurs when a user clicks left mouse button. The following code shows how we can
respond to this event. Note that what all we have to do is to write a function (event handler) in the
head section of the HTML document that will be called and executed when a user click mouse
button on an element of a form to which it is bound.
185
Client Side Scripting - II
When a user clicks on the button ("Say Hello"), then the alert will be displayed as shown in the
following output.
Activity 14
We want to update the “to-do” list, but not before the user clicks on the “Click me!” button. Change
the JavaScript code in such a way that it will execute when the user clicks the button. Following are
some tips to do this activity.
• Put all of the given code into a function with a name of your own choice.
• Set the “onclick” event handler for the button which refers to the created method.
onsubmit Event
This event occurs when a user clicks on the submit button on a form. In the following code,
doConfirm() function is executed before submitting a form data. The result for using the doConfirm()
function is that the form will be submitted if the function returns true otherwise it will not submit
the data.
186
Introduction to Web Development
The output of above code is shown in figure 8.15, 8.16 and 8.17.
187
Client Side Scripting - II
Activity 15
Create a web page that has a form element with an input button. When the user clicks on the input
button, the background color should be changed to green using document.bgColor property and
onClick event handler.
188
Introduction to Web Development
Activity 16
Modify the code 8.14 and change the event handlers by changing the background colors.
Unit Summary
In this unit, we learned how to use selection statements in javascript programs. We also learned the
use of loops to control the program statements. This unit also covers important concept of HTML
form and its associated elements in detail. The last section of the unit is focused on developing
interactive and responsive web pages using javascript.
189
Client Side Scripting - II
2. Which of the following statement is used to perform a specific action when a condition is
true or false?
A. While
B. If
C. For
D. All of the above.
190
Introduction to Web Development
Answer Key:
1. A 2. B 3. D 4. C 5. A 6. A 7. D 8. B 9. A 10. C
Review Questions
Write short answers of the following questions
191
Client Side Scripting - II
5. Write a javascript code that displays minimum and maximum values out of four given
numbers. The number should be stored in four different variables.
6. Develop a web page with javascript that displays all the even numbers from 1 to 100,.
7. Write a javascript program which prints "PASS" if the int variable "mark" is more than or
equal to 50; prints "FAIL" otherwise.
8. Write a program which allows entering the age of user and shows that either he is eligible to
vote. The basic criteria of eligibility of voting age are above and equal to 18 years.
9. Write a JavaScript program to calculate the area and perimeter of a circle.
10. Create a web page with a form that allows a user to enter two numbers and performs the
addition, subtraction, multiplication, division depending on the user’s choice. For each
operation, create a button on a form and write appropriate event handlers for each button.
192
Introduction to Web Development
UNIT 9
Website Hosting
193
Website Hosting
Introduction
We have discussed how we can develop a website using HTML, CSS and JavaScript. Once we have
our website ready and tested for its content and functionality, we need to upload the website (web
page) to a web server to make it accessible to the users. To make a website up and running, we have
to find a suitable web hosting server. There are number of ISPs that provide web hosting services on
payment. We might find some free hosting services as well. This unit discusses about different web
hosting options available to us. We then discuss a step by step procedure to upload our web pages
to a selected server.
Unit Outcomes
At the completion of this unit, you should be able to:
1. Explain different types of web servers.
2. In list different types of web hosting services.
3. Describe domain names.
4. Upload a website using FTP.
Terminologies
Web Server: A web server is a computer system that deliver services to the end users
Web Hosting: It is a service that host websites by providing space on the Internet.
Domain Name: It is a unique identifier for a website.
Internet Service Provider: A company that provide Internet services.
File transfer protocol: It is a protocol which is used to transfer files on a computer network.
194
Introduction to Web Development
Apache is an open source software and can be installed on almost all operating
systems.
Nginx is known for its high performance, stability, simple configuration and low
resource usage.
195
Website Hosting
This server is compatible with most common Apache features, including mod
rewrite, .ht access, and mod security.
Activity 1
Surf the Internet and explore detailed features of different web servers.
• Free hosting
• Shared hosting
• Dedicated hosting
• Collocated hosting
Free hosting
Free web hosting provides free of cost hosting facility for a website. Due to free of cost hosting the
problems like slow speed connection, frequent linking down of the website and automatic addition
of advertising banners are usually faced. Few companies compel to purchase a domain name to avail
free hosting services, while others offer a free subdomain under them, such as
yourname.webhost.com.
Shared Hosting
In a shared hosting environment, a number of websites share one server. This includes sharing the
physical server as well as software applications running on the server. Due to shared hosting, the
performance of a website may goes down.
196
Introduction to Web Development
Shared hosting services are affordable because the cost to operate the server is
shared among the clients.
Dedicated hosting
In a dedicated hosting environment, a dedicated web server is reserved for a particular website only
which results into faster performance, as we have all the server’s resources due to no sharing with
anybody else. However, the user has to bear the entire cost solely. This is a good choice for websites
that requires a lot of system resources or need a higher level of security.
Collocated hosting
In this type of hosting, we purchase our own server which is housed in a rental space along with
server of many other companies and individuals. It allows full control of the server and the
installation of any script or application we need.
Activity 2
Surf the Internet and find the organizations which provide free hosting services. Find the local
companies which provide web hosting services.
Each website has a domain name that serves as an address, which is used to
access the website.
197
Website Hosting
A subdomain is a second website, with its own unique content, but there is no
new domain name.
Activity 3
Find the domain name of your university website.
FTP is the easiest and most secure way to exchange files over the Internet.
Activity 4
Download the FTP user guide from the Internet and prepare the Unit Summary of FTP
commands.
198
Introduction to Web Development
1. Login to cPanel.
2. In cPanel’s Files section, click on the File Manager icon as shown the following figure 9.1.
3. Now select the directory as Web Root (public_html/www) and choose the domain name
from drop down arrow in case we have multiple domains under a hosting plan.
4. Check on Show Hidden Files (dotfiles) and click on Go button as shown in the figure 9.2.
5. Click on Public_html folder shown at the left side on the screen under the folder directory.
This will show list of files in the public_html folder. All files must be upload
in public_html folder.
6. Click on Upload in the navigation bar on the top of the page as shown in the figure 9.3.
199
Website Hosting
7. Click on Browse button and select the website's files from your PC/mobile which you want
to upload as shown in figure 9.4.
8. After selecting the files we want to upload, click on Open button and wait for the uploading
process to get completed.
9. Once the uploading process is complete, click Go Back button. It will take us back
to public_html folder in the cPanel as shown in figure 9.5.
200
Introduction to Web Development
10. Now the website has been uploaded. We can check the website by opening it in the
browser.
Host Name: Enter the host as a domain name or the IP address of the hosting account.
User Name: Enter the User name of your hosting account.
Password: Enter the password of your hosting account.
Port: Leave the port box blank.
201
Website Hosting
5. On the right side under the Remote Site, a list of folders is displayed. Select the folder on
server in which to upload website as shown in the figure 9.8.
6. Now on the left side under Local Site section, we will see a list of folders on our PC/Desktop.
Navigate to the files that we want to upload to the server. Select the files and then Right
Click on the files and click Upload as shown in figure 9.9.
202
Introduction to Web Development
The website's files are uploading to server. We can check the uploading process showing at the
bottom of your Filezilla FTP client. Once the website has been successfully uploaded, we can check
our website by opening it in the browser.
Activity 5
Upload your personal website on a free web hosting server.
Unit Summary
In this unit, we learned about different types of web servers, web hosting services and domain
names. We have also discussed how to upload a website on a server using
File Transfer Protocol.
203
Website Hosting
1. ______ is an open source software and can be installed on almost all operating systems.
A. Apache Web Server
B. IIS Web Server
C. Nginx Web Server
D. Light Speed Web Server
2. _______is known for its high performance, stability, simple configuration and low resource
usage.
A. Apache Web Server
B. IIS Web Server
C. Nginx Web Server
D. Light Speed Web Server
3. _______ Server is compatible with most common Apache features, including mod rewrite,
.htaccess, and mod security.
A. Apache Web Server
B. IIS Web Server
C. Nginx Web Server
D. Light Speed Web Server
4. A web hosting service provider allows individuals to post a website or web page on to the
Internet?
A. True
B. False
5. _______hosting services are affordable because the cost to operate the server is shared
among the clients.
A. Shared Hosting
B. Dedicated Hosting
C. Collocated Hosting
D. Free Hosting
7. _______hosting service provides faster performance, as you have all the server’s resources
entirely.
A. Shared Hosting
B. Dedicated Hosting
C. Collocated Hosting
D. Free Hosting
204
Introduction to Web Development
8. _______ is a second website, with its own unique content, but there is no new domain
name.
A. Sub Domain
B. Domain
C. Web Server
D. None of these
Answer Key:
1. A 2. B 3. D 4. A 5. A 6. B 7. B 8. A 9. B 10. C
Review Questions
Write short answers of the following.
205
Website Hosting
206
Introduction to Web Development
207