BCA-341-20-AWD-2020 (New)
BCA-341-20-AWD-2020 (New)
BCA-341-20-AWD-2020 (New)
Basic Concepts
What is HTML?
HTML History
Setting up Your Development Environment
Understanding Three Layers of Web: HTML, CSS, JavaScript
Understanding HTML Tags
Introduction HTML5
1.0 Objectives
1.1 Introduction
1.2 Basic Concepts
1.2.2 What is HTML?
1.2.3 HTML History
1.2.4 Setting up Your Development Environment
1.3 Understanding Three Layers of Web: HTML, CSS, JavaScript
1.4 Understanding HTML Tags
1.5 Summary
1.6 Check Your Progress Answers
1.0 Objectives
After studying this chapter you will be able to understand
- Basic concepts of Web
- What is HTML and its history
- Three layers of web
- HTML Tags
1.1 Introduction
This chapter gives you clear idea about basic concepts of web like WWW, URL, Web Server, Browsers,
HTML etc. It also teaches you three layers of web page and introduces you to the HTML tags.
WWW vs Internet
The World Wide Web is what a lot of people think of as the Internet. It is all the Web pages, pictures, videos
and other online content that can be viewed via a Web browser. The Internet, in contrast, is the underlying
network connection that allows us to send email and access the World Wide Web.
URL
URL stands for Uniform Resource Locator, and is used to specify addresses on the World Wide Web. A URL
is the fundamental network identification for any resource connected to the web.
For example, the URL for Indiana University's home page is:
http://www.tmv.edu.in/contactus.asp
Web Server
A web server is a system that provides content or services to end users over the internet. Simply put it is a
computer that hosts a website on the Internet.
Website
A website is a group of publicly available, interlinked Web pages that share a single domain name. Websites
can be developed and maintained by an individual, group, business or organization to provide a variety of
purposes. Often it is called a web site or simply a site.
Web Page
A web page or webpage is a file usually written in HyperText Markup Language (HTML) that is accessible
through the Internet or other network using an Internet browser. A web page is viewed by entering a URL
address and may have text, graphics, and hyperlinks to other web pages and files.
Search Engine
Search Engine is a website that helps you find other web pages. Some of the popular examples of search
engines are Google, Bing and Yahoo.
Browsers
A browser or web browser is a software program built to access content on the World Wide Web. There have
been a number of web browsers that have come and gone over the years. The first, known as
WorldWideWeb (later changed to Nexus), was invented by Tim Berners-Lee in 1990. Some of the current
popular browsers are Google Chrome, Firefox, Opera, Microsoft Internet Explorer or Edge, or Apple's
Safari.
Operating Systems
An operating system (OS) is system software that manages computer hardware and software resources and
provides common services for computer programs. After being initially loaded into the computer by a boot
program, OS manages all the other programs in a computer. The most popular desktop operating system is
the Microsoft Windows. The macOS by Apple Inc. is in second place, and the varieties of the Linux are
collectively in third place. Google's Android and Apple's iOS are dominant operating systems in mobile
sector. While in the web server sector Linux has the major market share.
• Hypertext: Text that you click to jump from document to document. This is a reference to the ability of
Web pages to link to one another.
• Markup: Tags that apply layout and formatting conventions to plain text. Literally, the plain text is
“marked up” with the tags.
• Language: A reference to the fact that HTML is considered a programming language.
• Exploring HTML Editors: An HTML editor is a computer program for editing HTML, the
markup of a webpage. Even though the HTML web page can be created with any text editor like
notepad, specialized HTML editors can provide ease and added functionality. Some of the popular
free HTML editors are Notepad++, Sublime Text, Atom, Brackets.
• Exploring Web Browsers: Because your website users can use different browsers, you need to
make sure that your website is cross-browser compatible. For this reason, every web developer must
have major browsers like Google Chrome, Firefox, Opera, Microsoft Internet Explorer or Edge, or
Apple's Safari.
• Viewing Source Code in Browser: Underneath all the beautiful images, perfect typography, and
wonderfully placed calls to action buttons lies your webpage source code. Every web browser allows
you to access the source code of every website. You can access the HTML code of any website by
right clicking in the browser window and selecting "view page source".
• HTML - Structure or content layer: The HTML code is the structure or content layer of the web
page. The way frames of a house generate a solid foundation, upon which the rest of the house is
built, so does a solid foundation of HTML produces a platform upon which a website can be created.
HTML structure can consist of text or images and it contains the hyperlinks that visitors use to
navigate around the web site.
• CSS - Style or presentation layer: The style or presentation layer dictates how a structured HTML
document will look to a site's visitors. This layer is defined by CSS (Cascading Style Sheets). These
files contain styles that indicate how the document should be displayed in a web browser.
• JavaScript - Behavior or interactivity layer: The behavior layer is the layer of a Web page that can
respond to different user actions or make changes to a page based on a set of conditions. For most
Web pages, JavaScript is the behavior level for the interactions on the page.
The code within an HTML file is made up of text surrounded by tags. These tags indicate where the
formatting should be used, how the layout should appear, what pictures should be placed in certain locations,
and more. For example, suppose you wanted a certain word to be italicized, like this:
In HTML, there’s no Italics button to click, like there is in a word-processing program. Therefore, you have
to “tag” the word that you want to be italicized. The code to turn on italics is <i>, and the code to turn italics
off is </i>. Your HTML code would look something like this:
Here the <p></p> tags are the starting and ending HTML tags that indicate the presence of a paragraph and
the text “Welcome to Our Website.” comprises the paragraph text.
Empty Tags or One Sided Tags: Not every tag encloses document content. Empty tags or one sided tags
are elements that are either non-textual (such as images) or contain directives to the browser about how the
page should be treated. An empty tag is entered using one of the following forms of the one-sided tag:
<element>
For example, the following <br> element, which is used to indicate the presence of a line break in the text, is
entered with the one-sided tag:
<br>
Tag Attributes
HTML attribute is a modifier of an HTML element type. All HTML elements can have attributes which give
additional information about an element.
<img src=”logo.png”>
In the above example, img tag has src (source) attribute with value logo.png file.
1.5 Summary
Hypertext Markup Language (HTML) is the standard markup language for constructing web pages and web
applications. With Cascading Style Sheets (CSS) and JavaScript, it forms a triad of foundation technologies for
the World Wide Web.
1.3
1.4
1. opening, closing
Chapter 2
2.0 Objectives
2.1 Introduction
2.1.1 Specifying Document Type
2.1.2 The Head Section
2.1.3 The Body Section
2.1.4 “Hello World” Example
2.1.5 View HTML5 Page in Browser
2.1.6 HTML5 Boilerplate
2.1.7 HTML5 Validation
2.2 Adding External Files
2.2.1 Adding Stylesheet to HTML
2.2.2 Adding JavaScript Files to HTML
2.2.3 Organizing File and Folder Structure
2.3 Summary
2.4 Check Your Progress Answers
2.0 Objectives
After studying this chapter you will be able to understand
- What is doctype
- Html, head and body elements
- How to add stylesheet and JavaScript files to HTML
- How to organize web files and folder
- How to validate your html code
2.1 Introduction
In the previous chapter we briefly discussed about the HTML5 tags. In this section you will learn three most
important tags in HTML5 namely <html>, <head>, <body>.
When creating an HTML5 document, the first line of the HTML 5 document should be doctype:
<!DOCTYPE html>
The DOCTYPE tag always starts with an exclamation point and is always located at the beginning of the
document, before any other tag. HTML tags are not case-sensitive, but the word DOCTYPE should usually
be uppercase. When a Web browser encounters a DOCTYPE tag, it assumes you are using HTML5. Once a
browser understands the doctype, it can render the page faster and more correctly.
<!DOCTYPE html>
<html>
</html>
Two main structural branches: the <head> and the <body> reside inside the root <html> tag . The head
section consists of information about the current document, often known as metadata. This metadata may
include the title of the document, keywords and descriptions that describe the page, author details, and
copyright statements among other information. Almost all of the content within the <head>… </head> tag
pair is hidden from immediate public view; except the <title> tag. The content in the head is not displayed in
the browser. It is meant to be applied by the external agents, such as search engine spiders.
<!DOCTYPE html>
<html>
<head>
</head>
</html>
The second structural branch within the <html> tag is the <body> tag. The body section is home to all the
content visible in the browser. The <body>… </body> tag pair is written immediately after the closing
</head> tag and before the closing </html> tag, like this:
<!DOCTYPE html>
<html>
<head>
<body>
</body>
</head>
</html>
Character Encoding
The character encoding is the standard that tells a browser how to convert your text into a sequence of bytes
when it’s stored in a file. There are many different character encodings in the world. Today, practically all
English websites use an encoding called UTF-8, which is compact, fast, and supports all the non-English
characters you’ll ever need.
<head>
<meta charset=”utf-8”>
</head>
</head>
<body>
<h1>Hello World</h1>
<p>Hey There</p>
</body>
</html>
Open the saved HTML file in your favorite browser (double clicks on the file, or right-click - and choose
"Open with" your favorite browser).
The entire structure of an HTML document can be looked at as a set of nested elements in a hierarchical tree.
At the top of the tree is the html element, which marks the entire document. Within the html element is the
head element used to mark information about the document itself and the body element used to mark the
content that will show up in the web page. Thus, the general structure of an HTML file, like the one shown
below:
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”utf-8”>
</head>
<body>
Body content goes here
</body>
</html>
As a beginner, it is very common that you will make mistake in writing your HTML code. Incorrect or non-
standard code may cause unexpected results in how your page displayed or functions in a web browser. The
World Wide Web Consortium (W3C) has created great tools https://validator.w3.org/ to automatically check
your pages, and point out any problems/errors your code might have, such as missing closing tags or missing
quotes around attributes.
True or False
You can add external files like Style sheets, JavaScript Files to HTML document.
<head>
</head>
<head>
A well-designed folder structure will help you quickly navigate to the HTML or CSS files that contain your
code. index.html is the home page main file. To store other resources you need 3 folders namely css, js and
img for storing CSS, JavaScript and Image files respectively. So the website file and folder structure look like
this:
index.html
about.html
contact.html
/css/
/js/
/img/
True or False
2.3 Summary
An HTML document includes some essential components: a document type declaration (or doctype), a root
element <html> that wraps around the entire document, a head element <head> having a title and other
information about the document, and a body element <body> that contains all of the content.
2.1
1. True
2. True
3. False
4. False
5. True
2.2
1. True
Chapter 3
3.0 Objectives
3.1 Introduction
3.1.1 Line Break
3.1.2 Creating Headings
3.1.3 Applying Bold and Italic Formatting
3.1.4 Superscript and Subscript
3.1.5 Block Quotation
3.1.6 Preformatted Text
3.2 Unordered, Ordered and Definition Lists
3.2.1 Ordered Lists
3.2.2 Unordered Lists
3.2.3 Nesting Lists
3.2.4 Definition Lists
3.3 Using Links & Creating Navigation
3.3.1 Using Relative and Absolute Paths
3.3.2 Setting Link Target:
3.3.3 Linking to a Phone Number
3.3.4 Linking to an E-Mail Address
3.3.5 Creating and Hyperlinking to Anchors
3.4 Adding Images
3.5 Displaying Data with Tables
3.5.1 Table Row
3.5.2 Table Data
3.5.3 Colspan
3.5.4 Rowspan
3.5.5 Table Heading
3.6 Adding Line Break & Horizontal Line
3.7 Commenting Your Work
3.8 Summary
3.9 Check Your Progress Answers
3.0 Objectives
After studying this chapter you will be able to understand
- How to create text elements
- Build lists
- Create links
- Add images
- Structure data in tables
3.1 Introduction
To begin a new paragraph in your Web page, you use the <p> tag. Each paragraph of text should be
enclosed in a two-sided <p>. The <p> tag sets apart a text block from other elements, including other <p>
tags. A paragraph tag can have one or more sentences.
Example:
When you hit the enter key in a word processor or your text editor, the application breaks the text you write
after it, into a new paragraph, but when you press enter key in an HTML document, the browser ignores it. If
you want to show your two sentences in two separate paragraphs, you have to clearly tell the browser to do it.
You do this with paragraph tags.
Example:
<p>First paragraph.</p>
To create a line break without officially starting a new paragraph, use the line break tag: <br>. This is a one-
sided tag placed within a paragraph, at the end of each line, like this:
Example:
<p>First line<br>
Headings in webpages work the same manner as they do in printed documents - they separate text into
sections. The HTML standard defines six levels of headings, <h1> through <h6>, each one gradually smaller
in font size. The heading levels indicate relative sizes; the higher the heading number, the smaller the size.
<h1> has the large font size and <h6> has the smaller font size.
Example:
Making use of bold and italic styles are two ways of making text stand out and draw in attention. For simple
boldface and italics, use the <b> tag or the <i> tag, correspondingly. Both are two-sided tags that enclose the
text to be formatted.
Example:
Superscript formatting makes text smaller and raises it off the baseline. You’d typically use superscript <sup>
to format exponents in arithmetic equations (for example, the 2 shown in X2+1). You can also use
superscript to format ordinal numbers (such as 1st, 2nd, and 3rd) to make your page look more refined.
Subscript <sub> makes text smaller and moves it below the baseline. The most common use for subscripts is
in chemical formulas (for example, H 2 SO 4 ).
Example:
<p>1<sup>st</sup></p>
<p>H<sub>2</sub>SO<sub>4</sub></p>
The <blockquote> tag specifies a section that is quoted from another source. Browsers usually indent
<blockquote> elements.
Example:
<blockquote>Our greastsst weakness lies in giving up. The most certain way to succeed is always to try just
one more time. </blockquote>
The <pre> tag describes preformatted text. Text in a <pre> element is shown in a fixed-width font (usually
Courier), and it maintains both spaces and line breaks.
Example:
<pre>
is displayed in a fixed-width
True or False
HTML supports three types of lists: 1) ordered lists, 2) unordered lists, and 3) definition lists.
Ordered lists are designed for items that follow some defined sequential order, such as items organized
alphabetically or numerically. An ordered list is marked using the ol (ordered list) element with each list item
marked using the li element. The standard layout is
Example:
<ol>
<li>Paris</li>
<li>London</li>
<li>New York</li>
</ol>
</ol>
Output:
1. Paris
2. London
3. New York
Note that because both the ol and li elements are considered grouping elements, each list item will appear, by
default, on a new line in the document unless a different style is applied to those elements.
Example:
<ul>
<li>Paris</li>
<li>London</li>
<li>New York</li>
</ul>
Output:
1. Paris
2. London
3. New York
3.2.3 Nesting Lists
You can nest lists within one another. In the next example, we have a bulleted list embedded within a
numbered list. Notice how this nested list was built. The bulleted sublist (the <ul> tag) is put within one of
the <li> tags within the numbered <ol> list.
Example:
<ol>
<li>France</li>
<li>England:
<ul>
<li>London</li>
<li>Birmingham</li>
<li>Leeds</li>
<li> Glasgow</li>
</ul>
</li>
<li>USA</li>
</ol>
Output:
1. France
2. England
• London
• Birmingham
• Leeds
• Glasgow
3. USA
A third type of list is the definition list made up of a list of terms and matching definitions. The definition list
is grouped by the dl (definition list) element, the terms are noted with the dt (definition term) element, and
the definition (s) associated with each term is noted by the dd element. The standard structure is
Example:
<dl>
<dt>HTML</dt>
<dt>CSS</dt>
</dl>
True or False
Links are one of the most significant elements in HTML. Without the ability to link from one document to
another, the Web wouldn't be the Web. The “H” in “HTML,” hypertext, becomes meaningless without the
concept of linked documents. Linking the Web begins with the <a>, or anchor element, one of the oldest
elements.
Hypertext is designed by enclosing content within a set of opening and closing <a> tags in the following
structure:
Example:
<a href=”http://google.com”>Google</a>
Paths that include a complete address that everyone can use to get to that page are called absolute paths.
Absolute paths are very reliable, but they are also long and awkward to type.
Example:
When you are linking to files in the same website as the link itself, you do not need to include the full path to
the file; you can simply provide its name. When the file is in the same folder, you need only supply the file
name. For example, if the index.html and about.html pages of the web site are in the same folder, in the
index.html file, you can refer to about.html like this:
Example:
This is called a relative path, because the destination file is relative to the current file’s location. Relative paths
make it easier to develop and test your website in a different file location than the one where it will eventually
be stored.
Example:
<a href=”about/history.html”>History</a>
You can also create a link to a file that is up one level (a parent folder) with a relative reference as below:
Example:
<a href=”../contact.html”>Contact</a>
By default, a hyperlink opens the linked page in the same browser tab. Which means the new page replaces
the previous page. Generally this is fine, but in some instances you might want the hyperlink to open in a new
tab. For example, maybe you want to endorse that visitors check out a page on another site, but you don’t
want them to leave your site. To direct the hyperlink to open a page in a new tab, add the attribute
target=“_blank” to the <a> tag.
Example:
Due to the increased use of mobile phones to visit the web, we need to include link to contact phone number
of the organization. Clicking on the link brings up the user’s phone app with the number already entered,
making it much easier and more convenient to call the business or organization. You can use tel: followed by
telephone number without space to create telephone link.
Example:
Many websites use e-mail to allow users to communicate with a site’s owner, sales representative, or technical
support staff. You can turn an e-mail address into a hypertext link using the URL:
Example:
Clicking the link opens the user’s e-mail program with the e-mail address automatically inserted into the “To”
field of a new outgoing message.
An anchor is a marker within an HTML document, similar to a bookmark in a Word document. You define a
specific location in the document with an anchor name, and then you can hyperlink directly to that anchor.
Anchors are most valuable in lengthy documents with multiple sections. They give a means for users to jump
straight to whatever section they want rather than having to read or scroll through the entire document.
For example, you have a heading that reads Services, and you have an anchor point with name="services". To
refer to the anchor point, include its name in the href= attribute and precede the anchor name with a pound
(hash) sign (#).
Example:
True or False
1. Paths that include a complete web address are called absolute paths.
Example:
The <img> tag is a single or empty HTML tag, which means no closing tag is required. The primary attribute
of an <img> tag is src, short for source. The src value contains the path to the desired graphic file. As with
links, the path can be either relative to the current page, like the preceding example, or absolute, like this one:
http://www.example.com/images/logo.gif
Strictly speaking, browsers don’t need the width or height attributes to render the image; they can detect the
size if those values are not present. The final attribute in the example code, alt, is short for alternative text. If,
for whatever reason, the browser is not able to display the image, the alternative text is shown.
The three most widely used formats on the Web are GIF, PNG, and JPEG. Current browsers can view all
three image formats. The JPEG format is good for color photographs because it handles large amounts of
color and it compresses well. The PNG and GIF formats are often used when you’re saving files like logos
with transparency. JPEG images are not transparent.
True or False
If you’ve used a word-processing program before, you’re most likely already familiar with the task of creating
tables. A table is a grid of rows and columns, the intersections of which form cells. Every cell is a distinct
area, into which you can place text, graphics, or even other tables. HTML handles tables very well, and you
can use them to set up and present complex data to your site visitors.
Tables are composed of cells organized into rows and columns. In HTML, you mark up tables one row at a
time using the <tr> element which is short for “table row.”
The <td> element, the workhorse of any HTML table, represents an individual cell in a data table. The
element’s name, which is short for “table data,” gives you a hint of its expected content.
Example:
<table>
<tr>
<td>Contect</td>
</tr>
</table>
3.5.3 Colspan
The colspan attribute accepts a positive integer and instructs the browser to create a cell that spans as many
columns of the table
Example:
<table>
<tr>
</tr>
<tr>
<td>One</td>
</tr>
</table>
3.5.4 Rowspan
Similar in usage to the colspan attribute, the rowspan attribute accepts a positive integer as its value. The
higher the specified value, the more rows your cell will span.
Example:
<table>
<tr>
</tr>
<tr>
<td> Price</td>
<td Quantity </td>
</tr>
<tr>
<td>50</td>
<td 2 </td>
</tr>
</table>
The <th> tag defines a header cell in an HTML table. The text in <th> elements are bold and centered by
default.
Example:
<table>
<tr>
<th>Product></th>
<th>Quantity></th>
</tr>
<tr>
<th>Mobile</th>
<th>19</th>
</tr>
<tr>
<th>Laptop<th>
<th>27</th>
</tr>
</table>
3.5 Check Your Progress
True or False
Horizontal lines can be valuable as dividers between sections of text in a Web page. By default, the line runs
the whole width of the browser window, is two pixels in height, and is black. You can change these
characteristics by applying attributes within the tag.
Example:
<hr>
True or False
Commenting is a way to tell the browser to ignore certain parts of text that you include within the body of
code. Comments are for the human, not the machine. They help you and others understand your code when
it’s time to revise the code. You can also use commenting to comment out portions of your code for testing
and debugging.
In HTML any text enclosed by an opening <!— tag, and a closing --> tag is invisible to the browser.
Example:
<!—
This is a comment
True or False
3.8 Summary
<p> tag is used to add text paragraph in HTML page. Six levels of headings, <h1> to <h6>, are used to add
titles. You can use <b> and <i> tag to make text bold and italic respectively. HTML supports three types of
lists - ordered list, unordered list and definition list. <a> or also called as anchor tag is used to create web
links. You can add images to web site with <img> tag and data tables with <table> tag.
3.1
1. True
2. False
3. True
4. True
3.2
1. False
2. True
3.3
1. True
3.4
1. False
3.5
1. True
3.6
1. False
3.7
1. True
Chapter 4
4.0 Objectives
4.1 Introduction
4.2 Summary
4.0 Objectives
- Form elements like input, textarea, radio button, checkbox, select box etc
- Form submission
- Form processing
4.1 Introduction
You can insert a form anywhere in the body of an HTML document. All basic web forms function in the
same manner. The user fills in some details and then clicks a button. At this stage, the server gathers all the
data that the user has entered and transmits it back to the web server.
<label for=”fullName”>Name:</label>
</form>
Form Attributes
• action: Specifies the URL of the form handler, which is the script or application that will process the
submitted form data.
• method: Specifies which HTTP method will be used to submit the form data, either get or post. The
method defaults to get if this attribute is missing.
• enctype: Specifies the type of encoding to use when the form is submitted, one of three possible
values: application/x-www-form-urlencoded (the default), multipart/form-data (if the submitted form
will include files uploaded via an input type="file" control), or text/plain which performs no
additional encoding.
Most popular form controls are instances of the input element, with each type of input control showed by a
corresponding type attribute. The input element is styled as inline by default so many can appear on the same
line.
Text
You create a regular text box using a single-sided <input> tag with a type=“text” attribute:
Example:
<input type=”text”>
Each control within a form must have a unique name, expressed with the name attribute. For example, to
name a particular text box phone:
You can also specify a maximum length for the text string that users enter into the text box.
In HTML5, you can require users to fill out a field before they submit the form
HTML5 supports a new input field type e-mail address. Use the attribute type=”email” instead of
type=”text” to define a field designed to collect e-mail addresses.
Password
This control is similar to a text field. The input type="password" defines a password field. The characters in a
password field are masked (shown as asterisks or circles).
Url
The input type="url" is used for input fields that should contain a URL address:
Date
The input type="date" is used for input fields that should contain a date. A date picker pops up when you
enter the input field.
Number
The input type="number" defines a numeric input field. You can use the min and max attributes to add
numeric restrictions in the input field:
Range
The input type="time" allows the user to select a time (no time zone):
A time picker might pop-up when you enter the input field.
You create a multi-line text area by using a two-sided <textarea> tag containing a rows attribute that specifies
the number of lines of text that the box should accommodate.
You can also include a columns attribute that specifies how many characters (each character represents a
single column) wide the text area will be. The default is 40 characters.
The columns attribute affects only the size of the box, not the maximum number of characters that can be
entered. You can use the maxlength attribute to limit the number of characters a user can enter.
Placeholder Text
By default, text boxes and text areas are blank when the form loads. You can in addition place either default
or placeholder text in them. Placeholder text is "dummy" text that shows up as a prompt within the text box
but disappears when the user types something else there.
The HTML <label> element represents a caption for an item in a user interface. The “for” attribute specifies
which form element a label is bound to.
<input> elements of type radio are generally used in radio groups - collections of radio buttons explaining a
set of related options. Only one radio button in a given group can be selected at the same time. Radio buttons
are commonly rendered as small circles, which are filled or highlighted when selected.
<label for=”male”>Male</label>
<input> elements of type checkbox are rendered by default as square boxes that are checked (ticked) when
activated, like you might see in an official government paper form. They allow you to select single values for
submission in a form. It is used for yes no type of questions.
Example:
Check boxes are good for yes/no questions, and option buttons are suitable when there are a few options to
select from, but what if you have a dozen or more choices? The <select> element is used to create a drop-
down list. The <option> tags inside the <select> element define the available options in the list. A single-line
selection control, generally called a drop-down menu, will display the selected option when in its collapsed,
inactive state, with a small arrow at one end as a visual cue that the control can be expanded.
Example:
<select name=”colors”>
<option value=”red”>Red</option>
<option value=”blue”>Blue</option>
</select>
You will require including a Submit button on the form so your site visitors can send the information to you.
Submit refers to the button’s function, not the text that appears on the button face. The default button text is
Submit, but you can use a value attribute to show different text on the button.
You can also include a Reset button on the form, which allows the user to clear all the fields. Again, use the
value attribute to change the text on the button:
The specific form processing script to be used is identified with the action attribute in the <form> tag
Example:
<form action=”submit.php” method=”post”>
</form>
True or False
4.2 Summary
Getting feedback from your Web site’s users can be a useful way of assessing your site’s success, and it can
help you build a customer or subscriber database. For example, a business could collect the addresses, phone
number and email addresses of people who are interested in receiving product samples, e-mail newsletters, or
notifications of special offers. You can create form with <form> tag and add fields like input, checkbox,
radio button, select options, submit button.
4.2
1. False
2. True
3. True
4. True
Chapter 5
5.0 Objectives
5.1 Introduction
5.4 Summary
5.0 Objectives
- Distinction between different semantic elements and when to use each one
5.1 Introduction
The HTML Content Division element (<div>) is the popular container for flow content. It has no impact on
the content or layout until styled using CSS. As a "pure" container, the <div> element does not naturally
represent anything. Rather, it's used to group content so it can be very easily styled using the class or id
attributes.
Example:
<div>
<h1>Title</h1>
<p>Some Content</p>
<ul>
</ul>
<div>
</div>
</div>
True or False
Semantic markup brings out meaning to the web page rather than just presentation. For example, a <article>
tag implies that the enclosed text is an article. This is both semantic and presentational, mainly because people
know what articles are and browsers know how to display them. On the flip side of this picture, tags like <b>
and <i> are not semantic, because they define only how the text should look (bold or italic) and do not
furnish any extra meaning to the markup.
Example:
<header>
<ul>
<li><a href=”index.html”>Home</a></li>
<li><a href=”about.html”>About</a></li>
<li><a href=”services.html”>Services</a></li>
<li><a href=”contact.html”>Contact</a></li>
</ul>
</header>
An opposite number to the header element, the <footer> element includes extra information about its parent
sectioning element, which include author contact information, related links, copyright or licensing,
supplemental navigation, and disclaimers. It commonly shows up at the end of a section but that’s not a
requirement. Just like header, the name “footer” doesn’t actually refer to a location-this is footer content by
nature, not just by position.
Example:
<footer>
</footer>
A <nav> element consists of navigation - a group of web links that lead to other pages on a website, or to
sections of the current page. In a sense, all links are navigation, but don’t use <nav> for every collection of
links; the nav element is designed only for main blocks of navigation. Most websites have a header or
masthead, a dominant banner that features the site name, logo, and generally the primary navigation for the
website. You can use <nav> element in the masthead as below:
Example:
<header class=”masthead”>
<nav class=”site-navigation”>
<ul>
<li><a href=”index.html”>Home</a></li>
<li><a href=”about.html”>About</a></li>
<li><a href=”services.html”>Services</a></li>
<li><a href=”contact.html”>Contact</a></li>
</ul>
</nav>
</header>
The HTML <main> element signifies the dominant content of the <body> of a document. The main
content area is made up of content that is directly related to the core topic of a document.
Example:
<main>
<h1>Title</h1>
<p>Some Content</p>
</main>
The HTML <section> element represents a standalone section — which doesn't have a more specific
semantic element to represent it.
Example:
<section>
<h1>Title</h1>
<p>Content</p>
</section>
5.2.6 The Independent Content Container: <article> Tag
The <article> element is just like the section element, although with a more enhanced definition. According
to the HTML5 specification, an article element means “a self-contained composition in a document, page,
application, or site and that is, in principle, independently distributable or reusable, e.g. in syndication.” Put
simply, an article element’s content should stand on its own. It could be a blog entry, a comment, a forum
post, a letter, a review, a poem, a short story, or indeed an article. Following is a good example of a concise,
self contained article, complete with title, author byline, and date.
Example:
<article>
<h2>ROBERT FULTON</h2>
<p>Published: 1897</p>
</article>
Another new element in HTML5 <aside> represents - content that works with and improves the main
content, but isn’t an essential part of it. It is optional information that you could very easily remove without
doing harm to the reader’s understanding of the primary content. An aside element might contain extra
commentary, a glossary of terms, background information, a collection of related links, a pull quote, or even
advertising. The kind of secondary content you would use in an aside element is often called a sidebar in
publishing, and that term is prevalent in web design as well, but the words “sidebar” and “aside” don’t really
mean a position on the left or right side of the main content. Use aside properly and don’t get stuck on the
name.
Example:
<aside>
<h3>Related Posts</h3>
<ul>
<li>Article 1</li>
<li>Article 2</li>
<li>Article 3</li>
</ul>
</aside>
The HTML <address> element implies that the enclosed HTML presents contact information of the
organization. The contact information presented by an <address> may include any type of contact
information needed, such as physical address, URL, email address, phone number, social media handle,
geographic coordinates, and so forth. It can contain the name of the person or organization of which the
contact information refers.
Example:
<address>
</address>
A new addition to HTML5, the figure element represents an image, video, quotation, code listing, or some
other content, along with an optional caption.
Example:
<figure>
<figcaption>Product Name</figcaption>
</figure>
The canvas element creates an empty drawing area for dynamically generated imagery - a figurative blank
canvas. The markup is incredibly simple:
Example:
<canvas></canvas>
The canvas element creates 300 pixels wide by 150 pixels high box by default, but you can supply your own
dimensions with the optional width and height attributes.
The addition of the <video> and <audio> tags in HTML5 makes it easy to deliver and play video and audio
files. In the past, developers and designers have mostly set up pages to play video and audio on the website
using Adobe Flash Player. This required that the end user has the Adobe Flash player installed to play the
audio and video file.
The HTML Video element (<video>) embeds a media player which supports video playback into the
document. It may contain one or more video sources, represented using the <source> element: the browser
will choose the most suitable one.
Example:
</video>
The HTML <audio> element is used to embed sound content in documents. It may contain one or more
audio sources, represented using the src attribute or the <source> element: the browser will choose the most
suitable one.
Example:
<audio controls=”controls”>
</audio>.
5.2.12 The Vector Based Image Container: <svg> Tag
SVG stands for Scalable Vector Graphics. It is used to define graphics for the Web. The HTML <svg>
element is a container for SVG graphics. It has several methods for drawing paths, boxes, circles, text, and
graphic images.
Example:
</svg>
True or False
5.3 Summary
Semantic markup brings out meaning to the web page. The <header> element is used for introduction of a
document. Footer element commonly shows up at the end of a section or document. A <nav> element
consists of navigation or web links. Element <address> can be used for contact information. Some of the
newly added graphic and media related elements are <canvas>, <figure>, <video>, <audio>, <svg>.
5.1
1. True
5.2
1. True
2. True
3. False
4. True
Chapter 6
6.0 Objectives
6.1 Introduction
6.3 Summary
6.0 Objectives
- What is CSS
- History of CSS
- Syntax of CSS
6.1 Introduction
Building a website with HTML (Hypertext Markup Language) is only part of the story. HTML controls the
structure of a web page, using tags such as <img> for images, <p> for paragraphs, and <a> for link
elements. This structural role has become even more important with the arrival of semantic elements, such as
<header>, <footer>, <article> and <nav>, in HTML5. But HTML mentions nothing about how the page
should look. That is the role of Cascading Style Sheets (CSS).
Cascading Style Sheets (CSS) is a simple language defining styles, which can be applied to HTML. Where
HTML represents the structure of a web page, CSS represents its presentation. Cascading Style Sheets - CSS
for short, provide you total control over the layout and design of your web pages. Using CSS, you can spice
up your site’s text with eye-catching headlines, borders, and drop caps, just like the ones in shiny magazines.
You can also organise images with accuracy, create columns and banners, and spotlight your links with
compelling rollover effects. You can even make components fade in or out of the view, make a button
gradually transform colors when a visitor moves mouse over it, or move items around the web page.
An international community also known as the World Wide Web Consortium (W3C) creates and maintains
the CSS specifications that specify and standardize the method in which people should write the CSS
language and browsers should execute it.
Before CSS, almost all of the presentational features of HTML documents were added in the HTML markup;
all font styles, colors, background styles, borders, element alignments had to be clearly described, within the
HTML. Due to this, development of huge web sites, in which fonts and color information were often added
to each and every page, became a lengthy and costly process. CSS eliminate these issues, by enabling web
designers to move all of that formatting information to a distinct style sheet generating considerably cleaner
HTML markup.
• Consistency and Efficiency: By making one change to our website's CSS Style Sheet, you can
automatically make it available to every page of your website. It also ensures that all your web pages
have consistent styling throughout your site.
• Pages load faster: When you use CSS you do not need to style HTML tags every time. You can just
write one CSS rule of a tag and apply it to all the occurrences of that tag in your website. Less code
simply means faster load time.
• Easy Maintenance: CSS simplifies website maintenance and give web designers’ one file to manage
all the styling.
• Mobile Responsive: CSS allows content to be optimized for more than one type of device. Using
CSS, the same HTML document can be presented in different viewing layouts for different rendering
devices such as computer screen, smart phones, tablets etc.
CSS was first recommended by Hakon Wium Lie on October 10, 1994 and managed through a group of
people within the W3C (World Wide Web Consortium) called the CSS Working Group. The World Wide
Web Consortium or W3C is a group that makes suggestions about how the Internet works and how it should
develop.
CSS Versions
CSS level 1 (CSS1) was officially introduced in 1996, and included properties like typeface and emphasis color
of text, backgrounds, and other text attributes such as spacing between words, letters, and lines of text.
CSS level 2 (CSS2) standard was designed by the W3C and released as a recommendation in 1998. It added
properties for positioning that allowed CSS to be utilized for page layout.
The CSS level 3 (CSS3): First drafts were published in 1999. CSS3 adds presentation-style properties, allowing
us to effectively build presentations from HTML documents. CSS3 is divided into 50 plus CSS modules. Last
working draft was released in 2016. All the major browsers now support majority of the CSS3 features.
CSS4: First draft of CSS4 was released in 2017. It is still under development stage.
There are 3 ways to add CSS styles to the website: You can 1) use internal CSS and include CSS rules in
<head> section of the HTML document, 2) use inline CSS to apply rules for specific element in HTML file
or 3) link to an external CSS file which contains all CSS rules (Recommended method)
Internal CSS
Internal styles are added within the <style> element, within the <head> section of an HTML page. The
<style> tag is part of HTML, and not CSS. But its job is to inform the web browser that the data included
within the <style> tags is CSS code. To create a <style> block, you write the style rules in precisely the same
way as in an external style sheet, and use them in a pair of HTML <style> tags. Using an HTML <style>
block restricts the style rules to the current page, so this technique should not be employed for styles that
need to be applied to multiple pages.
Example:
<head>
<style>
body{
background-color: red;
</style>
</head>
Inline CSS
Inline css style goes in the opening tag of an HTML element, so it is applicable to that element alone. To
make use of it you can simply add a "style" attribute to the HTML element. The style attribute can consist of
any CSS property. Applying CSS this way is not recommended, as each HTML tag requires to be styled
separately. Organizing your website may become too complicated if you only use inline CSS. However, it can
be beneficial in some situations, like email newsletters.
Example:
External CSS
This is the most popular and powerful way of using CSS. The styles in external style sheets impact all pages to
which they’re connected. Primarily an external style sheet is implemented for an entire site or subsection of a
site, making it easy to update multiple pages by editing only one file. An external style sheet is simply a text
file comprising all our CSS rules having file extension of .css. This is the most popular method of using CSS.
With an external style sheet, you can alter the look of an entire website by editing just one file! An external
style sheet can be anywhere within your website, but the common practice is to place all style sheets in a
dedicated folder called styles or css. You attach an external style sheet in the <head> section of your web
page with a <link> tag. A <link> tag looks like this:
Example:
<head>
</head>
The CSS syntax is composed of a set of rules. These rules have 2 parts: a selector and a declaration block.
1. Selector: The selector pertains to the HTML element you want to style.
2. Declaration Block: The declaration block starts with an opening brace ({) and ends with a closing
brace (}).
• Declaration: Between the opening and closing braces of a declaration block, you add one or
more declarations, or formatting commands. Every declaration has two parts, a property and a
value. A colon separates the property name and its value, and the whole declaration ends with a
semicolon.
1. Property: CSS offers you a number of formatting options, known as properties. A property
is a word-or a few hyphenated words - implying a particular style effect. Most properties
have simple names like font-size, margin-top, and text-align.
2. Value: Every given property has a value that indicates how we wish to change the features
of the property. Some properties have a set list of values that you can select from. Others
allow you to define the value yourself.
Note: You don’t need to write a style on a single line, as in the picture, you can write it as shown below:
Example:
p{
color: blue;
font-size:16px;
color: blue;
font-size:16px;
The property “color” has “blue” value. Every property-value pair ends with semicolon.
6.2.1 Using Different Units of Measurement
Units of measurement generally used with printed materials - picas, points, inches, and so on, don’t function
well on web pages because you can’t anticipate how they’ll look from one monitor to the next. CSS supports
a number of, units of measurements consisting of absolute units such as inches, centimeters, pixels etc., and
relative measures including percentages, em and rem units.
If you don’t define a text size using CSS, a web browser falls back on its pre-programmed options. Generally
in most browsers, text inside a paragraph tag is displayed 16 pixels tall-that’s known as the base text size.
Absolute Units
Absolute units are fixed and don’t relate to one another, meaning they aren’t inherited. For example: pixel
Relative Units
Relative units are those that relate to each other, being inherited from their parent element. For example
percentage, em and rem
Pixel: Pixel values are the simplest to understand, since they’re totally independent from any browser
options. When you define, for example, a 36-pixel font size for an <h1> tag, the web browser shows text
that’s 36 pixels tall, period! Web designers enjoy pixel values since they offer constant text sizes across distinct
types of browsers. The CSS code looks like this:
font-size :36px;
Keywords: CSS provides seven keywords that let you assign a size that’s relative to the base text size: xx-
small, x-small, small, medium, large, x-large, and xx-large. The CSS code looks like this:
font-size :large;
Percentage: Like keywords, percentage values adjust text in relationship to the font size defined by the
browser, but they give you much finer control than just large, x-large, and so on.
Ems: The W3C defines an em unit as “the computed value of the font-size property of the element on which
it is used.”
div{
font-size:20px;
width:4em;
height:4em;
}
In the above example, width and height will be 20x4 =80px
Rem: CSS Level 3 introduces a new unit called Rem (Root em). The W3C is aware of the troubles when
working with inherited values and em, so it released rem. Rem inherits its value only from the root element,
that being the <html> element. Therefore, in the rem unit, each element inherits the same font size from the
root (16px).
div{
font-size:20px;
width:4em;
height:4em;
When you use rem, it does not matter what font size you use for the element. The browser’s default font size
of <html> is 16px hence the width and height in above example will be 16x4=64px
A block-level box or element - for example, a <div>, heading <h1>, or paragraph tag <p>, takes up all
available horizontal space, beginning on a line of its own and forcing following elements down onto a new
line. Common block level elements are: Paragraphs <p>, Headers <h1> through <h6>, Divisions <div>,
Lists and list items <ol>, <ul>, and <li>, Forms <form>.
However, an inline box or element, such as a <span>, image <img> sits together with previous and next
inline elements. Common inline elements are Spans <span>, Images <img>, Anchors <a>.
When it’s time to edit a style sheet weeks, months, or even years after building it, you may find yourself
questioning, “Why did I create that style? What does it do?” When you’re developing a website, you must
keep records of what you did and why. Thankfully, you don’t require a pad of paper to do this. You can add
your notes directly into your style sheets applying CSS comments.
A CSS comment is simply a note enclosed within two sets of characters, /* and */. As with HTML
comments, CSS comments aren’t read or acted on by a web browser, but they do let you create useful alerts
to your style sheets.
Example:
/* A one-line comment*/
/*
This is multi-line
Comment
*/
CSS Reset:
Web browsers make use of their own built in styles to style various tags: Headings are big and bold; links are
blue, and so on. A CSS Reset is a set of styles that overwrite browser styles, causing the default styles as
consistent as possible along all browsers. Eric Meyer, an industry expert, has worked on strengthening this
system over several years, creating a small set of styles that make writing CSS extremely easy from the start.
We need to copy styles in https://meyerweb.com/eric/tools/css/reset/ and paste in the beginning of the
stylesheet.
Code formatting has nothing in any way to do with how the CSS works. These are simply visual choices by
the coder. But that's not to say formatting isn't essential. It impacts how it feels to write CSS, how convenient
it is to read, how easy it is to navigate, and how easy it is to revisit and familiarize you with previously written
CSS. The reason there are so many options with CSS formatting is that there are no strict syntax rules when it
comes to spacing and line-breaks.
• Single-line Format: This is most likely the most space and size efficient, short of being totally
compressed to remove all spaces and line breaks. This approach would need the least vertical and
horizontal scrolling as you write and edit CSS, but at the probable cost of appearing untidy and
slightly complicated to read and find things you are searching for.
• Multi-line Format: This is the most prevalent approach. It is the simplest to read, which is why
most of the designers use this format.
div.wrapper{
margin: 0 auto;
padding: 200px 0 0 0;
width:1140px;
z-index:2;
}
ul{
position: absolute;
top:0;
left:430px;
padding:120px 0 0 0;
ul li{
display: inline;
margin:0 10px 0 0;
}
6.2.5 Validate Your CSS Code:
It’s easy to produce a typo when crafting CSS and one little mistake can put all of your cautiously designed
designs out of whack. When your CSS infused web page doesn’t appear as you imagine, a basic CSS error may
be the reason. The W3C CSS validator is a good first stop when troubleshooting your designs.
Just as you ought to make sure you’ve properly written the HTML in your web pages applying the W3C
HTML validator, you should also verify your CSS code to ensure it’s clean. The W3C provides an online tool
for CSS checking as well: http://jigsaw.w3.org/css-validator. It works just like the HTML validator: You can
type the URL of a web page (or even just the address to an external CSS file), upload a CSS file or copy and
paste CSS code into a web form and submit it for validation.
6.3 Summary
Cascading Style Sheets (CSS) is a simple language defining styles. It was first introduced in 1994. You can add
CSS to HTML file in 3 ways namely, Internal CSS, Inline CSS and External CSS. CSS syntax has 2 parts: a
selector and a declaration block. Many different units of measurements like px, rem, em, percentage etc can
be used in CSS.
6.1
6.2
CSS: Selectors
7.0 Objectives
7.1 Introduction
7.1.2 ID Selector
7.2 Inheritance
7.2.2 !important
7.3 Summary
7.0 Objectives
- Specificity in CSS
7.1 Introduction
CSS is a collection of rules, which are made up of two parts, selector and declaration. A selector is used to
select the element you want to apply styles to, and a declaration is the combination of a property and a value
for that element. Selecting the correct selector is the key to working effectively with CSS.
7.1.1 Element Selector:
An element selector is the name of an HTML element (tag). Element selector often called type or tag
selectors, are highly efficient styling tools, as they apply to every single incidence of the tag on a web page.
Example:
HTML
CSS
p{
background-color: yellow;
7.1.2 Id Selector
An ID selector applies styles to elements which have the same id attribute in their opening HTML tag. Unlike
classes, which can be used to multiple elements in the same page, IDs must be unique within a page. It’s
alright to apply the same ID on different pages, provided that it’s used only once on each page. In CSS file
the selector is defined by prefixing the ID with the hash or pound sign (#).
Example:
HTML
CSS
#main{
background-color: yellow;
When you'd like to give one or two images on a page a black thick border while leaving the majority of other
images unstyled, in such situation you can use a class selector.
Example:
HTML
<img src=”image01.jpg” class=”mybox”>
<img src=”image03.jpg”>
CSS
.mybox{
The universal selector is represented by an asterisk (*) and selects every element that makes up a web page
Example:
*{
font-size: 16px;
Descendant selectors are great for styling elements that exist inside of other elements. A descendant selector
matches any element that is a descendant of another. To create a descendant selector, separate the two
selectors by a space, putting the ancestor first.
Example:
HTML
<div id=”main”>
</div>
CSS
#main p{
background-color :black;
The above code selects all <p> tags inside the element having id “main”
Example:
HTML
<section>
<div>
<p>First Paragraph</p>
</div>
</section>
CSS
Section > p {
background-color: yellow;
In the above CSS code, the second <p> gets selected as it is the only direct child of <section> element. The
first <p> tag inside <div> element is not a direct child of <section> tag hence won’t get selected.
Parent-child relationships aren’t the only ones in the HTML family tree. Sometimes you need to select a tag
based not on its parent tag but on its sibling tags that share a common parent. The sibling selector uses an
additional symbol-plus (+) to show the relationship between the two elements.
Following code selects every <p> elements that are placed immediately after <div> elements:
Example:
div + p{
background-color: yellow;
Select and style every <p> elements that are placed after <div> elements:
Example:
div ~ p{
background:#ff0000;
Attribute selectors allow you to select elements by referring to their attributes, such as alt, title, src and so on.
Example:
HTML
CSS
A[title=”mylink”] {
background-color: red;
Occasionally you need an easy way to apply the same formatting to many different elements. To work with
selectors as a group, just create a list of selectors separated by commas. Thus, to style all the heading tags with
the same color, you can write following rule:
Example:
color: red;
}
7.1.10 Pseudo Class
A pseudo-class doesn’t rely on a class attribute in the HTML markup, but is applied automatically by the
browser depending on the position of the element or its interactive state.
selector: pseudo-class{
property: value;
: link - The :link CSS pseudo-class represents an element that has not yet been visited.
Example:
/* unvisited link */
a:link{
color:#FF0000;
:visited - Selects links that have already been visited by the current browser.
Example:
/* visited link */
a:visited{
color:##00FF00;
:hover - When the mouse cursor rolls over a link, that link is in its hover state and this will select it.
Example:
a:hover{
color:##FF00FF;
Example:
/* Seleted link */
a:active{
color:##0000FF;
:focus - The :focus CSS pseudo-class represents an element (such as a form input) that has received focus.
input: focus{
width:250px;
:first-child - The :first-child CSS pseudo-class represents the first element among a group of sibling elements.
In the following example, the selector matches any <p> element that is the first child of any element:
Example:
p:first-child{
color: green;
:last-child - The :last-child CSS pseudo-class represents the last element among a group of sibling elements.
Specify a background color for the <p> element that is the last child of its parent:
Example:
p:last-child{
background-color: #ff0000;
}
:first-of-type
The :first-of-type CSS pseudo-class represents the first element of its type among a group of sibling elements.
Selects any <p> that is the first element of its type among its siblings
Example:
p:first-of-child{
color: red;
:last-of-type
The :last-of-type CSS pseudo-class represents the last element of its type among a group of sibling elements.
Selects any <p> that is the last element of its type among its siblings
Example:
p:last-of-child{
color: yellow;
True or False
7.2 Inheritance
Inheritance is the process by which some CSS properties applied to one tag are passed on to nested tags. For
example, a <p> tag is always nested inside of the <body> tag, so the properties applied to the <body> tag
get inherited by the <p> tag. In the following example because of the inheritance rule, text inside <p> will be
displayed in green color.
HTML
<body>
</body>
CSS
Specificity is the means by which browsers decide which CSS property values are the most relevant to an
element and, therefore, will be applied.
Specificity is a weight that is applied to a given CSS declaration, determined by the number of each selector
type in the matching selector. When multiple declarations have equal specificity, the last declaration found in
the CSS is applied to the element. Specificity only applies when the same element is targeted by multiple
declarations. As per CSS rules, directly targeted elements will always take precedence over rules which an
element inherits from its ancestor.
Example:
HTML
<span>Text</span>
</div>
CSS
7.2.2 !important
When “!important” rule is used on a style declaration, this declaration overrides all other declarations. We can
use the “!important” rule to override the specificity rule we learned in the above example.
Example:
CSS
In continuation with the previous example, we have added “!important” rule to the span { color: red }. As the
“!important” rule overrides specificity rule, here the text will be of color red.
True or False
7.3 Summary
Cascading Style Sheets (CSS) is a simple language defining styles. It was first introduced in 1994. You can add
CSS to HTML file in 3 ways namely, Internal CSS, Inline CSS and External CSS. CSS syntax has 2 parts: a
selector and a declaration block. Many different units of measurements like px, rem, em, percentage etc can
be used in CSS.
7.1
1. True
2. True
3. False
4. False
7.2
1. True
Chapter 8
Formatting Text
8.0 Objectives
8.1 Introduction
8.0 Objectives
8.1 Introduction
Attractive and readable text is essential to the success of a website. CSS has a significant number of properties
specific to formatting text, providing you control not only over fonts and colors, but also allowing you to
change the distance between lines, words, and individual letters.
The primary thing you can do to make text on your website appear even more interesting is to use different
fonts to headlines, paragraphs, and other written elements on your pages. To apply a font to a CSS style, you
use the font-family property and state the font you wish to use.
p{
Note: If the name of a font family is more than one word long, it must be in quotation marks, like: "Times
New Roman".
The font-family CSS property specifies a prioritized list of one or more font family names and/or generic
family names for the specified element. The font-family property should have several font names as a
"fallback" system. If the browser does not support the first font, it tries the next font, and so on.
In the past, the font-family property only functioned if your site’s visitors had the same font installed on their
computers. Quite simply, if someone browsing your site didn’t have the font you applied in the website, on
his computer, the content would display with the web browser’s default font like Times New Roman. Web
safe fonts are those fonts that are most likely to be installed on the most of the devices accessing the web.
Between computers with different operating systems, you can locate around 50 web safe fonts, but with
mobile devices now accessing the web too, the number of web safe fonts drops to just a few. Arial, Times
New Roman, Times, Courier New, Courier, Verdana, Georgia, Garamond, Trebuchet MS and Impact are
some of the Web safe fonts.
For several years, web designers, annoyed by the limited range of web-safe fonts, have been asking for the
power to embed different fonts in their web pages. The condition began to transform quickly after 2008-
2009, when all major browsers finally provided support for CSS @font-face rules that specified the location
of font files. This caused the creation of many new fonts designed specifically for embedding in web pages.
Google font (https://fonts.google.com) is the most popular place to download free fonts. Some of the other
popular sites are Da Font (https://www.dafont.com) and Font Squirrel (https://www.fontsquirrel.com).
• .ttf and .otf : These are the font formats most commonly used for computer fonts.
• .woff : Web Open Font Format files is a newer font format that’s designed specifically for the Web.
• .svg : Scalable Vector Graphic format isn’t a font format, per se. It’s actually a way to create vector graphics.
@font-face{
font-family:my-font-name;
src: url(format);
The font-family property defines the name of the web font. You can select any name you want. If it has
spaces, the name must be surrounded in quotes. The src property instructs the web browser where to find the
font files. Provide multiple values for several font formats as a comma-separated list.
1. Upload font file to the server: First upload all font files to web server. Then in CSS file add
following:
@font-face{
font-face : ‘ My Font Name ’;
src : url ( ‘myfontname.eot’ );
src : url ( ‘myfontname.eot’?#iefix’ ) format(‘embedded-opentype’),
url ( ‘myfontname.woff’ ) format(‘woff’),
url ( ‘myfontname.ttf’ ) format(‘truetype’),
url ( ‘myfontname.svg’ ) format(‘svg’);
}
Inside HTML File Link “Roboto” font hosted on Google CDN as below
<link href=”http://font.googleapis.com/css?family=Roboto” rel=”stylesheet”>
Note: Many fonts are protected by copyright, so you can’t upload font files to your website without first
examining the license and seeing if there are any limitations on its use. Even if you have paid for a font, you
cannot presume that you have the right to use it in a website. It might be limited to use on your local
computer. That being said, there are hundreds of fonts that you can use, and many of them are available free
of charge.
True or False
1. .ttf and .otf are the font formats most commonly used for computer fonts
8.2.1 Adding Colors to Text
Coloring your text with CSS is easy. You have many different ways to specify the exact color you want, but
they all follow the common basic structure.
• Hexadecimal Color Notation: In this example, the color value is a hexadecimal number producing
an orange color. The most well-known color system applied by web designers is hexadecimal
notation. A color value-like #FFA500 - in fact has three hexadecimal numbers - in this example FF,
A5, 00 - each of which specify an amount of red, green, and blue, correspondingly.
color: #FFA500;
• RGB: You can even use the RGB - red, green, blue-method, this is popular in computer graphics
programs. The color value is made up of three numbers representing numbers between 0-255 for
each hue (red, green, and blue).
• RGBA: To add depth to a page, consider one of the more recent color methods. RGBA is short for
Red, Green, Blue, Alpha, and it functions just like the RGB colors with the addition of an alpha
channel. That is, you can state a level of opacity (transparency) so that the color isn’t solid, but see-
through. To the RGB colors, you add one last number, a value between 0 and 1. A value of 0 makes
the color transparent, while 1 makes the color totally opaque.
color: rgba(255,165,0,0.5);
Varying the size of text on a web page is a nice way to create aesthetic interest and direct your visitor's focus
to important aspects of a page. Headlines in large type sizes catch attention, whereas copyright notices shown
in small type quietly recede from importance. The font-size property sets text size. It’s always followed by a
unit of measurement (px, em, rem), like so:
Example:
h1{
font-size: 40px;
p{
font-size: 16px;
}
Other methods you can use to change the font size:
Keywords: Font-size can be changed using a series of keywords: xx-small, x-small, small, medium, large, x-
large, and xx-large.
font-size: large;
Percentages: When you use a percentage value, the font size is relative to the parent element’s font size,
which is inherited. Suppose the inherited font-size of an element is 16px, and if you declare that element’s
font-size as 50%, then the measured font-size is 8px.
font-size: 50px;
The font-weight property lets you make text bold, normal or light. The font-weight property accepts the
following values: bold, bolder, lighter, normal and one of nine values increasing in steps of 100 from 100 to
900 (300 equals light, 400 equals normal, and 700 equals bold).
Example:
p{
font-weight: bold;
By using the font-style property, you can change the style of a font between normal, italic, and oblique.
p{
font-style: italic;
With text-transform, you can make text all uppercase, all lowercase, or even capitalize the first letter of each
word. Text Transform accepts these values: none, uppercase, lowercase, and capitalize.
Example:
p{
text-transform: uppercase;
CSS also provides the text-decoration property to add several improvements to text. Make use of the text
decoration property by applying one or more of the following keywords: underline, overline, line-through, or
blink.
Example:
a{
text-decoration: none;
Applying the text-align property, you can center a paragraph on a page, align the text along its left or right
edge, or justify both left and right edges. Mostly, text on a page is left aligned, but you may choose to center
headline. Languages that read from right to left, like Hebrew and Arabic, need right-alignment. To alter the
alignment of text, make use of any of the following values left, right, justify, center:
Example:
h1{
text-align: center;
For more typographic elegance, you can also switch to the font-variant property, which allows you set type as
small-caps. In small cap style, lowercase letters turn up as somewhat downsized capital letters. Although hard
to read for long stretches of text, small caps give your page an old-world, bookish look when applied on
headlines and captions. To create small-cap text:
Example:
p.small{
font-variant: small-caps;
The letter-spacing property manages the amount of horizontal space between letters. In print terminology,
this is referred to as tracking. You can use normal, or px, em, rem as unit with number. Negative number
decreases the space between letters.
Example:
h1{
letter-spacing: normal;
h2{
letter-spacing: 2px;
h3{
letter-spacing: -1px;
Similar to letter-spacing, the word-spacing property helps you alter the spacing between words. The primary
value of “normal” indicates the default space between words, and you can define a length value to alter this
space as you want.
Example:
p.small{
word-spacing: -1px;
}
8.2.11 Line Height
The line-height property handles the vertical space or leading between lines of the text. Setting the line-height
property impacts the readability of a web page. Not enough space and the text look cramped and very
difficult to read. A lot of space and the reader’s eyes wander, making reading equally challenging.
This property takes a length, percentage, or number as value. A number value is a multiplication of an
element’s font size. There’s no unit (like em, rem or px) after this value. You can also use the keyword normal
to reset line-height to its default value. Negative values are not allowed.
Example:
p.a{
line-height: normal;
p.b{
line-height: 1.6;
p.c{
line-height: 80%;
The text-indent property accepts length or percentage, and indents the first line of text in every block by the
length selected. In cases where the value is a percentage, the indentation is a percentage of the parent
element’s width.
Example:
p{
text-indent: 50px;
}
8.2.13 Word Wrapping
Whenever there are no spaces in text, for example, with a long URL, the browser is unable to break it,
causing an ugly overflow. All latest browsers support the word-wrap property to manage this problem. It
takes normal, and break-word values:
Example:
p{
word-wrap: break-word;
True or False
The CSS list properties allow you to set different list item markers for ordered lists and unordered lists. You
can set an image as the list item marker as well.
List Style Type property accepts disc (a solid round bullet), circle (a hollow round bullet), or square (a solid
square) values.
Example:
ul .a{
list-style-type: circle;
ul .b{
list-style-type:squre;
}
ul .c{
list-style-type:disc;
You can control the position of the bullet points applying the list-style-position property. You can either have
the bullet appear outside of the text (the way browsers normally display bullets) or inside the text block itself.
Example:
ul .a{
list-style-position: outside;
ul .b{
list-style-position: inside;
The CSS list-style-image property lets you define a path to a graphic file on your server, just like you specify a
file when adding an image to a page by applying the src attribute of the HTML <img> tag. You can use the
property like this:
Example:
ul {
The list-style shorthand property takes the same values as the individual list-style-type, list-style position, and
list-style-image properties. You can define all three values, separated by a space, or just one or two.
Example:
ul {
True or False
1. You can control the position of the bullet points applying the list-style-position property
8.4 Summary
With font-family property you can set font. Other important properties for font mangement are font-size,
font-weight, font-style etc. You can set text color with color property. Line height, text indent, word
wrapping are some of the paragraph styles.
8.1
1. True
8.2
1. False
2. True
3. True
8.3
1. True
Chapter 9
9.0 Objectives
9.1 Introduction
9.2 Background
9.3 Summary
9.0 Objectives
9.1 Introduction
You already know that all elements on a web page are treated as boxes-some are block-level, some are inline-
level. The CSS box model is mainly a box that wraps around every HTML element. It includes: margins,
borders, padding, and the actual content. The image below illustrates the box model:
Explanation of the different parts:
• Content - The content of the box, where text and images appear, it has width and height.
• Padding - Horizontal and vertical space surrounding the content
• Border - A border that goes around the padding and content
• Margin - Horizontal and vertical space outside the border
Browsers make use of default values to individual elements. Such as, paragraphs have default top and
bottom margins, but no padding or border, whereas <div> elements have no padding, border, or
margins. You can use CSS to adjust the padding, border, and margins individually on each side of an
element to control its look and layout.
The width and height properties set the horizontal and vertical sizes of an element. The default value of
both properties is auto, meaning that the element expands or contracts to fit the natural size of the
content.
Using these properties to a style is very easy. Just type the property followed by any of the CSS
measurement units like px, em, rem or percentage (%) you’ve already learned.
Example:
div{
width:300px;
height:200px;
}
span{
width:30%;
height:25%;
There are four additional properties that let you to restrict the dimensions of an element within a given range,
namely minimum width (min-width), maximum width (max-width), minimum height (min-height) and
maximum height (max-height). Any unit of measurements like px, em, rem or percentage (%) can be used for
these properties.
Minimum Width:
Example:
div{
min-width: 300px;
height:100px;
background-color :blue;
Maximum Width:
Example:
div{
max-width: 500px;
height: 100px;
background-color: red;
Minimum Height:
Example:
div{
width: 100px;
min-height: 100px;
background-color: blue;
Minimum Height:
Example:
div{
width: 100px;
max-height: 700px;
background-color: blue;
Padding:
Both padding and margins create vertical and horizontal space around elements. But, the important difference
is that padding goes inside the border and margin goes outside the border. You can use unit of measurements
px, em, rem or percentage (%). But, negative values are not allowed.
Padding Top:
The padding-top CSS property sets the height of the padding area on the top of an element.
Example:
padding-top:20px;
Padding Right:
The padding-right CSS property sets the width of the padding area on the right side of an element.
Example:
padding-right : 5em;
Padding Bottom:
The padding-bottom CSS property sets the height of the padding area on the bottom of an element.
Example:
padding-bottom :10%;
Padding Left:
The padding-left CSS property sets the width of the padding area on the left side of an element.
Example:
padding-left :10px;
The padding CSS property creates the padding area on all four sides of an element. It is shorthand for setting
all individual padding at once: padding-top, padding-right, padding-bottom, and padding-left.
Example:
padding :10px;
The padding property may be specified using one, two, three, or four values.
• When one value is specified, it applies the same padding to all four sides.
padding: 30px;
• When two values are specified, the first padding applies to the top and bottom, the second to the left and
right.
/* vertical | horizontal */
padding: 5% 10%;
• When three values are specified, the first padding applies to the top, the second to the left and right, the
third to the bottom.
Margin:
Implementing margin is a great way of creating space between two elements on a web page. Using margins is
very similar to padding. There are separate properties to control the margin independently on each side of an
element, as well as a shorthand property.
Margin Top:
The margin-top CSS property sets the margin area on the top of an element. A positive value will place it
further than normal from its neighbors, while a negative value will place it closer.
Example:
margin-top: 15px;
Margin Right:
The margin-right CSS property sets the margin area on the right side of an element. A positive value will
place it further than normal from its neighbors, while a negative value will place it closer.
Example:
margin-right: 25px;
Margin Bottom:
The margin-bottom CSS property sets the margin area on the bottom of an element. A positive value will
place it further than normal from its neighbors, while a negative value will place it closer.
Example:
margin-bottom: 15px;
Margin Left:
The margin-left CSS property sets the margin area on the left side of an element. A positive value will place it
further than normal from its neighbors, while a negative value will place it closer.
Example:
margin-left: 20px;
9.1.3 Border:
The CSS border properties let you specify the style, width, and color of an element's border.
Border Style
Example:
Border Width
The width can be set as a specific size (px, em, rem etc) or by using one of the three pre-defined values: thin,
medium, or thick.
Example:
p.one{
border-style: solid;
border-width: 5px;
}
p.two{
border-style: solid;
border-width: medium;
p.three{
border-style: solid;
Border Color
The border-color property is used to specify the color of the four borders.
Example:
p.one{
border-style: solid;
border-width: 3px;
border-color: red;
p.two{
border-style: solid;
border-width: 3px;
border-color: #009900;
}
p.three{
border-style: solid;
border-width: 3px;
border-color: rgb(0,0,204);
To shorten the code, it is also possible to specify all the individual border properties in one property.
The border property is a shorthand property for the following individual border properties:
• border-width
• border-style (required)
• border-color
Example:
p{
You can also specify all the individual border properties for just one side:
Example:
p{
}
Rounded Borders
Example:
p{
border-radius:5px;
True or False
9.2 Background
The key to the good web design is attracting the visitor’s eyes to important parts of the page. Background
colors and images make it easier to break up the page and focus attention.
Example:
body{ background-color: red;}
p{ background-color:#ff0000;}
The background-image CSS property sets one or more background images on an element.
Example:
body{
background-image: url(“image.png”);
}
div{
background-image: url(“assets/images/image.png”);
The background-repeat CSS property specifies how background images are repeated. A background image
can be repeated on the horizontal axis, the vertical axis, both axes, or not repeated at all. The values we can
use for background -repeat property are repeat, repeat-x, repeat-y, no-repeat.
Example:
body{
background-image: url(“image.png”);
/* repeat vertically */
background-repeat: repeat-y;
The background-position CSS property sets the initial position for each defined background image.
The first value is horizontal position (x axis) while the second value is vertical position (y Axis).
Example:
body{
background-image: url(‘image.png’);
background-repeat: no-repeat;
background-position: left-top;
div{
background-image: url(‘picture.png’);
background-repeat: no-repeat;
background-position: 50% 0;
}
The value for background-position may be:
1. One of the keyword values top, left, bottom, right. This specifies an edge against which to place the
item.
2. We can use a length like bottom 100px or percentage value like 50% .
The background-size CSS property specifies the size of an element's background image. The image can be left
to its natural size, stretched to a new size, or constrained to fit the available space while preserving its intrinsic
proportions.
Example:
.first{
background-image: url(‘image.png’);
background-repeat: no-repeat;
background-size: auto;
.second{
background-image: url(‘image.png’);
background-repeat: no-repeat;
.third{
background-image: url(‘image.png’);
background-repeat: no-repeat;
background-size: cover;
}
The values we can use for background-size are
• Auto: The default value. The background image is displayed in its original size
• Contain: Resizes the image as large as possible without cropping or stretching the image.
• Cover: Scales the image as large as possible without stretching the image. If the proportions of the
image differ from the element, it is cropped either vertically or horizontally so that no empty space
remains.
• Length: Stretches the image in the corresponding dimension to the specified length. (e.g. 300px)
• Percentage: Stretches the image in the corresponding dimension to the specified percentage. (e.g.
50%)
The background CSS property allows you to adjust all background style options at once, including color,
image, origin and size, repeat method, and other features. The property is a shorthand that sets the following
properties in a single declaration: background-color, background-image, background-position, background-
repeat and background-size.
Example:
body{
True or False
1. The background-size CSS property specifies how background images are repeated
9.3 Summary
Every HTML box element is composed of four parts, defined by their respective edges: the content, padding,
border and margin. The content part of element has width and height. You can use properties like padding,
border and margin to manage the space around the content. You can change background color or image with
background property.
9.1
1. False
2. True
3. True
9.2
1. False
Chapter 10
Page Layout
10.0 Objectives
10.1 Introduction
10.3.2 Z-index
10.4 Summary
10.0 Objectives
- control visibility
10.1 Introduction
Positioning enables you to take elements out of the regular document layout flow, and make them act in a
different way, for example sitting on top of one another, or always remaining in the same place inside the
browser viewport. By default, HTML elements are all position: static, this means they are positioned
according to their actual place in the default flow. Statically positioned elements cannot have their top, left,
right, and bottom properties altered.
There are a number of different types of positioning that you can put into effect on HTML elements. To
make a particular type of positioning active on an element, you can use the position property.
Static: Static positioning is the default that each and every element gets. This leaves the element in the
normal document flow. The only time you need to use static is if you want to override another style rule to
make an element act like normal HTML.
Example:
p{
position: static;
background: yellow;
Relative: This moves the element relative to its normal position in the document flow, but without impacting
the position of other elements. By indicating position: relative on an element, you tell the browser to position
it relative to its default position in the document flow. You can now make use of left, top, right, or bottom
rules to the element and it will move out of its location as you specify.
Example:
p{
position: relative;
Absolute: This takes out the element, including any child elements, entirely from the flow of the document,
and positions it at the chosen offsets. If the element is nested inside another positioned element, the offsets
are calculated with reference to the positioned parent. Usually, the offsets are calculated with reference to the
page.
Example:
p{
position: absolute;
background: blue;
}
Fixed: This works simply the same way as absolute positioning, with one key difference - unlike absolute
positioning fixes an element in place relative to the <html> element or its nearest positioned ancestor, fixed
positioning fixes an element in place relative to the browser viewport itself.
Example:
p{
position: fixed;
You can specify where an element is positioned by setting offsets from its containing block with the top,
right, bottom, and left properties, all of which accept a length or a percentage.
Example:
div{
top:200px;
left:100px;
Float-based layouts take benefit of the float property to position elements side-by-side and create columns on
a web page. The float property moves a page element to one side of the page. Any HTML element that
appears below the floated element moves up on the page and wraps around the float. The float property takes
one of three different values-left, right, and none. You should always give your floated element a width. To
move an image to the right side of the page as shown below:
Example:
img{
float: right;
width:300px;
Floats are effective design tools as they let content flow around them. Floating a photo lets text below it
move up and wrap around the image. When you’re creating float-based column designs, though, occasionally
you don’t want the content to move up and next to a floated element. In such situations you can use the clear
property. This property stops an element from wrapping around floats. You can use left, right and both as
value for clear property.
Example:
img{
clear: both;
True or False
1. Statically positioned elements cannot have their top, left, right, and bottom properties altered
2. clear property stops an element from wrapping around floats
CSS manages all elements as boxes, the two main types being block level and inline. The display property
provides you the power to change an element’s box type by using one of the values: block, inline, inline-
block, flex, none.
Example:
li{
display: inline-block;
The visibility CSS property can show or hide an element without impacting the layout of a document.
Visibility property accepts visible and hidden as values. The value visibility: hidden, hides the element but
does not remove it from the page layout. If you want to remove the element totally then you should use
display: none
Example:
span{
visibility: hidden;
}
10.3.2 Z-index:
The z-index CSS property identifies the z-order of a positioned element and its descendants. When elements
overlap, z-order decides which one appears on the top of the other. An element with a larger z-index shows
up on the top of the other element with a lower z-index.
Example:
p{
z-index:100;
The overflow CSS property specifies what to do when an element's content is too big to fit in its block
formatting context. The overflow property takes visible, hidden, scroll, auto values. It is shorthand for the
overflow-x and overflow-y properties.
Example:
div{
overflow: hidden;
The main feature of flexible box layout is that it makes a block known as a flex container, in which the flow
of the document can be virtually turned on its head. Everything inside the flex container becomes a flex item
that can be displayed in a different order from the underlying HTML.
Example:
HTML
<div class=”container”>
<div>1</div>
<div>2</div>
<div>3</div>
</div>
CSS
.container{
display: flex;
Flex Direction:
The flex-direction property defines in which direction the container wants to stack the flex items. flex-
direction property takes column, row, column-reverse, row-reverse as values.
Example:
.container{
display: flex;
flex-direction: column;
Flex Wrap:
The flex-wrap property specifies whether the flex items should wrap or not. The values you can use are wrap
and nowrap.
Example:
.container{
display: flex;
flex-direction: column;
flex-wrap: wrap;
Justify Content:
The justify-content property is used to horizontally align the flex items. Values accepted by this property are
center, flex-start, flex-end, space-around and space-between.
Example:
.container{
display: flex;
justify-content: center;
}
Align Items:
The align-items property is used to align the flex items vertically. The values accepted by this property are flex-
start, flex-end, center
Example:
.container{
display: flex;
height:200px;
align-items: center;
True or False
1. When elements overlap, z-order decides which one appears on the top of the other
2. Visibility property removes element from the page layout
10.4 Summary
With the help of position property, you can take elements out of the regular document layout flow. You can
use float property to position elements side-by-side. Visibility property hides the element but does not
remove it from the page layout. Flexbox is a new and exciting addition to CSS3, with concepts like flex
container, flex item, flex direction.
10.2
1. True
2. True
10.3
3. True
4. False
Chapter 11
Responsive CSS
11.0 Objectives
11.1 Introduction
11.2 Summary
11.0 Objectives
11.1 Introduction
It’s very difficult to read a four-column web page on a phone whose screen is just 320 pixels wide. It’s just as
difficult to read a single column of text that’s displayed across the 2560 pixels of a large desktop monitor.
Responsive web design, a term coined by web design pioneer Ethan Marcotte, is an effort to solve that
problem. Responsive web design, or RWD for short, enables you to change the complete layout of a page
based on browser window width, so you can develop the most readable presentation for each device, without
having to create multiple versions of the same website. RWD is not a single technology or technique. Rather,
it brings together several CSS and HTML methods to create web pages whose layouts adapt to different
screens.
Responsive web design technique takes advantage of several distinct tricks to make a page change its layout
based on the width of the browser screen. On a smartphone, for example, you can lay out a page in a single,
easy-to-read column to fit the narrow width of the screen while maintaining a multicolumn layout on wider
monitors.
RWD combines three main ideas: flexible grids for layout, flexible media for images and video, and most
importantly CSS media queries to create different styles for different screen widths.
• With flexible grids, you skip fixed-width layouts. Since smartphone screens come in a wide variety of
widths, it makes no sense to create a page at a fixed width; instead, you want the page to grow or
shrink to fit the particular device.
• Creating flexible media lets your images and videos scale to fit the appropriate screen real estate…big
photos for big monitors, smaller photos for small screens, and so on.
• Finally, media queries are a CSS technology that lets you send different styles to a browser based on
current conditions. For example, you can send one set of styles when the screen is less than 480
pixels wide and another set when the window is more than 760 pixels wide.
Simply add the following code to the <head> section of your web page
The viewport refers to the browser screen, and the content attribute sets the width of the browser to the
width of the phone’s. In other words, on mobile browsers that tend to zoom out, you’re telling them not to
zoom out, but to just make the screen’s width match the actual display of the phone.
There’s a wide variety of widths for these devices. You can have small phones, large phones, tablets, laptops
and large screen pc. Here are screen width sizes of some of the current popular devices:
• Desktop first. You can design your site with the desktop in mind. This becomes your base design,
and you can put all of these styles into an external style sheet and link it to the pages of your site as
you normally would.
• Mobile first. You can flip that approach on its head by designing first for mobile browsers. This
time, you put the basic small-screen styles in a regular external style sheet, and then refine the design
for tablets and desktops by adding columns and other adjustments for larger screens in media
queries.
Example:
@media(max-width:576px){
body{
@media(min-width: 768px){
body{
body{
}
11.1 Check Your Progress
True or False
1. CSS media queries create different styles for different screen widths
2. Flexible media lets your images and videos scale to fit the appropriate screen size.
3. In desktop first approach you can design your site with the mobile in mind
11.2 Summary
Responsive web design technique use many distinct tricks to make a page change its layout based on the
width of the browser screen. You can either build RWD based site with Desktop First approach or Mobile
first approach.
11.1
1. True
2. True
3. False
•
12.0 Objectives
12.1 Introduction
12.2.3 Gradient
12.2.4 Transformations
12.2.5 Transitions
12.3 Summary
12.0 Objectives
12.1 Introduction
CSS continues to mature as a language, and as it does it gives us a greater ability to create with code. Box
shadows, gradient effects, transforms, transitions, and CSS animations are excellent examples of things we
can create with CSS.
Example:
To add more than one shadow to the text, we need to add a comma-separated list of shadows.
Example:
Example:
Example:
Linear Gradients: Linear gradients are used to arrange two or more colors in linear formats like top to
bottom, left to right etc
Example:
background: linear-gradient (to right, orange, yellow);
Other than “to right”, we can also use “to left”, “to top”, “to bottom” value depending upon which direction
we want the color combinations to go.
You can even make the gradient run diagonally, from corner to corner.
The following example shows linear gradient that starts from top left to bottom right.
Example:
We can get more control over the direction of the gradient, by defining an angle, instead of the predefined
directions (to bottom, to top, to right, to left, to bottom right, etc.).
Example:
Radial Gradients: Radial gradient are used to arrange two or more colors emerge from a point and smoothly
spread outward in a circular shape.
Example:
12.2.4 Transformations
CSS3 presents many properties that transform a web page element, by either rotating it, scaling it, moving it,
or distorting it along its horizontal and vertical axes. The basic CSS property to accomplish any of these
changes is the CSS transform property. You use this property by providing the type of transformation you
want and a value indicating how much to transform the element. For example, to rotate an element, you
supply the keyword rotate, followed by the number of degrees to turn it:
transform: rotate(10deg);
Scale
You can also resize an element, making it bigger or smaller using the scale function. For example, to make an
element twice as big, you add this declaration:
Skew
Skewing an element lets you slant it on its horizontal and vertical axes: this can give an element a three-
dimensional feel. The skew function takes two values: the first specifies the horizontal movement and the
second the vertical movement. You can use values between 0deg to 360 deg.
Translate
The transform property’s translate function simply moves an element from its current position a set amount
left or right and up or down. By itself, it’s really not that useful. When a web browser transforms an element,
it doesn’t rearrange the page and the browser leaves an empty space where the tag would normally appear and
then draws the element in its new position.
The translate function takes two values: the first specifies the horizontal movement and the second the
vertical movement. You’re not limited to pixel values either. Any valid CSS length value — px, em, %, and so
on will work.
Transitions
While transforms can be fun, they really bring your page to life when coupled with a CSS3 transition. A
transition is simply an animation from one set of CSS properties to another set over a specific amount of
time. For example, you can make a banner rotate 360 degrees over the course of two seconds.
1. Two styles: One style represents the beginning look of the element — a red button, for example —
while the second style is the ending look — a green button. The web browser will take care of the
process of animating the change between the two styles (changing the button from red to green, for
example).
.button {
Background-color: red;
}
.button : hover {
Background-color: green;
}
2. The transition property: CSS3 adds the transition property—the secret sauce that makes the
animation possible. In general, you apply the transition property to the original style, the style that
defines the look of an element before the animation begins.
.button {
background-color: red;
transition-property: background-color;
transition-duration: 1s;
}
.button: hover {
Background-color: green;
}
3. A trigger: The trigger is the action that causes the change between the two styles. With CSS, you can
use several pseudo-classes to trigger an animation. The most common is the :hover pseudo-class.
With it, you can animate the change between an element’s normal appearance and how it looks when
a visitor mouse over it.
transition-delay: .5s;
True or False
1. Translate function simply moves an element from its current position to new location.
2. Skewing an element lets you resize the elements
3. You can delay animation with transition-delay property
12.3 Summary
The text-shadow CSS property adds shadows to the text. Box shadow property is similar to the text shadow
property. Gradients are combination of two or more colors. With CSS you can add different types of
gradients. CSS3 has many properties that transform a web page element.
12.4 Check Your Progress Answers
12.2
1. True
2. False
3. True
Chapter 13
Introduction to Bootstrap 4
13.0 Objectives
13.1 Introduction
13.3 Summary
13.0 Objectives
- what is bootstrap
13.1 Introduction
Bootstrap is an open source free front-end framework from Mark Otto and Jacob Thornton who, when it
was initially released, were both employees at Twitter. Since Bootstrap launched in August 2011, it has taken
off in popularity. It has evolved from being an entirely CSS-driven project to include a host of JavaScript
plugins that go hand in hand with forms and buttons. At its base, it allows for responsive web design and
features a robust 12-column.
If you don’t want to download bootstrap file, you can alternatively use the CDN method as below to link
bootstrap files.
<link rel=”stylesheet”
href=”https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css”>
<script
src=”https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js”></script>
Note: Make sure that you change the version number 4.0.0 to latest version in above links
The classes above can be combined to create more dynamic and flexible layouts.
Following is an example of 3 column grid for large and extra large screen
Example:
<div class=”container”>
<div class=”row”>
<div class=”colo-1g-4”>1 of 3 columns</div>
<div class=”col-1g-4”>1 of 3 columns</div>
<div class=”col-1g-4”>1 of 3 columns</div>
</div>
</div>
13.2.2 Bootstrap Content Classes
Bootstrap comes with pre built styles for typography, images, table etc. Here are some important styles:
Heading
Normal heading tags h1 through h6 work nicely most of the time. But there are times when you will need
larger font size for heading. Bootstrap has 4 different levels of display styles display-1 through display-4.
Typography
Images
With Bootstrap 4 you can make images responsive and change shape as well.
Responsive Images
When you use img-fluid class of Bootstrap 4 for any image, the image gets resized based on the screen size.
Images in Bootstrap are made responsive with max-width of image to 100% and height to auto.
Table
The basic table structure can be easily set with the bootstrap class name “table”. By default it adds nice
padding and formatting to the content.
<table class=”table”>
…
</table>
Buttons
Buttons are one of the most commonly used components in Bootstrap. Bootstrap includes several predefined
button styles, each serving its own semantic purpose, with a few extras thrown in for more control. Bootstrap
class “btn” creates the basic button while other classes add extra features.
True or False
Bootstrap is an open source free front-end framework. Grid systems enable you to create advanced layouts
using rows and columns. Bootstrap comes with pre built styles for typography, images, table etc.
13.2
1. True
2. True
3. False
Chapter 14
Introduction to JavaScript
14.0 Objectives
14.1 Introduction
14.1.6 Comments
14.2 Summary
14.0 Objectives
- what is JavaScript
- JavaScript syntax
14.1 Introduction
JavaScript is a scripting language that enables you to supercharge your HTML with animation, interactivity,
and dynamic visual effects. Majority of the modern day websites use JavaScript, and all current web browsers-
on desktops, game consoles, tablets, and smart phones-contain JavaScript interpreters, making JavaScript one
of the most utilized programming language in the history. JavaScript is part of the triad of technologies that
all Web developers need to learn: HTML to define the content of web pages, CSS to specify the appearance
of web pages, and JavaScript to specify the behavior of web pages. On web pages it provides interactivity,
from basic animation effects to form validation to full-fledged single-page applications.
When JavaScript first came out in 1995, its primary goal was to deal with some of the input validation that
had previously been left to server-side languages such as Perl. Prior to that time, a round-trip to the server
was required to decide if a required field had been left blank or an entered value was invalid. Since that time,
JavaScript has expanded into an essential feature of every major web browser on the market.
JavaScript Features:
Plenty of people believe that JavaScript is similar to the Java language as it contains the name but it is not
true. JavaScript, in spite of the name, is essentially unrelated to the Java programming language, even though
both have the common C syntax, and JavaScript copies many Java names and naming conventions. The
language JavaScript was originally named "LiveScript" but was renamed in a co-marketing deal between
Netscape and Sun.
The JavaScript programming language, developed by Netscape, Inc., is not a product of the Java platform.
JavaScript does not create applets or stand-alone desktop applications. In its most common form, JavaScript
exists inside HTML documents, and can generate levels of interactivity to web pages that are not achievable
with plain HTML.
Client-server is a software architecture model comprising two parts, client system and server system, both
interacting over a computer network. A client-server network is engineered for end-users, referred to as
clients, to gain access to resources such as files, songs, video collections, or some other service from a central
computer known as a server. A server's only purpose is to do what its name implies - serve its clients!
Client: Requests for resources over the network or internet. Clients include Web browsers, chat applications,
and email software etc.
Server: Listen to the clients requests and provide the desired resources (data, files, audio, video, images etc.)
to the clients over the network.
Website scripts run in one of two places - the client side, also known as the front-end, or the server side, also
known as the back-end. The client of a website refers to the web browser that is browsing it. The server of a
website is, obviously, the server that hosts it.
The majority of the web coding languages are designed to operate on either the server side or the client side.
This mainly defines how they work. Here are some examples.
Client side development is carried out almost entirely in JavaScript. This is, obviously, in addition to basic
HTML and CSS code. The reason JavaScript is referred to as a client side language is mainly because it runs
scripts on your computer after you’ve loaded a web page.
A server side or back-end language runs its scripts prior to the HTML is loaded, not after. There are a range
of server side languages in use on the web today. PHP is one of the most preferred, as well as Ruby on Rails,
ASP.NET and many more. They are referred to as server side languages mainly because their scripts are run
not on your computer, but on the server that hosts the website and delivers down the HTML code.
The primary method of inserting JavaScript into an HTML page is via the <script> element. There are two
ways to use the <script> element: embed JavaScript code directly into the page or include JavaScript from an
external file.
To include inline JavaScript code, place JavaScript code inside the <script> element directly, as follows:
Example:
<script type=”text/javascript”>
Alert(“Hello!”);
</script>
To include JavaScript from an external file, the src attribute is required. The value of src is a URL linked to a
file containing JavaScript code, like this:
Traditionally, all <script> elements were placed within the <head> element on a page, such as in this
example:
<!DOCTYPE hmtl>
<html>
<head>
<title>Page Title</title>
</head>
<body>
</body>
</html>
However, adding all JavaScript files in the <head> of a document means that all of the JavaScript code has
to be downloaded, parsed, and interpreted before the page starts rendering. For pages that require a lot of
JavaScript code, this can cause an obvious delay in page rendering, during that time the browser will be
entirely blank. For this reason, modern web developers mainly include all JavaScript references in the
<body> element, after the page content, as shown in this example:
<!DOCTYPE hmtl>
<html>
<head>
<title>Page Titiel</title>
</head>
<body>
</body>
</html>
Here is a simple Hello World example of using JavaScript. If you run this program, you will get an alert
message “Hello, world!”
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
</script>
<body>
</html>
14.1.5 JavaScript Syntax:
JavaScript borrows most of its syntax from Java, but also inherits from languages like Awk and Perl.
Case Sensitivity:
JavaScript is a case-sensitive language. It indicates that the language keywords, variables, function names, and
any other identifiers must always be typed with a consistent capitalization of letters. So the identifiers myVar
and MYVAR will convey different meanings in JavaScript. Care should be taken while writing variable and
function names in JavaScript.
Spaces, tabs and newlines used outside of string constants are called whitespace. JavaScript ignores spaces,
tabs, and newlines that appear in JavaScript programs. You can use spaces, tabs, and newlines freely in your
program and you are free to format and indent your programs in a neat and consistent way that makes the
code easy to read and understand.
Semicolon is optional at the end of the statement, although it is good practice to use it to avoid undesired
results.
• Any text between a // and the end of a line is treated as a comment and is ignored by JavaScript.
• Any text between the characters /* and */ is treated as a comment. This may span multiple lines.
Example:
<script type=”text/javascript”>
/*
*/
</script>
14.1.7 Reserved Words in JavaScript:
JavaScript reserves a number of identifiers as the keywords of the language itself. You cannot use these words
as identifiers in your programs: break, delete, function, return, typeof, case, do, if, switch, var, catch, else, in,
this, void, continue, false, instanceof, throw, while, debugger, finally, new, true, with, default, for, null, try
True or False
14.2 Summary
JavaScript is a scripting language that helps you add animation, interactivity, and dynamic visual effects to
HTML document. Java and JavaScript are two completely different languages. Traditionally JavaScript was
regarded as client side languages, but due to recent developments it can also be used as server side language.
JavaScript is a case sensitive language.
14.1
1. True
2. True
3. False
Chapter 15
15.0 Objectives
15.1 Introduction
15.3 Arrays
15.3.1 Object
15.4 Summary
15.0 Objectives
15.1 Introduction
Variables can be seen as named containers. You can set data into these containers and then refer to the data
simply by naming the container. Before you use a variable in a JavaScript program, you have to declare it.
JavaSctipt variables are loosely typed, which means that a variable can hold any type of data. Every variable is
just a named placeholder for a value. To define a variable, use the var keyword followed by the variable name.
Example:
var message;
This code defines a variable named message that can be used to hold any value. Without initialization, it has
the special value undefined. It is possible to define the variable and set its value at the same time, as in this
example:
var message = “Welcome”;
We manage distinct types of information every day e.g. name, age, price of product, address, date.
Programming languages classify this information into different types, and treat each type in a different way. In
JavaScript, there are three primary data types, two composite data types, and two special data types.
Numbers are used for counting and calculating. Unlike many languages, JavaScript does not make a
distinction between integer values and floating-point values.
Integer Values
Integer values can be positive whole numbers, negative whole numbers, and 0.
Floating-point Values
Floating-point values can be whole numbers with a decimal portion e.g. 12.77
Example:
Mathematical Operations:
Holding a particular piece of information such as a number in a variable is generally a first step in a program.
In JavaScript you can manipulate data to obtain new results. For example, you can add a number to a score to
increase it or perform other arithmetic operations like subtraction, multiplication or division.
Basic Math
JavaScript supports basic mathematical operations such as addition, division, subtraction, and so on.
Example:
alert (totalCost);
//output : 150
To store a name, a sentence, or any series of letters, you make use of strings. A string is just a series of
characters (letters and other symbols) enclosed inside of quote marks. For example, 'Welcome!', and "John
Smith" are both examples of strings. A string’s opening quote mark explains the JavaScript interpreter that
what follows is a string. You can use either double quote marks "hello world" or single quote marks 'hello
world' to enclose the string, but you need to make sure to use the same type of quote mark at the starting and
end of the string.
Example:
alert(myName);
Concatenate Strings:
One of the many built-in features of JavaScript is the ability to concatenate strings. If you use the + operator
with numbers, it adds them. But if you use this operator on strings, it joins them by appending the second to
the first.
Example:
alert(message + “ ” + user);
A boolean value represents true or false, on or off, yes or no. There are only two possible values of this type.
Boolean values are generally the result of comparisons you make in your JavaScript programs.
Example:
var a= true;
Undefined:
Undefined value means a variable has been declared but has not yet been assigned a value.
Example:
Null:
Example:
To create and store items in an array, you first declare the array’s name (just as you would a variable) and then
provide a list of comma-separated values: each value presents one item in the list. To create an array, you put
the list of items between opening and closing brackets: [ ].
Example:
You can get access to the contents of a basic variable just by using the variable’s name. But, because an array
can hold more than one value, you can’t just use its name alone to access the items it contains. A number,
called an index, displays the position of each item in an array. To obtain a particular item in an array, you use
that item’s index number. Arrays are zero-indexed, meaning that the first item in an array has an index value
of 0, and the second item has an index value of 1.
Example:
alert(days[0]);
//output : Mon;
15.2.1 Object:
The real life is full of objects, like a car or a dog. Many objects are made up of different parts: A dog has a tail,
a head, and four legs; a car has doors, wheels, headlights, and a horn. An object might also do something - a
car can transport passengers, a dog can bark.
The world of JavaScript is also full of objects: a browser window, a document, and a date are a few examples.
Like real-world objects, JavaScript objects are also made up of different parts. In programming language, the
parts of an object are known as properties. The actions an object can carry out are referred to as methods or
functions.
Every object in JavaScript possesses its own set of properties and methods. To access an object’s property or
execute one of its methods, you use dot syntax.
For example, document.write() means "run the write() method of the document object."
15.2 Check Your Progress
15.3 Summary
Variables are named containers. You can set data into these containers and then refer to the data simply by
naming the container. String, number, boolean, object, array, null and undefined are data types in JavaScript.
Variables store single piece of information while array store list of comma separated values.
15.1
1. Undefined
2. Boolean
15.2
1. Array
Chapter 16
16.0 Objectives
16.1 Introduction
16.2 If Statements
16.4 Summary
16.0 Objectives
- switch statement
16.1 Introduction
Usually when you write code, you want to do different actions for different decisions. You can use
conditional statements in your code to accomplish this.
16.2 If Statement
The “if” Conditional statements perform a task only if the answer to a question is true:
if ( condition ){
There are three parts to the statement: “if” indicates that the programming that follows is a conditional
statement; the parentheses enclose the yes or no question, known as the condition; and the curly braces ({ })
mark the start and end of the JavaScript code that should execute if the condition is true.
Example:
Example:
if ( condition ) {
//statement 1
} else{
//statement 2
}
This form of the statement executes statement 1 if expression is true and executes statement 2 if expression is
false.
The if/else statement examines an expression and executes one of the two pieces of code, based on the
outcome. But what about, when you need to execute one of many pieces of code? One way to do this is with
an else if statement.
Example:
if (a ==1) {
//Execute statement 1
else if (a == 2) {
//Execute statement 2
else if ( a == 3){
//Execute statement 3
else {
Switch statement is closely related to the “if” statement. The syntax for the switch statement in JavaScript is
similar to the syntax in other C-based languages:
Switch (expression) {
case value :
statement
break;
case value :
statement
break;
case value :
statement
break;
case value :
statement
break;
default : statement
Every case in a switch statement says, “If the expression is equal to the value, execute the statement.” The
break keyword triggers code execution to jump out of the switch statement. The default keyword implies
what is to be done if the expression does not evaluate to one of the cases.
var color = “Yellow”;
switch (color) {
case ‘Blue’:
alert (“Blue”);
break;
case ‘Yellow’
alert (“Yellow”);
break;
case ‘Red’
alert (“Red”);
break;
default :
True or False
while (condition) {
// do something
}
The first line presents the while statement. Just like a conditional statement, you place a condition between
the set of parentheses that follow the keyword while. The condition is any test you’d use in a conditional
statement, such as i <=3.
But, contrary to a conditional statement, when the JavaScript interpreter reaches the closing brace of a while
statement, rather than moving forward to the next line of the program, it gets back to the top of the while
statement and tests the condition a second time. If the condition is yet again true, the interpreter runs the
JavaScript code between the braces a second time. This process carries on till the condition is no longer true;
then the program moves on to the next statement following the loop.
Example:
var i = 1;
while (i <=3){
i =i + 1;
The first line of code var i = 1; isn’t part of the while loop: Rather, it creates a variable to hold the number.
The second line is the start of the loop. It sets up the test condition. So long as the number stored in the
variable "i" is less than or equal to 3, the code between the braces runs. When the test condition is tested for
the first time, the value of i is 1, so the test is true (1 is less than 3), and the document.write() command
executes, writing “Value of i is: 1” to the page (the <br> is just an HTML line break to ensure each line prints
onto a separate line on the web page).
The last line of the loop “ i = i+1;” is very important. It increases the value of variable i by 1. This process
continues until the condition is no longer true; that is when the value of variable i becomes more than 3. Just
after the value of variable i becomes 4 the program exits the while loop.
There exists one more, less common type of loop, named a “do while” loop. This type of loop works nearly
in the same ways to a while loop. Its basic structure looks like this:
do{
// javascript to repeat
} while ( condition );
In this kind of loop, the conditional test occurs at the end, after the loop has run. Because of this, the
JavaScript code within the curly braces always runs at least once. Even if the condition isn’t ever true, the test
isn’t performed until after the code runs once. There aren’t too many cases where "do while" is useful.
var i = 0;
do {
i = i + 1;
alert ( i );
A for loop is usually used in the same way a while loop is, particularly, to execute code a certain number of
times. You use a “for” loop to generate a loop in which the conditions are initialized, evaluated, and changed
in a efficient form. Here’s an example:
alert ( i );
A for statement has three clauses in parentheses. The first clause sets the primary expression, as shown in the
preceding example and also here:
var i= 1;
The next clause of a “for” statement identifies the test expression, displayed by the following code from the
example:
i <= 3;
The final expression is generally used to increment the counter used for the test. In the code example, this
expression is the final clause in the parentheses:
i ++;
Check Your Progress
True or False
16.4 Summary
Conditional statements are used to decide the flow of execution based on different conditions. If a condition
is true, you can perform one action and if the condition is false, you can perform another action. There are
three JavaScript conditional statements – if statement, if/else statement, if-else-if statement. You should use
loops when you want to run series of steps over and over again. “For loop” and “while loop” are popular
loops in JavaScript.
16.2
1. True
2. True
3. True
16.3
1. True
Chapter 17
17.0 Objectives
17.1 Introduction
17.2 Summary
17.0 Objectives
- how to pass data to function and receive back the return value
17.1 Introduction
So far, all the JavaScript code we’ve seen executes as soon as the page loads in your browser. It runs from top
to bottom and then stops, never to run. Quite often, we’ll want to execute different parts of our program at
different times, or re-run the same code quite a few times. In order to do this, you have to put your code into
functions.
Functions are like little packages of JavaScript code waiting to be called into action. A function can essentially
be seen as a wrapper for a block of code. All you need to do is name that block, and you’ll be able to call it
from other areas of your program, whenever you like.
You can define your own functions using the function keyword. This tells the program that you’re defining a
new function, and that the code contained between the curly braces that follow should be executed whenever
that function is called.
}
Although the function message is declared above, the code inside it won’t get executed till you invoke it.
Invoking Function:
message ();
Functions are perfect when you have something that needs to happen multiple times within a program.
Rather than defining the same code multiple times, you can use a function.
Functions can accept arguments, which are input values passed into the function. Within a function, those
arguments passed into the function can be acted upon and the results returned to the caller of the function
via a return value.
Arguments are passed to a function within the parentheses of the function definition. Here’s a brief example
of using function arguments:
//Do something
Example:
In the above example, the function “message” accepts two arguments userName and userMessage. These two
arguments are then displayed through alert function. On the last line function “message” is invoked passing
two values to the function.
Thus far, the outcome of most of our functions has been to display an alert box to the user with a message in
it. But most of the time, you’ll want your functions to be silent, simply passing data to other parts of your
program. A function may return data to the statement that called it. The neat thing about that is that you can
assign a function call as the value of a variable, and that variable’s value will become whatever was returned
by the function.
To get a function to return a value, we use the return keyword, followed by the value we want it to return:
Example:
var sumTotal;
alert (sumTotal);
// output: 7
In the above example, first we have declared 1 variable to store the returned value of function. Then we have
declared a function named “sum”. The “sum” function accepts 2 arguments. It then adds the two arguments
and returns back the total. Till now nothing happens as we have not yet invoked or called the function. On
the next line we have invoked the “sum” function and passed 2 values to process. The result returned back by
“sum” function is stored in the variable sumTotal. On the last line the value in sumTotal variable is displayed
through alert function.
In JavaScript there are two types of scope local scope and global scope. Each JavaScript function creates a
new scope. Variables defined inside a function are not accessible from outside the function. Variables
declared within a JavaScript function, become LOCAL to the function. Local variables have local scope: They
can only be accessed within the function.
function myFunction( ){
}
A variable declared outside a function, becomes GLOBAL.
function myFunction( ){
17.2 Summary
Functions are like little packages of JavaScript code waiting to be called into action. By merely defining the
function the code inside the function does not automatically execute. You need to invoke the functions to
execute it. Function accepts parameter and returns value. Variable defined inside a function has local scope,
while variable defined outside the function has global scope.
17.1
1. False
2. True
Chapter 18
18.0 Objectives
18.1 Introduction
18.2 Summary
18.0 Objectives
18.1 Introduction
The DOM represents HTML documents in a tree-like structure — or rather, an uprooted treelike structure
because the root of the tree is on top.
Inside DOM model each element in the HTML document becomes an object, as do all the attributes and
text. JavaScript can access each of these objects independently, using built-in functions that make it easy to
find and change what we want on the fly. Due to the way in which HTML is written-as a hierarchy of nested
elements marked with start and end tags-the DOM creates a different object for each element, but links each
element object to its enclosing (or parent) element. This produces an explicit parent-child relationship
between elements, and lends the visualization of the DOM most readily to a tree structure. The Document
Object Model provides a way to access and alter the contents of Hypertext Markup Language (HTML)
documents. The DOM is a standard defined by the World Wide Web Consortium (W3C).
<html>
<head>
<title>Hello World</title>
</head>
<body>
</body>
</html>
Nodes:
To generate the DOM for a document, every element in the HTML is displayed by what’s known as a node.
A node’s position in the DOM tree is determined by its parent and child nodes. An element node is
recognized by its element name (head, body, h1, etc.).
The elements inside the tree structure are sometimes referred to as nodes or node objects. Nodes at the level
under a given node are known as children. For example, the <body> node is said to be a parent of the <p>
nodes. Any nodes under a given node are known as descendants of that node.
Finding the elements of a document is an essential way you use the DOM when programming with
JavaScript. The document.getElementsByTagName() method selects every instance of a particular tag -
document.getElementsByTagName('a'), for example, selects all anchor tags on a page;
You could then examine the properties of the “a” elements stored in the myAnchors variable by looping
through them.
The getElementsByClassName() method returns a collection of all elements in the document with the
specified class name.
The getElementById() method is a workhorse method of the DOM. It retrieves a specified element of the
HTML document and returns a reference to it. To retrieve an element, it must have an id attribute.
Every element node — except for the document node — has a parent. Consequently, each element node has
a property called parentNode. When we use this property, we receive a reference to the target element’s
parent.
Once we have a reference to the element, we can get a reference to its parent using parentNode like so:
The parent-child relationship isn’t just one way. You can discover all of the children of an element applying
the childNodes property. An element can only have one parent, but it can have many children, so childNodes
is in fact a node list that contains all of the element’s children, in source order.
You can get first child and last child in above example as below:
var z = y.firstChild;
var k = y.lastChild;
As well as moving up and down the DOM tree, we can move from side to side by getting the next or
previous node on the same level. Continuing with the last example, we can use nextSibling and
previousSibling to do so.
var b = y . nextSibling;
var c = y . previousSibling;
Attributes like width, height, src etc. are localized to the elements they’re associated with-they don’t have
much significance in the bigger scheme of things. So, we don’t have DOM functions that will let you get a
particular attribute node, or all attributes with a certain value. DOM only provides two methods related to
attributes, and both of them can only be used when you you have an element reference.
Getting an Attribute
With a reference to an element already in hand, you can get the value of one of its attributes by calling the
method getAttribute with the attribute name as an argument.
Setting an Attribute
As well as being readable, all HTML attributes are writable via the DOM. To write an attribute value, we use
the setAttribute method on an element, specifying both the attribute name we want to set and the value we
want to set it to:
Nearly all aspects of your web page are accessible via the DOM, including the way it looks. Each element
node has a property called style. style is a deceptively substantial object that lets you change every aspect of an
element’s appearance, from the color of its text, to its line height, to the type of border that’s drawn around it.
For every CSS property that’s relevant to an element, style has an identical property that enables you to
change that property’s value. To change the text color of an element, we’d use style.color:
True or False
18.2 Summary
Document Object Model provides a way to access and alter the contents of HTML. You can find the element
by getElementsByTagName, getElementsByClassName, getElementById in JavaScript. You can also find
parent, child and sibling of element.
18.1
1. True
2. True
3. True
4. False
Chapter 19
JavaScript Events
19.0 Objectives
19.1 Introduction
19.2 Summary
19.0 Objectives
19.1 Introduction
Events are actions that the user performs while visiting your page. When the browser detects an event, such
as a mouse click or a key press, it can trigger JavaScript objects associated with that event, called event
handlers.
<input type= “button” value=”Click Me” onclick=”alert (‘You Clicked !’) “>
<p onmuseup= “alert (‘Mouse Up’) “>Click, Hold And Release </p>
</form>
</form>
Example:
Example:
True or False
1. The onunload event occurs once a page has resized.
2. The onmouseup event occurs when a user releases a mouse button over an element.
3. The onkeypress event occurs when the user presses a key
19.2 Summary
Events are actions that the user performs while visiting your page. There are four major types of events in
JavaScript – window event, mouse event, form event, keyboard event.
19.1
1. False
2. True
3. True
Chapter 20
JavaScript Events
20.0 Objectives
20.1 Introduction
20.3 Summary
20.0 Objectives
- what is jQuery
20.1 Introduction
jQuery is a fast, efficient, feature rich and most widely used JavaScript Library developed by John Resig in
2006 with a goal of writing less and doing more. jQuery makes a web developer's life easy. It provides many
built-in functions which simplifies DOM manipulation, event handling, web animation, and Ajax interactions
for rapid web development. jQuery is not a language but a JavaScript toolkit designed to simplify various
tasks by writing less code.
jQuery aims to make JavaScript coding easier and more productive. Here is a list of important jQuery
features:
• DOM Selection: jQuery provides selectors to select DOM elements based on element tag, id, class
name, attribute name, value, etc.
• DOM Manipulation: jQuery makes it easy to select DOM elements, modify their content.
• Event Handling: With the help of jQuery, you can capture a wide variety of events, such as clicking
on a link.
• Animation: jQuery has plenty of built-in animation effects such as show, hide, fade-in, fade-out etc.
• Cross Browser Support: jQuery automatically takes care of JavaScript related cross browser issues. It
works well in IE6+, FireFox2+, Safari 3+, Chrome and Opera 9+.
• AJAX: With jQuery, you can easily use AJAX functionality to load data from server without
reloading the whole page.
JQuery has been a blessing for web developers be it experienced and newbie. The use of JQuery has several
benefits which include:
• Easy to learn: This is the main advantage of using jQuery. It has coding syntax similar to JavaScript.
• Easy to use: One of the goals of jQuery is to make the difficult tasks in JavaScript simple. jQuery
requires less lines of code to achieve the same result as compared to pure JavaScript code.
• Small File Size: The minified version of jQuery is only 84kb in size, which may be smaller than
single photo on a website.
• Documentation and Community Support: jQuery website has extensive documentation and
tutorials to get started.
• Extensible: jQuery comes with plugin framework, which makes it easy to extend jQuery.
1. Download jQuery file: This is the most common method of using jQuery.
Example:
Note: The jQuery version used in this example is 3.3.1. Change the version name based on the latest version
you have downloaded.
2. Without downloading file: Another method is to reference a jQuery file in our HTML code directly
from Content Delivery Network (CDN) sites like Google, Microsoft, jQuery etc. Google hosts several
popular, open-source libraries on its CDN, including jQuery. So instead of hosting the jQuery file on our
own web server as we did in previous example, you can let google host the jQuery file.
Example:
Before we can interact with HTML elements on a page, we first need to make sure that those elements have
been loaded. $(document).ready is an event which fires up when document is ready. Whenever we use jQuery to
manipulate our web page, we must wait until the document ready event has fired. All the jQuery code should
be inside the document ready() method:
Example:
<script type=”text/javascript”>
$(document) . ready (function ( ) {
Document.wirte (“Hello World”);
});
</script>
jQuery Syntax
$ (selector) . action ( )
$ (“ p”) . hide ( );
$ (“.example”) .css(“background-color”,”red”);
20.1 Check Your Progress
True or False
Now that we are familiar with the basic jQuery syntax, let’s dive deep into selecting elements on the page. In
JavaScript, we used getElementById() and getElelementsByTagName() to select elements in a document.
Unfortunately, these two methods don’t provide us needed control to select elements. Fortunately, jQuery
has very powerful technique for selecting and working on the page elements with CSS selectors.
Selectors: To work with an element on the web page, first we need to find them. To find the html
element in jQuery we use selectors.
1. Selecting element by Tag Name: We can select all <p> tags with following code
$ (“p”)
2. Selecting element by ID: The jQuery #id selector uses the id attribute of an HTML tag to find the
specific element.
$ (“#header”)
3. Selecting element by class name: The jQuery class selector finds elements with a specific class.
Following code selects all elements with class name “entry-title”
$ (“.entry-title”)
$(“*”)
$ (“div, p, .entry-content”)
This will select all <div> tags, <p> tags and elements with class name “entry-content”
jQuery has powerful methods for manipulating HTML elements and attributes. Following are the 3 most
useful methods of jQuery for DOM manipulation:
text() method: The text() method sets and gets the text content of all the selected elements
Example:
html() method: The html() method sets and gets the html content of all the selected elements
Example:
html() method returns not just the content inside selected element but also other elements as well.
val() method: The val() method sets and gets the value of form field
Example:
The value of the input box is stored in the variable “inputValue” and then alert message displays it.
Add DOM Content: We can easily add or remove DOM element contents with jQuery.
Here are four jQuery methods that are used to add new content:
append(): With this method we can add content (inside) at the end of the selected elements
Example:
prepend():With this method we can add content (inside) at the beginning of the selected elements
Example:
$ (“ . content”) . prepend (add me at the start’);
after(): This method inserts content after (outside) the selected element
Example:
before(): As the name suggests, this method adds content before (outside) the selected element
Example:
$(".content").before('<p>add me before</p>');
Remove DOM Content: There are mainly two jQuery methods to remove elements and contents.
Example:
$ (“#container-one”) . remove ( );
empty() : With this method we can remove child elements of selected elements
Example:
$ (“#container-two”) . empty ( );
jQuery has many methods for CSS manipulation. Following four are the most important jQuery methods for
CSS manipulation.
addClass(): This method adds one or more classes to the selected elements
Example:
Example:
toggleClass(): With this method we can toggle between adding/removing classes from the selected
elements.
Example:
$ (“ . content-3”) . toggleClass (‘green’);
css(): We can set the style attributes for selected elements with this method
Example:
• Mouse Events: Here are some of the popular mouse events, click, dbclick, mouseenter and
mouseleave, hover
• Keyboard Events: Some of the important keyboard events are keypress, keydown and keyup
• Form Events: submit, change, focus, blur are important form events.
• Document/Window Events: Important document events includes load, ready, scroll
jQuery Event Syntax: The syntax for jQuery Event handling is pretty straightforward.
Example:
The click() method, attaches an event function to the selected html element (button in this case). The code
inside the function() gets executed only when the event happens, that is when the visitor clicks the button.
On happening of the button click event, all the <p> tags will hide. Here are some more examples of jQuery
event handling:
$ (“button”) . dbclick(function ( ){
$ (“p”) . hide ( );
});
Example:
True or False
1. The val() method sets and gets the value of form field
2. append() method adds content at the beginning of the element
20.3 Summary
jQuery is a JavaScript Library developed by John Resig in 2006. With jQuery you can easily select and modify
DOM elements, handle events, add animation effects. It is light weight and cross browser supported. jQuery
syntax consists of two parts, selector and action to be performed. Methods like text() val() and html() are used
to get and set content in HTML DOM. jQuery can also be used to style the elements.
20.1
1. True
20.2
1. True
2. False
Chapter 21
21.0 Objectives
21.1 Introduction
21.1.7 JSON
21.2 Summary
21.0 Objectives
21.1 Introduction
JavaScript development is changing quickly, especially over the past few years. Lot of action, changes, and
new initiatives in front-end web development happened in recent years.
JavaScript is a loosely typed (dynamic) scripting language. If you have worked with languages like Java or C#,
you must be familiar with the strictness of the language. For example, you expect the compiler to give an
error if you have used a variable before defining it. JavaScript allows similar strictness of the code using "use
strict" with ECMAScript 5 or later. You write "use strict" at the top of JavaScript code to activate strictness as
below.
“use strict”;
The strict mode in JavaScript does not allow you to do many things including: use of undefined variables, use
of reserved keywords, duplicate properties of an object, duplicate parameters of function, assign values to
read-only property etc.
Regular expressions are patterns applied to match character combinations in strings. You can imagine regular
expressions as wildcards. You may be most likely familiar with wildcard notations such as *.txt to find all text
files in a file manager. In JavaScript, regular expressions are also objects. They are a powerful tool for
inspecting and processing strings. Properly understanding regular expressions will make you a more powerful
programmer.
Object Oriented Programming (OOP) refers to using self-contained parts of code to develop applications.
These self-contained parts of code are called as objects or classes. Building applications with objects enables
us to implement some valuable techniques, namely, Inheritance, Polymorphism and Encapsulation. JavaScript
began with simple one-liners embedded in HTML, but is now used in much more complex ways. JavaScript
developers leverage the object-oriented nature of the language to build scalable code architectures composed
of reusable parts.
Ajax stands for Asynchronous JavaScript and XML. It is not a programming language or a tool, but a
concept. Ajax is a client-side script that communicates to and from a server/database without the need for a
complete page refresh. In simple words Ajax is “the method of exchanging data with a server, and updating
parts of a web page – without reloading the entire page.” Now a days, Ajax uses JSON instead of XML to
transmit data between browser and server.
Benefits of Ajax:
ECMAScript is the specification and JavaScript is based on it. By reading the ECMAScript specification, you
learn how to create a scripting language. By reading the JavaScript documentation, you learn how to use a
scripting language. ECMAScript 1, the first version of the JavaScript language standard, was released in June
1997. ECMAScript 6, the current version was released in 2015.
JavaScript is mainly a client side scripting language but with Node.js it can work as sever side language as well.
Node.js is a free open source server environment that runs on various platforms (Windows, Linux, Unix, Mac
OS X, etc.) and uses JavaScript on the server.
Node.js runs single-threaded, non-blocking, asynchronously programming, which is very memory efficient.
Node.js can generate dynamic page content. It can create, open, read, write, delete, and close files on the
server. It can also collect form data and add, delete, modify data in your database. You can build complete
web application with node.js
21.1.7 JSON
When exchanging data between a browser and a server, the data can only be text. JSON, or JavaScript Object
Notation, is a minimal, human readable format for structuring data. It is used primarily to transmit data
between a server and web application, as an alternative to XML. The two primary parts that make up JSON
are keys and values. Together they make a key/value pair.
Example:
“age" : “21”
A JavaScript framework is something from which you can build web application. A framework provides some
rules and guidelines. Using those rules and guidelines help you in building awesome web application rapidly.
• Efficiency: Projects that used to take months and thousands of lines of code now can be achieved
much faster with well-structured pre-built patterns and functions.
• Safety: Top JavaScript frameworks have firm security arrangements and are supported by large
communities where members and users also act as testers.
• Cost: Most frameworks are open source and free. Since they help programmers to build custom
solutions faster, the ultimate price for web application will be lower.
Some of the most popular JavaScript Frameworks are:
Angular.js
Angular.js it is one of the most beloved and used JavaScript frameworks for building single page applications.
It is available as an open source solution and is supported by Google. Angular JS is highly preferred for
hybrid mobile application development. Featured with components like overlays, sidebars, switches and
absolute positioned navigation bars, this framework incorporates dynamic functionality to the application.
React.js
React.js was created by the team of Facebook developers and came out in 2013. Being pretty new in
comparison with other JavaScript frameworks it confidently wins its niche. If you like the user interface of
Facebook and Instagram then you might like React.js too. This very framework is behind the front-end
scenes of the two social giants. There are other companies that benefit from using it: Atlassian, BBC,
Coursera, Dropbox, Flipboard, Netflix, Paypal, WhatsApp.
Vue.js
Introduced in 2016, Vue has a low learning curve. The framework delivers two-way data binding, server-side
rendering, Vue-CLI and optional JSX support. It is one the fastest emerging frameworks till date and is a
preferable choice for quick cross-platform solutions.
There are many other popular JavaScript Frameworks like Polymer, Aurelia.js, Embre.js and Backbone.js but
the above three are currently the most popular.
True or False
21.2 Summary
Although the core of JavaScript has remained the same, JavaScript has changed a lot in recent time. Now it
can be used as server side language. The ECMAScript 5 and later has introduced some new features like strict
mode in JavaScript. JSON has made life easier for developers. The most exciting thing happened to
JavaScript is emergence of numerous JavaScript Frameworks like Angular, React and Vue.
21.1
1. True
2. False
3. True
Chapter 22
22.0 Objectives
22.1 Introduction
22.2 Summary
22.0 Objectives
- what is version control system and some of the important concepts of git
- what is gulp
22.1 Introduction
A version control system is an application that allows you monitor the history and attribution of your project
files, and which helps the developers in the team to work together. Present day version control systems help
them work together, in a non-blocking way, by providing each developer his or her own sandbox, avoiding
their work in progress from conflicting, and all the while offering a mechanism to merge changes and
synchronize work.
Github:
GitHub.com is the leading code-hosting platform with virtually millions of open source projects having their
code hosted on it. In conjunction with Git, it supplies the means for a productive development workflow and
is the preferred git tool among developers.
The aim is to make the coding process simpler and more efficient. A CSS preprocessor is a scripting language
that extends CSS by allowing developers to write code in one language and then compile it into CSS. Sass is
perhaps the most popular preprocessor around, but other common alternatives are Less and Stylus.
• .scss (Sassy CSS): Uses the .scss file extension and is fully compliant with CSS syntax
• .sass: Uses .sass file extension and indentation rather than brackets; it is not fully compliant with
CSS syntax, but it's quicker to write
Important Concepts:
Variables:
Think of variables as a way to store information that you want to reuse throughout your stylesheet. You can
store things like colors, font stacks, or any CSS value you think you'll want to reuse.
Example:
$primary-color: #333;
body{
color: $primary-color;
Nesting:
SASS lets you nest your CSS selectors in a way that follows the same visual hierarchy that your HTML code
follows.
Example:
nav{
ul{
margin: 0;
padding: 0;
padding: 0;
list-style: none;
Import:
CSS has an import option that lets you split your CSS into smaller, more maintainable portions. The only
drawback is that each time you use @import in CSS it creates another HTTP request. Sass builds on top of
the current CSS @import but instead of requiring an HTTP request, Sass will take the file that you want to
import and combine it with the file you're importing into so you can serve a single CSS file to the web
browser.
Mixins:
Some things in CSS are a bit tedious to write, especially with CSS3 and the many vendor prefixes that exist. A
mixin lets you make groups of CSS declarations that you want to reuse throughout your site. You can even
pass in values to make your mixin more flexible. A good use of a mixin is for vendor prefixes. Here's an
example for border-radius.
Example:
@mixin my-border-radious($radius){
-webkit-border-radious: $radiou;
-moz-border-radious: $radious;
-ms-border-radius: $radius;
border-radius: $radius;
.box{
@include my-border-radious(10px);
True or False
1. Git is a version control system
2. Gulp solves the problem of repetition
3. SASS lets you use features that don't exist in CSS yet.
22.2 Summary
Although the core of JavaScript has remained the same, JavaScript has changed a lot in recent time. Now it
can be used as server side language. The ECMAScript 5 and later has introduced some new features like strict
mode in JavaScript. JSON has made life easier for developers. The most exciting thing happened to
JavaScript is emergence of numerous JavaScript Frameworks like Angular, React and Vue.
22.1
1. True
2. True
3. True
Questions Bank: Questions for Self Study
Chapter 1:
1. What is WWW?
2. Explain the term internet?
3. Differentiate between WWW and internet.
4. What is URL?
5. Write a short note on Operating System.
6. What is HTML?
7. Describe the three layers of Web.
8. Discuss two sided tags and one sided (empty) tags with example.
Chapter: 2
Chapter: 3
Chapter: 4
Chapter: 5
Chapter: 6
• What is CSS?
• Describe the 3 methods of adding CSS to HTML.
• Discuss different units of measurements.
• Differentiate between Block Level and Inline Level element.
Chapter: 7
Chapter: 8
Chapter: 9
Chapter: 10
Chapter: 11
Chapter: 12
Chapter: 13
• What is bootstrap?
• Explain the bootstrap grid system
• List out some text related bootstrap classes.
• List out image related bootstrap classes.
Chapter: 14
• What is JavaScript?
• Differentiate between Java and JavaScript.
• Write a short note on Client Server Architecture
• Describe how to add JavaScript to HTML.
Chapter: 15
• What is variable?
• List out various data types in JavaScript.
• Write a short note on concatenating string
• Differentiate between Null and Undefined
• Explain the term array
Chapter: 16
Chapter: 17
• What is a function?
• Discuss the concept passing data to function
• What is return statement?
• Write a short note on function scope.
Chapter: 18
• What is DOM?
• List out various methods of finding elements on page.
• Discuss finding parent element, children and sibling of element in JS
Chapter: 19
Chapter: 20
• What is jQuery? What can you do with it?
• Write short note on jQuery factory function and document.ready() method
• Discuss jQuery syntax
• List out 3 jQuery DOM manipulation methods
• Explain how jQuery can be used to style elements
• Discuss how jQuery handle events
Chapter: 21
Chapter 22:
HTML 5:
CSS:
Bootstrap:
JavasScript:
jQuery:
Git:
Gulp:
SASS: