UNIT-I Notes Web Programming
UNIT-I Notes Web Programming
Web Scripting
Client-Side Scripts :
1. Client-side scripting is responsible for interaction within a web page. The client-side scripts are
firstly downloaded at the client-end and then interpreted and executed by the browser (default
browser of the system).
2. The client-side scripting is browser-dependent. i.e., the client-side browser must be scripting
enables in order to run scripts
3. Client-side scripting is used when the client-side interaction is used. Some example uses of
client-side scripting may be :
To get the data from user’s screen or browser.
For playing online games.
Customizing the display of page in browser without reloading or reopening the page.
4. Here are some popular client-side scripting languages VBScript, JavaScript, Hypertext
Processor(PHP).
5. ient-side scripting languages run off the user’s browser.
6. It is usually performed at the front end, which makes it visible to visitors and makes it less
vulnerable to exploits and leaks. As such, it is often used to build user interfaces and lighter
functionality such as that.
7. Since it runs locally, they usually provide better performance and, therefore, do not strain your
server.
6. They are often used to create dynamic websites and platforms, handle user queries, and generate
and provide data and others. A famous example of server-side scripting is the use of PHP in
WordPress.
Script code is downloaded and executed at The script is executed at the server end, and the result is
the client end. sent to the client end.
Response to interaction is more immediate Complex processes are more efficient as the program
once the program code has been and associated resources are not downloaded to the
downloaded. browser.
Services are secure as they do not have Have access to files and databases, but have security
access to files or databases. considerations when sending sensitive information.
Influenced by the user's computer's Affected by the processing speed of the host server
processing speed
Introduction to Design Web Pages in HTML
HTML, known as HyperText Markup Language, is one of the most popular languages used for
designing web pages and structuring content. HTML uses tags, elements, images, and some latest
By combining HTML with CSS, the appearance of a web page can be easily customized. HTML
plays a crucial role in properly structuring web pages on the World Wide Web. It can be edited
using simple text editors, allowing users to make changes whenever needed.
Open a text editor like Notepad, Sublime Text, or Visual Studio Code in order to write your
HTML code.
Begin your HTML file by adding the <!DOCTYPE html> declaration at the top. This tells
Inside the HTML tags, create the opening and closing head tags: <head></head>.
Within the head tags, add the opening and closing title tags: <title></title>. This is where
is where you’ll put all the visible content of your web page.
Inside the body tags, you can start adding elements such as headings, paragraphs, images,
and links.
To add a heading, use the <h1></h1> tags for the main heading
To add an image, use the <img> Within the <img> tag, you need to specify the src attribute,
which should contain the file path or URL pointing to the location of the image file.
To add a link, use the <a></a> tags with the href attribute specifying the URL.
<!DOCTYPE html>
<html>
<head>
<title>My First Web Page</title>
</head>
<body>
<h1>Unlock the Power of Online Learning</h1>
<p>Master 1000+ Tools & Technologies.</p>
<img src="C:\Users\Demo2\Desktop\HTML\webimage.PNG">
<ul>
<li>Python</li>
<li>Artificial Intelligence</li>
<li>Java</li>
</ul>
<a href="https://www.educba.com">View All 1000 Skills</a>
</body>
</html>
You should see the below web page displayed in the browser, showing the content we
added.
Learn CSS (Cascading Style Sheets) to style your web page and make it visually appealing.
Experiment with more advanced HTML features like forms, tables, and multimedia
elements.
HTML is the building block for web pages. HTML is a format that tells a computer
how to display a web page. The documents themselves are plain text files with
special "tags" or codes that a web browser uses to interpret and display information
on your computer screen.
HTML Tags:- HTML tags are used to mark-up HTML elements .HTML tags are
surrounded by the two characters < and >. The surrounding characters are called
angle brackets. HTML tags normally come in pairs like and The first tag in a pair is
the start tag, the second tag is the end tag . The text between the start and end tags is
the element content . HTML tags are not case sensitive, <B>means the same as<b>.
The most important tags in HTML are tags that define headings, paragraphs and line breaks.
Tag Description
<!DOCTYPE...> This tag defines the document type and HTML version.
<html> This tag encloses the complete HTML document and mainly comprises of
document header which is represented by <head>...</head> and document
body which is represented by <body>...</body> tags.
<head> This tag represents the document's header which can keep other HTML tags
like <title>, <link> etc.
<title> The <title> tag is used inside the <head> tag to mention the document title.
<body> This tag represents the document's body which keeps other HTML tags like
<h1>, <div>, <p> etc.
<p> This tag represents a paragraph.
<h1> to <h6> Defines header 1 to header 6
Headings:-
Headings are defined with the <h1> to <h6> tags. <h1> defines the largest heading
while <h6> defines the smallest.
<h1>This is a heading</h1>
<h2>This is aheading</h2>
<h3>This is aheading</h3>
<h4>This is aheading</h4>
<h5>This is aheading</h5>
<h6>This is aheading</h6>
Paragraphs:-
Paragraphs are defined with the <p> tag. Think of a paragraph as a block of text. You can use the align attribute
with a paragraph tag as well.
<p align="left">This is a paragraph</p>
<p align="center">this is another paragraph</p>
Line Breaks:-
The <br> tag is used when you want to start a new line, but don't want to start a new paragraph. The <br> tag
forces a line break wherever you place it. It is similar to single spacing in a document.
This Code output
<p>This <br> is a para<br> graph with
Horizontal Rule The element is used for horizontal rules that act as dividers between sections like this:
The horizontal rule does not have a closing tag. It takes attributes such as align and width
Code Output
<hr width="50%" align="center">
Sample html program
<!DOCTYPE html>
<html>
<head>
<title>This is document title
</title>
</head>
<body>
<h1>This is a heading</h1>
<p>Document contentgoeshere </p>
</body>
</html>
•Type the above program in notepad and save with some file nameeg:sample.html
•Open the file with browser and the webpage looks likethis
Lists
HTML offers web authors three ways for specifying lists of information. All lists must contain one or more list
elements. Lists are of three types
HTML Ordered Lists:- items are numbered list instead of bulleted, This list is created by using
<!DOCTYPE html>
<html>
<head>
<title>HTML Ordered List</title>
</head>
<body>
<ol>
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
HTML Definition Lists:- HTML and XHTML supports a list style which is called definition lists where
entries are listed like in a dictionary or encyclopedia. The definition list is the ideal way to present a glossary,
list of terms, or other name/value list. Definition List makes use of following three tags.
HTML Tables:
The HTML tables allow web authors to arrange data like text, images, links, other tables, etc. into
rows and columns of cells. The HTML tables are created using the <table>tag inwhich the <tr>tag
is used to create table rows and <td>tag is used to create data cells.
Table Heading: Table heading can be defined using <th>tag. This tag will be put to replace <td>
tag, which is used to represent actual data cell. Normally you will put your top row as table heading as shown
below, otherwise you can use <th> element in any row.
Tables Backgrounds: set table background using one of the following two ways: 1)bgcolor attribute - You
can set background color for whole table or just for one cell.
background attribute - You can set background image for whole table or just for one cell. You can
also set border color also using border color attribute
<col> It is used with <colgroup> element to specify column properties for each
column.
<html>
<head>
<title>table</title>
<style>
table{
border-collapse: collapse;
width: 100%;
}
th,td{
border: 2px solid green;
padding: 15px;
}
</style>
</head>
<body>
<table>
<tr>
<th>1 header</th>
<th>1 header</th>
<th>1 header</th>
</tr>
<tr>
<td>1data</td>
<td>1data</td>
<td>1data</td>
</tr>
<tr>
<td>2 data</td>
<td>2 data</td>
<td>2 data</td>
</tr>
<tr>
<td>3 data</td>
<td>3 data</td>
<td>3 data</td>
</tr>
</table>
</body> </html>
HTML FORMS:
HTML Forms are required to collect some data from the site visitor. For example, during user registration
you would like to collect information such as name, email address, credit card, etc. A form will take input
from the site visitor and then will post it to a back-end application such as CGI, ASP Script or PHP script etc.
The back-end application will perform required processing on the passed data based on defined business
logic inside the application. There are various form elements available like text fields, text area fields, drop-
down menus, radio buttons, checkboxes, etc.
<form action="Script URL" method="GET|POST"> form elements like input, text area etc.
</form>
There are different types of form controls that you can use to collect data using HTML form:
Text InputControls
Checkboxes Controls
Radio BoxControls
Select BoxControls
File Selectboxes
Hidden Controls
ClickableButtons
Submit and ResetButton
Text Input Controls:-
There are three types of text input used on forms:
Single-line text input controls - This control is used for items that require only one line of user
input, such as search boxes or names. They are created usingHTML
<input>tag.
Example:
<form> Firstname:<br>
<input type="text"name="firstname"><br> Lastname:<br>
<input type="text" name="lastname">
</form>
Password input controls - This is also a single-line text input but it masks the character as soon as
a user enters it. They are also created using HTML <input>tag
<input type="password">defines a password field:
<form>
User name:<br>
</form>
Multi-line text input controls - This is used when the user is required to give details that may be
longer than a single sentence. Multi-line input controls are created using HTML
<textarea> tag.
<html>
<head>
<title>Multiple-Line Input Control</title>
</head>
<body>
<form> Description: <br />
<textarea rows="5" cols="50" name="description"> Enter description here... </textarea>
</form>
</body>
</html>
Checkboxes Controls:-
Checkboxes are used when more than one option is required to be selected. They are
also created using HTML <input> tag but type attribute is set to checkbox.
Here is an example HTML code for a form with two checkboxes:
<html><head><title>Checkbox Control</title></head>
<body>
<form>
<input type="checkbox" name="C++" value="on"> C++
<br>
<input type="checkbox" name="C#" value="on"> C#
<br>
<input type="checkbox" name="JAVA" value="on"> JAVA
</form>
</body>
</html>
created using HTML <input> tag but type attribute is set toradio
</form> </body></html>
Select Box Controls :- A select box, also called drop down box which provides option to list down various
options in the form of drop down list, from where a user can select one or more options.
<html>
<head>
<title>Select Box Control</title>
</head>
<body>
<form>
<select name="dropdown">
<option value="JAVA">JAVA</option>
<option value="HTML">HTML</option>
</select></form>
</body></html>
File Select boxes:- If you want to allow a user to upload a file to your web site, you will need to use a file
upload box, also known as a file select box. This is also created using the <input> element but type attribute
is set to file.
<form>
<p>This is page 10</p>
<input type="hidden" name="pagename" value="10" />
<input type="submit" name="submit" value="Submit" />
<input type="reset" name="reset" value="Reset" />
</form> </body> </html>
Button Controls:-
There are various ways in HTML to create clickable buttons. You can also create a clickable
button using <input> tag by setting its type attribute to button. The type attribute can take the
following values:
<DOCTYPE html>
<html>
<head>
<title>File Upload Box</title>
</head>
<body>
<form>
<input type="submit" name="submit" value="Submit" />
<input type="reset" name="reset" value="Reset" />
<input type="button" name="ok" value="OK" />
<input type="image" name="imagebutton" src="test1.png" />
</form>
</body></html>
HTML frames:
These are used to divide your browser window into multiple sections where each section can load a separate
HTML document. A collection of frames in the browser window is known as a frameset. The window is
divided into frames in a similar way the tables areorganized: into rows andcolumns.To use frames on a page
we use <frameset> tag instead of <body> tag. The <frameset> tag defines, how to divide the window into
frames. The rows attribute of <frameset> tag defineszontal frames and cols attribute defines vertical frames.
Each frame is indicated by <frame> tag
<html>
<head>
<title>Page Title</title>
</head>
<body>
<iframe src="sample1.html" height="400" width="400"frameborder="1">
<h1>This is aHeading</h1>
<p>This is aparagraph.</p>
</iframe>
</body>
</html>
Example 2
<html>
<head>
<title>Example of HTML Frames Using col Attribute</title>
</head>
<frameset cols = "30%, 40%, 30%">
<frame name = "top" src =
"C:/Users/dharam/Desktop/attr1.png" />
<frame name = "main" src =
"C:/Users/dharam/Desktop/gradient3.png" />
<frame name = "bottom" src =
"C:/Users/dharam/Desktop/col_last.png" />
<noframes>
<body>The browser you are working does
not support frames.</body>
</noframes>
</frameset>
</html>
JavaScript:
Javascript is a lightweight programming language commonly used by web developers to
add dynamic interactions to web pages, applications, servers, and even games.
Today, JavaScript has plenty of frameworks and libraries to simplify complex projects,
such as AngularJS, jQuery, and ReactJS.
JavaScripts enclosed in <script>...</script> runs during loading of the page. Some
JavaScripts, called event handlers, run as a result of the user's or browser's action (or event). For
example, clicking a button (onclick) or loaded a page (onload).
There are, therefore, two places to put your JavaScript:
between <script> and </script> container tags;
and inside the HTML tags as the event handlers (such as onclick, onmouseover, onload),
e.g.,
onclick="JavaScriptStatements".
Java Script is one popular scripting language over internet. Scripting means a small sneak
(piece). It is always independent on otherlanguages.
JavaScript is most commonly used as a client side scripting language. This means that
JavaScript code is written into an HTML page. When a user requests an HTML page with JavaScript
in it, the script is sent to the browser and it's up to the browser to do something with it.
Difference between JavaScript and Java
JavaScript Java
Cannot live outside a Web page Can build stand-alone applications or live in a Web
page as an applet.
Doesn‘t need a compiler Requires a compiler
Knows all about your page Applets are dimly aware of your Web page.
Untyped Strongly typed
Somewhat object-oriented Object-oriented
There are no relationship between in java & java script. Java Script is a scripting language
that always dependent in HTML language. It used to css commands. It is mainly used to creating
DHTML pages & validating the data. This is called client side validations.
Comments
Comments are ignored by the JavaScript runtime but greatly useful in explaining your codes
to others (and also to yourself three days later). You should use comments liberally to explain or
document your codes.
An end-of-line comment begins with // and lasts till the end of the current line. A multi-line
comment begins with /* and lasts till */.
Take note that:
HTML comments are enclosed inside <!-- ... -->.
CSS supports multi-line comment /* ... */, but NOT end-of-line comment //.
JavaScript supports both /* ... */ and //, like Java/C/C++/C#.
Features of JavaScript
1. JavaScript is a client side technology, it is mainly used for gives client side validation, but it have lot
of features which are given below;
2. Java script is object based oriented language.
3. Inheritance is does not support in JavaScript, so it is called object based oriented language.
4. JavaScript was developed by Netscape (company name) & initially called live script. Later
Microsoft developed & adds some features live script then it is called “Jscript”. Jscript is nothing
but Java script. We cannot create own classes in java script.
5. Java script is designed to add interactivity to HTML pages. It is usually embedded directly
into html pages.
6. Java script is mainly useful to improve designs of WebPages, validate form data at client side,
detects (find) visitor‘s browsers, create and use to cookies, and much more.
7. Java script is also called light weight programming language, because Java script is return
with very simple syntax. Java script is containing executable code.
8. Java script is also called interpreted language, because script code can be executed without
preliminary compilation.
9. It Handling dates, time, onSubmit, onLoad, onClick, onMouseOver & etc.
10. JavaScript is case sensitive.
11. Most of the javascript control statements syntax is same as syntax of controlstatements in C
language.
12. An important part of JavaScript is the ability to create new functions within scripts.
13. Declare a function in JavaScript using function keyword.
Creating a java script: - html script tag is used to script code inside the html page.
<script> </script>
1) Language attribute:-
<script language=―JavaScript‖>
Type attribute: - It indicates MIME (multi purpose internet mail extension) type of scripting code.
It sets to an alpha-numeric MIME type of code.
<html> <html>
<head> <head>
<script type=―text/JavaScript‖>
</head>
Scriptcodehere
<body>
</script> <script type= ―text /JavaScript‖>
</head> Script codehere
<body> </script>
</body> </body>
</html> </html>
Scripting in both head & body section: - we can create unlimited number of scripts inside the
same page. So we can locate multiple scripts in both head & body section of page.
Ex: - <html>
<head>
<script type=―text / JavaScript‖>
Script code here
Program: -
<html>
<head>
<script language="JavaScript">
document.write("hai my name is yz")
</script>
</head>
<body text="red">
<marquee>
<script language="JavaScript">
Ex: -
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional // EN">
<HTML>
<HEAD>
<script
language="JavaScri
pt"> function myf(
)
{
document.write("Hai Kalpana")
}
</script>
</HEAD>
<BODY>
to execute script code:
<input type="button" value="click me" onclick="myf( )"> To execute script code:
<input type="button" value="touch me" onmouseover="myf( )">
</BODY>
</HTML>
JavaScript functions: - in java script functions are created with the keyword
‗function‘ as shownbelow
--------
}
Generally we can place script containing function head section of web page. There
are 2 ways to call the function.
1) direct callfunction
2) Events handlers to call the functiondynamically.
We can pass data to function as argument but that data will be available inside
the function.
Ex: -
<HTML>
<HEAD>
<TITLE> Function direct call</TITLE>
<script language="JavaScript">
function add(x,y)
{
z=x+y return z
}
</script>
</HEAD>
<BODY>
<script>
var r=add(30,60) document.write("addition is :"+r);
</script>
</BODY>
</HTML>
Objects
An object in JavaScript is a data type that is composed of a collection of names or keys and values,
represented in name:value pairs. The name:value pairs can consist of properties that may contain
any data type — including strings, numbers, and Booleans — as well as methods, which are
functions contained within an object.
Objects in JavaScript are standalone entities that can be likened to objects in real life. For example,
a book might be an object which you would describe by the title, author, number of pages, and
genre. Similarly, a car might be an object that you would describe by the color, make, model, and
horsepower. JavaScript arrays are also a type of object.
Objects are an integral and foundational aspect of most JavaScript programs. For example, a user
account object may contain such data as usernames, passwords, and e-mail addresses. Another
common use case is a web shopping platform’s shopping cart that could consist of an array of many
objects containing all the pertinent information for each item, such as name, price, and weight for
shipping information. A to-do list is another common application that might consist of objects.
In this tutorial, we will review how to create an object, what object properties and methods are, and
how to access, add, delete, modify, and loop through object properties.
Creating an Object
An object is a JavaScript data type, just as a number or a string is also a data type. As a data type, an
object can be contained in a variable.
Both of these approaches will create an empty object. Using object literals is the more common and
preferred method, as it has less potential for inconsistencies and unexpected results.
We can create an example object, contained in the variable gimli, to describe a character.
// Initialize gimli object
const gimli = {
name: "Gimli",
race: "dwarf",
weapon: "axe",
greet: function() {
return `Hi, my name is ${this.name}!`;
},
};
Our new object is gimli, which has three properties. Each property consists of a name:value pair,
also known as key:value pair. weapon is one of the property names, which is linked to the property
value "axe", a string. It has one method, with a method name of greet and the method value
consisting of the contents of the function.
Within greet, you may notice the this keyword. When using this inside of an object, it refers to the
current object, in this case gimli.
Sending gimli to the console will print out the entire object.
gimli;
Output
{name: "Gimli", race: "dwarf", weapon: "axe", greet: ƒ}
This output may render differently depending on what console you are using, but you should notice
that all of the values passed to the object are shown in the output.
A property is the association between a name (key) and value within an object, and it can contain
any datatype. A property generally refers to the characteristic of an object.
A method is a function that is the value of an object property, and therefore a task that an object can
perform.
An easy way to remember the difference between object properties and methods is to think of a
property as a noun, and a method as a verb. name, race and weapon are all nouns associated with an
object, and are properties. fight() or talk() are verbs that might be used as a method function
definition.
Dot notation: .
Bracket notation: []
Let’s revisit our original example object, gimli.
const gimli = {
name: "Gimli",
race: "dwarf",
weapon: "axe",
greet: function() {
return `Hi, my name is ${this.name}!`;
},
};
If we want to retrieve the property value of weapon, we can do so with object dot notation by typing
the variable name of the object, followed by a dot (.) and the property or method name.
A JavaScript Literal can be a numeric, string, floating-point value, a boolean value or even an object.
In simple words, any value is literal
Numeric Literal
Floating-Point Literal
Boolean Literal
String Literal
Array Literal
Regular Expression Literal
Object Literal
Character Description
\b
It represents a backspace.
\f It represents a Form Feed.
\n It represents a new line.
\r It represents a carriage return.
\t It represents a tab.
\v It represents a vertical tab.
\' It represents an apostrophe or single quote.
\" It represents a double quote.
\\ It represents a backslash character.
\u It represents a Unicode character specified by a four-digit hexadecimal number.
JavaScript Array Literal
An array literal is a list of zero or more expressions representing array elements that are enclosed in
a square bracket([]).
Whenever you create an array using an array literal, it is initialized with the elements specified in
the square bracket.
JavaScript Array Literal Example
var emp = ["aman","anu","charita"]; // Array literal
Keyword ` Description
for The for keyword is used to create a for-loop.
do/while The do and while both keywords are used to create loops in JavaScript.
if/else The if and else keywords are used to create conditional statements.
continue The continue keyword is used to resume the loop.
break It is used to break the loop.
Function The function keyword is used to declare a function.
debugger It is used to call the debugger function
class The class keyword is used to declare the class.
Return Return keyword is used to return function from the function.
Float It is used to declare float type variable.
int It is used to declare int type variable.
private It is an access modifier.
public Public is an access modifier that gives the class public access.
var Var is used to declare a variable.
switch The switch creates various statement blocks and executes only on block
depending on the condition or the case.
try/catch It creates a block for error handling of the statements.
JavaScript Data Types
JavaScript Data types are used to identify the type of data that is stored inside a variable during the
script execution. As we have already specified about the Dynamic Typed JavaScript feature so we
do not have to specify the data type of the variable while declaring it.
So JavaScript data types are basically for identification purposes to know what is being stored in the
variable, when it's stored, not before that.
Dynamically typed language is a language that infers data types at runtime. It allows storing
different types of values to a variable during programming.
Below we have a basic example, where we have defined a variable with a numeric value and then
updated it to store a string value. So JavaScript allows this.
var x = 5; // x is a number
x = "studytonight"; // x is string here.
JavaScript broadly supports three types of Data types, they are:
Primitive Type
Reference Type
Special Data Type
Let's cover each one of this one by one while seeing which category has all data types.
These are the most common data types, used for storing sequences of characters, true/false and
numeric values respectively. Let's cover them one by one with examples.
var a = 100;
var b = -100;
var c = 0;
alert(a/c); // Infinity
alert(b/c); // -Infinity
And Nan means Not a number, if we try to perform any operation between a numeric value and a
non-numeric value like a string we will get this as output.
var a = "Studytonight";
var b = 7;
alert(a/b); // Nan
JavaScript Composite Data types
These data types can hold collections of values and more complex entities. It is further divided into
Object, Array and Function.
Object data type
Array data type
Function data type
The key (name) must always be a string, but the value can be of any data type. This is pretty similar
to a map data structure in many programming languages which also stores key-value pairs like this.
Each element in the array gets a numeric position, known as its index. The array index starts from 0
or we can say that array indexes are zero-based, so that the first array element is arr[0] and not
arr[1].
// Creating an Array
var cars = ["Ferrari", "Volvo", "BMW", "Maseratti"];
We have covered JavaScript Arrays in a separate tutorial with examples.
Functions can be stored in variables, objects, and arrays. Functions can be passed as arguments to
other functions too and can be returned from other functions as well.
We can even use this value while doing some comparison. Let's take an example:
var a; // Undefined
The Null data type can have only one value, which is null. Let's take an example for this:
var a = null;
// Function datatype
var welcome = function() {
return "Welcome to StudyTonight!";
}
var a = null;
typeOf a; // null
// Array datatype
var cars = ["Ferrari", "Volvo", "BMW", "Maseratti"];
What is an Operator?
An operator is a symbol that is reserved for special tasks or operations. Operators are used to
performing operations on the operands. The operands can be variables or numeric literals or string
Operators are useful to modify or change data by manipulating the respective variables. For
example, there are two variables a and b and we want to add the values of both of these variables,
to do so we can use arithmetic operator + to perform addition of these two variables.
JavaScript supports a rich set of operators. These operators perform a specific task and every
operator has different properties. The list of operators is given below:
Arithmetic Operators
Relational Operators
Bitwise Operators
Logical Operators
Assignment Operators
String Operators
Let's cover each one of the above-mentioned operator types one by one and see the different
operators that are supported in JavaScript.
0101&0001 // returns 1
| (OR) Sets each bit to 1 if one of two bits are 1 5|1 // returns 5
0101^0001 // returns 4 in
decimal or 64 in octal
~ (NOT) inverts all the bits ~5 // output 6
Conditional Operator
Operat
Description Example
or
Conditional Statements
This is where we decide the flow of a program's execution. Based on the outcome, Conditional Statements
determine the next step. The outcome of a conditional assertion can be True, or it can be false. If the
condition comes out to be true, the programme goes to the next step. On the other hand, if the condition
comes out to be false, the programme goes out to a different. Unlike Loop statements, these statements
get executed only once.
Below we can see the different types of Conditional Statements.
If Statment
As the name suggests, we use the If Statement if we want to check for a specific condition. When we are
using the IF condition, the inner code block gets executed only when the given condition is satisfied.
Syntax:
if (condition_is_given_here) {
// If the condition is met, the code block will get executed.
}
If-Else Statement
The If-Else Statement is an extended version of the If statement. We use this one when we want to check a
condition we want and another one if the evaluation turns out otherwise.
Syntax:
if (condition_is_given_here) {
// If the condition is met, this code block will get executed.
}
else {
/*If the condition is not met and turns out to be false, this code block will get executed. */
}
As we can see, the first block of code gets executed when the condition in IF-ELSE is satisfied. The second
block of code gets executed when the condition does not get satisfied.
Switch Statement
A switch statement is similar to an IF statement. It is used when the user needs to execute one code block
execution from their own choices out of several code block execution options. It is based on the outcome of
the expression given. Switch statements hold an expression that is compared to the values of the following
cases. If a match is found, the code associated with that case is executed.
Syntax:
switch (expression) {
case first:
// Here, we add the code block that is to be executed
Break;
// Break creates a separation between each case
case second:
// Here, we add the code block that is to be executed
Break;
case third:
// Here, we add the code block that is to be executed
Break;
default:
// Here, we add the default code block that is to be executed. It happens if none of the above cases is
executed.
}
At the beginning of the code, an expression gets checked and compared with the cases given. If the given
expression matches the first case, the code block present within the case gets executed. The same is true
for the second case and the third case. However, when the expression passed matches none of the cases
given, the code enters the default case and executes the code that is under the default case.
Iterative Statement
Looping is a strong feature in any programming language. This is for repeatedly executing a sequence of
instructions while the expression passed is met. A simple example would be to print "Hello Ninjas" ten
times. Now, typing the same print statement with "Hello Ninjas" ten times in a row will take time. As an
influence, it will also affect the execution time. This is the place where looping comes to play.
We should know that iterative statements are divided into three types: WHILE, DO-WHILE, and FOR. Let's
break each down with syntax and take a look at them.
While Statement
One of the control flow statements is the. When the condition is met, they run a code block. However,
unlike the IF statement, while keeps repeating itself until the condition is met. The difference between IF
and while is that IF executes code when the condition is met. Whereas while statement keeps repeating
itself till the condition is met.
Syntax:
while (the_condition_is_put_here)
{
// The code block is executed when the conditions are met
}
Do-While Statement
We can call the Do-While Statement a sibling of the While Statement. Similar to a while loop, but with the
addition of a condition at the end of the loop. DO-WHILE, also known as an Exit Control Loop, performs the
code and then checks for the condition.
Syntax:
while
{
// Code block gets executed till the condition is satisfied
} (we_add_the_conditon_here)
The loop will get repeated if the condition at the end is met.
For Statement
Now let us take a look at the For Loop. A for loop will run a code block several times. The FOR statement is
shorter and easier to debug than other loops. This is because it contains initialization, condition, and
increment or decrement on a single line.
Syntax:
The loop is started using initialize. It uses a declared variable. The exit condition for the loop then gets
tested in the condition section. The code block inside is run when this condition returns true.
JavaScript Events
JavaScript Events are the building blocks of an interactive webpage. In JavaScript, events refer
to the actions that are detected by a web browser whenever it detects any user movement on the
browser screen. So everything starting from the movement of the mouse, keyboard click, hover over
any particular HTML element, form submission, click on any input field, selection of a value from a
dropdown, and everything else you do on a webpage, the browser generates an event for it which
can be handled using JavaScript.
JavaScript enables us to write scripts to be executed when any of these events occur. For example,
the onclick event is detected by the browser whenever you click the mouse button and using
JavaScript we can perform any action on mouse click
Several mouse events are available in JavaScript that can be used to react to user
interaction with a web page. The following are a few of the most typical mouse events :
Mouse Description
event
click When the mouse button is clicked (pressed and released) on an element, this event is
triggered.
mouseover When the mouse pointer enters an element, the mouseover event is triggered.
mouseout This event is triggered when the mouse pointer leaves an element.
mousedown When the mouse button is pressed down on an element, this event is triggered.
mouseup Fires when the mouse button on an element is released.
mousemove This event is triggered when the mouse pointer moves over an element.
There are several keyboard events in JavaScript that you can use to detect when a user
interacts with the keyboard on a web page. The following table lists and describes the
keyboard events in JavaScript:
Keyboard Description
event
keydown When a key on the keyboard is pressed, this event occurs. You can use it to determine which
key was pressed by accessing the event object's "keyCode" or "which" property.
keyup When a key on the keyboard is released, this event occurs. You can use it to determine which
key was released by accessing the event object's "keyCode" or "which" property.
keypress When a key on the keyboard is pressed and a character is generated, this event is triggered.
You can use it to determine which character was generated by accessing the event object's
"keyCode" or "charCode" property.
input Typing or pasting text in an input field triggers this event. It detects text entered into input
fields.
Several events in JavaScript can be used to monitor changes and interactions with HTML
forms. The following table lists and describes the form events in JavaScript:
Form Description
event
submit When a form is submitted, either by clicking the submit button or by pressing the Enter key
while a form element is in focus, this event is started.
reset When a user clicks the Reset button on a form, this event is started.
input When the value of a form input field changes, as happens when a user types into a text input
or chooses an option in a select element, this event is triggered.
change When a form element's value changes and it loses focus, such as when a user selects a new
option in a select element or unchecks a checkbox, this event is triggered.
focus When an element receives focus, such as when a user clicks on a form element or uses the
keyboard to move to it, this event is triggered.
blur When an element loses focus, such as when a user clicks outside of a form element or uses
the keyboard to navigate away from it, this event is launched.
JavaScript window events
Window Description
event
load This event is triggered when the window's entire content, including images, scripts, and
stylesheets, has been loaded.
resize When the size of the window changes, either by resizing the browser window or switching
between portrait and landscape modes on a mobile device, this event occurs.
scroll This event occurs when the user scrolls the window's content using the scrollbar or touch
gestures.
unload This event occurs just before the window is closed or navigated away from, giving you the
opportunity to perform cleanup tasks or prompt the user to confirm their action.
beforeunload This event occurs before the unload event, allowing you to prompt the user to confirm their
action or prevent the window from closing.
error This event is triggered when an error occurs while the window or its content is being loaded,
such as a missing image or a syntax error in a script.
<body>
<p>Click the following button and see result</p>
<form>
<input type = "button" onclick = "sayHello()" value = "Say
Hello" />
</form>
</body>
</html>
<body>
<p>Bring your mouse inside the division to see the
result:</p>
<div onmouseover = "over()" onmouseout = "out()">
<h2> This is inside the division </h2>
</div>
</body>
</html>
Onclick Event
<html>
<head>
<script type = "text/JavaScript"
function submit() {
alert("click performed")
}
</script>
</head>
<body>
<form>
<input type = "button" onclick = "submit()" value = "click performed" />
</form>
</body>
</html>
If the user clicks "OK", the box returns true. If the user clicks "Cancel", the box returns false.
Syntax
window.confirm("sometext");
The window.confirm() method can be written without the window prefix.
Example
if (confirm("Press a button!")) {
txt = "You pressed OK!";
} else {
txt = "You pressed Cancel!";
}
Prompt Box
A prompt box is often used if you want the user to input a value before entering a page.
When a prompt box pops up, the user will have to click either "OK" or "Cancel" to proceed after
entering an input value.
If the user clicks "OK" the box returns the input value. If the user clicks "Cancel" the box returns
null.
Syntax
window.prompt("sometext","defaultText");
The window.prompt() method can be written without the window prefix.
Example
let person = prompt("Please enter your name", "Harry Potter");
let text;
if (person == null || person == "") {
text = "User cancelled the prompt.";
} else {
text = "Hello " + person + "! How are you today?";
}
Javascript Window
The Window object represents the browser window. It is the topmost object in the browser's
window hierarchy. It is supported by all browsers.
The window object represents the frame or window in which the webpage is contained in the
browser. It is a Global object, its properties and functions can be accessed without referring
to it.
Example: window.alert() is used to alert something but we can directly use alert() without
referring to the window object.
The window is the root object, even the document is the property of the window object. You can
use it to find out screen height, screen width, history, localStorage, location, events, etc.
Everything that is visible and non-visible on a webpage all are part of the windowcrip
window.alert("Page Loaded!");
alert("Page Loaded!");
// Both are the same
window.console.log("Hello World!");
console.log("Hello World!");
Window Properties
The window object has lots of properties that can be used to get information about the window.
Some of the most commonly used properties are listed below.
Property Description
window.screenX Returns the horizontal coordinate of the window relative to the screen.
window.screenY Returns the vertical coordinate of the window relative to the screen.
window.screenLeft Returns the horizontal coordinate of the window relative to the screen.
window.screenTop Returns the vertical coordinate of the window relative to the screen.
window.screen.availHeigh Returns the height of the screen in pixels, fewer interface features like the
t Windows Taskbar.
window.screen.availWidth Returns the width of the screen in pixels, fewer interface features like the
Windows Taskbar.
window.screen.colorDepth Returns the color depth of the screen in bits per pixel.
window.screen.pixelDepth Returns the color depth of the screen in bits per pixel.
window.location Returns the Location object for the window that contains information about the
URL of the document and provides methods for changing that URL and loading
another URL.
window.history Returns the History object for the window that contains information about the
URLs visited in the window.
window.navigator Returns the Navigator object for the window that contains information about the
browser.
window.performance Returns the Performance object for the window that contains information about
the performance of the window.
window.localStorage Returns the Storage object for the window that contains information about the
local storage of the window.
window.sessionStorage Returns the Storage object for the window that contains information about the
session storage of the window.
window.document Returns the Document object for the window that contains information about the
document loaded in the window.
window.frames Returns the array of all the frames (iframes) in the window.
Window Methods
The window object has lots of methods that can be used to perform different tasks. Some of
the most commonly used methods are listed below.
Method Description
window.confirm() Displays a dialog box with a message and an OK and a Cancel button.
window.prompt() Displays a dialog box that prompts the visitor for input.
window.moveTo() Moves the window relative to the upper-left corner of the screen.
Window Events
The window object has lots of events that are triggered when a specific action is performed.
Some of the most commonly used events are listed below
Event Description
</body>
</html>
The document object stores the elements of an HTML document, such as HTML, HEAD, BODY, and
other HTML tags as objects.
Properties Description
cookie returns a report that contains all the visible and unexpired cookies associated with
the document
domain returns the domain name of the server from which the document has originated
title returns the name of the HTML document defined between the starting and ending
tags of the TITLE element
Now let's take an example, to see the document object methods like open(), write(),
and getElementById() to explain their usage. See the below example:
<!doctype html>
<head>
<title>JS Document Methods Example</title>
</head>
<body>
<h3>Document Methods Example</h3>
<p id="demo">It Will change</p>
<script>
// Open document
document.open();
// writing
document.write("Hello" +"<br>");
document.getElementById("demo").innerHTML = "Set by ID";
</script>
</body>
</html>
There is so much that you can do using these WebAPIs and Interfaces. All the supported Web APIs
and Interfaces in JavaScript are listed on the Mozilla Developer website.
The Iterfaces (object types) which help us interact with the browser window are known
as Browser objects. Browser object is not an official term but its a group of objects which belongs
to different WebAPIs but are used for managing various browser related information and actions.
For example, when an HTML document is opened in a browser window, the browser interprets the
document as a collection of hierarchical objects(HTML tags) and accordingly displays the data
contained in these objects(HTML page rendering). The browser parses the document and creates a
collection of objects, which defines the documents and its details. We have shown the various
objects that can be used to access various components of the browser window in the picture below:
The browser objects are of various types, used for interacting with the browser and belongs to
different APIs. The collection of these Browser objects is also known as Browser object
Model(BOM).
The default object of browser is Window which means you can call its functions directly.
Browser Objects:
Navigator
It is used to interact with the browser window which displays the web page. It generally represents
a tab in browser, but some actions like window width and height will affect the complete browser
window.
Navigator Object
It acts as a storehouse of all the data and information about the Browser software used to access
the webpage and this object is used to fetch information related to the browser for example,
whether the user is using Chrome browser or Safari browser, which version of browser is being used
etc.
Document Object
This object represent the HTML document that is loaded into the browser. A document object is
an object that provides access to all HTML elements of a document(webpage). We can use this
object to append a new HTML tag to the webpage, modify any exsiting HTML tag, etc.
History Object
It stores Uniform Resource Locator(URLs) visited by a user in the browser. It is a built-in object
which is used to get browser history. This object is a property of the JavaScript Window object.
Screen Object
It is a built-in object which is used to fetch information related to the browser screen, like the
screen size, etc. It is also obtained from the Window object.
Location Object
Location is a built-in object which represent the location of the object to which it is linked,
which can be Window or Document. Both the Document and Window interface have a linked
location property.
The Number object contains only the default methods that are part of
every object's definition.
1 constructor()
Returns the function that created this object's instance. By default this is the Number
object.
2 toExponential()
Forces a number to display in exponential notation, even if the number is in the range in
which JavaScript normally uses standard notation.
3 toFixed()
Formats a number with a specific number of digits to the right of the decimal.
4 toLocaleString()
Returns a string value version of the current number in a format that may vary according
to a browser's locale settings.
5 toPrecision()
Defines how many total digits (including digits to the left and right of the decimal) to
display of a number.
6 toString()
7 valueOf()
1 toSource()
Returns a string containing the source of the Boolean object; you can
use this string to create an equivalent object.
2 toString()
3 valueOf()
String Methods
1 charAt()
2 charCodeAt()
Returns a number indicating the Unicode value of the character at the given index.
3 concat()
4 indexOf()
Returns the index within the calling String object of the first occurrence of the specified
value, or -1 if not found.
5 lastIndexOf()
Returns the index within the calling String object of the last occurrence of the specified
value, or -1 if not found.
6 localeCompare()
Returns a number indicating whether a reference string comes before or after or is the
same as the given string in sort order.
7 length()
8 match()
9 replace()
Used to find a match between a regular expression and a string, and to replace the
matched substring with a new substring.
10 search()
Executes the search for a match between a regular expression and a specified string.
11 slice()
12 split()
Splits a String object into an array of strings by separating the string into substrings.
13 substr()
Returns the characters in a string beginning at the specified location through the
specified number of characters.
14 substring()
Returns the characters in a string between two indexes into the string.
15 toLocaleLowerCase()
The characters within a string are converted to lower case while respecting the current
locale.
16 toLocaleUpperCase()
The characters within a string are converted to upper case while respecting the current
locale.
17 toLowerCase()
18 toString()
19 toUpperCase()
20 valueOf()
1 anchor()
2 big()
3 blink()
4 bold()
6 fontcolor()
7 fontsize()
8 italics()
9 link()
10 small()
11 strike()
12 sub()
13 sup()
Array Methods
1 concat()
2 every()
3 filter()
Creates a new array with all of the elements of this array for
which the provided filtering function returns true.
4 forEach()
5 indexOf()
6 join()
7 lastIndexOf()
8 map()
9 pop()
10 push()
Adds one or more elements to the end of an array and returns
the new length of the array.
11 reduce()
12 reduceRight()
13 reverse()
14 shift()
15 slice()
16 some()
17 toSource()
18 sort()
19 splice()
20 toString()
Returns a string representing the array and its elements.
21 unshift()
Date Methods
1 Date()
2 getDate()
Returns the day of the month for the specified date according to local time.
3 getDay()
Returns the day of the week for the specified date according to local time.
4 getFullYear()
5 getHours()
6 getMilliseconds()
7 getMinutes()
8 getMonth()
9 getSeconds()
Returns the seconds in the specified date according to local time.
10 getTime()
Returns the numeric value of the specified date as the number of milliseconds since January
1, 1970, 00:00:00 UTC.
11 getTimezoneOffset()
12 getUTCDate()
Returns the day (date) of the month in the specified date according to universal time.
13 getUTCDay()
Returns the day of the week in the specified date according to universal time.
14 getUTCFullYear()
15 getUTCHours()
16 getUTCMilliseconds()
17 getUTCMinutes()
18 getUTCMonth()
19 getUTCSeconds()
20 getYear()
Deprecated - Returns the year in the specified date according to local time. Use
getFullYear instead.
21 setDate()
Sets the day of the month for a specified date according to local time.
22 setFullYear()
Sets the full year for a specified date according to local time.
23 setHours()
24 setMilliseconds()
25 setMinutes()
26 setMonth()
27 setSeconds()
28 setTime()
Sets the Date object to the time represented by a number of milliseconds since January 1,
1970, 00:00:00 UTC.
29 setUTCDate()
Sets the day of the month for a specified date according to universal time.
30 setUTCFullYear()
Sets the full year for a specified date according to universal time.
31 setUTCHours()
32 setUTCMilliseconds()
Sets the milliseconds for a specified date according to universal time.
33 setUTCMinutes()
34 setUTCMonth()
35 setUTCSeconds()
36 setYear()
Deprecated - Sets the year for a specified date according to local time. Use setFullYear
instead.
37 toDateString()
38 toGMTString()
Deprecated - Converts a date to a string, using the Internet GMT conventions. Use
toUTCString instead.
39 toLocaleDateString()
Returns the "date" portion of the Date as a string, using the current locale's conventions.
40 toLocaleFormat()
41 toLocaleString()
42 toLocaleTimeString()
Returns the "time" portion of the Date as a string, using the current locale's conventions.
43 toSource()
Returns a string representing the source for an equivalent Date object; you can use this value
to create a new object.
44 toString()
45 toTimeString()
46 toUTCString()
47 valueOf()
1 Date.parse( )
Parses a string representation of a date and time and returns the internal millisecond
representation of that date.
2 Date.UTC( )
Returns the millisecond representation of the specified UTC date and time.
Math Methods
1 abs()
3 asin()
4 atan()
5 atan2()
6 ceil()
7 cos()
8 exp()
Returns EN, where N is the argument, and E is Euler's constant, the base of the natural
logarithm.
9 floor()
10 log()
11 max()
12 min()
13 pow()
15 round()
16 sin()
17 sqrt()
18 tan()
19 toSource()
RegExp Methods
1 exec()
2 test()
3 toSource()
Returns an object literal representing the specified object; you can use this value to create a
new object.
4 toString()
JavaScript provides facility to validate the form on the client-side so data processing will be faster
than server-side validation. Most of the web developers prefer JavaScript form validation.
Through JavaScript, we can validate name, password, email, date, mobile numbers and more fields.
Forms are used on webpages for the user to enter their required details that further send to the server for
processing. A form is also known as a web form or HTML form. Examples of form use are prevalent in e-
commerce websites, online banking, and online surveys to name a few.
Prerequisites:
HTML is used to create the form.
CSS to design the layout of the form.
JavaScript to validate the form.
Validating a form: The data entered into a form needs to be in the right format and certain fields need to be
filled in order to effectively use the submitted form. Username, password, and contact information are
some details that are mandatory in forms and thus need to be provided by the user.
Here, we are validating the form on form submit. The user will not be forwarded to the next page
until given values are correct.
<html>
<body>
<script>
function validateform(){
var name=document.myform.name.value;
var password=document.myform.password.value;
if (name==null || name==""){
alert("Name can't be blank");
return false;
}else if(password.length<6){
alert("Password must be at least 6 characters long.");
return false;
}
}
</script>
<body>
<form name="myform" method="post"
action="http://www.javatpoint.com/javascriptpages/valid.jsp" onsubmit="return
validateform()" >
Name: <input type="text" name="name"><br/>
Password: <input type="password" name="password"><br/>
<input type="submit" value="register">
</form>
</body>
</html>
<html>
<head>
<script type="text/javascript">
function matchpass(){
var firstpassword=document.f1.password.value;
var secondpassword=document.f1.password2.value;
if(firstpassword==secondpassword){
return true;
}
else{
alert("password must be same!");
return false;
}
}
</script>
</head>
<body>
</body>
</html>
JavaScript Number Validation
<html>
<head>
<script>
function validate(){
var num=document.myform.num.value;
if (isNaN(num)){
document.getElementById("numloc").innerHTML="Enter Numeric value only";
return false;
}else{
return true;
}
}
</script>
</head>
<body>
<form name="myform" action="http://www.javatpoint.com/javascriptpages/valid.jsp"
onsubmit="return validate()" >
Number: <input type="text" name="num"><span id="numloc"></span><br/>
<input type="submit" value="submit">
</form>
</body>
</html>
HTML5
The term HTML5 is essentially a buzzword that refers to a set of modern web technologies. This
includes the HTML Living Standard, along with JavaScript APIs to enhance storage, multimedia,
and hardware access. You may sometimes hear about "new HTML5 elements", or find HTML5
described as a new version of HTML.
HTML stands for Hyper Text Markup Language. It is used to design web pages using a markup language.
HTML is an abbreviation of Hypertext and Markup language. Hypertext defines the link between the web
pages. The markup language is used to define the text document within the tag which defines the structure
of web pages. HTML 5 is the fifth and current version of HTML. It has improved the markup available for
documents and has introduced application programming interfaces (API) and Document Object Model
(DOM).
Features:
It has introduced new multimedia features which supports both audio and video controls by using
<audio> and <video> tags.
There are new graphics elements including vector graphics and tags.
Enrich semantic content by including <header> <footer>, <article>, <section> and <figure> are added.
Drag and Drop- The user can grab an object and drag it further dropping it to a new location.
Geo-location services- It helps to locate the geographical location of a client.
Web storage facility which provides web application methods to store data on the web browser.
Uses SQL database to store data offline.
Allows drawing various shapes like triangle, rectangle, circle, etc.
Capable of handling incorrect syntax.
Easy DOCTYPE declaration i.e., <!doctype html>
Easy character encoding i.e., <meta charset=”UTF-8″>
There is a list of newly included tags in HTML 5. These HTML 5 tags (elements) provide a
better document structure. This list shows all HTML 5 tags in alphabetical order with
description.
CSS is used to apply the style in the web page which is made up of HTML elements. It describes the
look of the webpage.
CSS provides various style properties such as background color, padding, margin, border-color, and
many more, to style a webpage.
Each property in CSS has a name-value pair, and each property is separated by a semicolon (;).
Example:
<p style="color: blue; font-size: 25px; font-style: italic ;">This is a great website to learn technologies in very
simple way. </p>
</body>
o Inline CSS: Define CSS properties using style attribute in the HTML elements.
o Internal or Embedded CSS: Define CSS using <style> tag in <head> section.
o External CSS: Define all CSS property in a separate .css file, and then include the file with
HTML file using tag in section.
Inline CSS:
Inline CSS is used to apply CSS in a single element. It can apply style uniquely in each element.
To apply inline CSS, you need to use style attribute within HTML element. We can use as many
properties as we want, but each property should be separated by a semicolon (;).
Example:
<h3 style="color: red;
font-style: italic;
text-align: center;
font-size: 50px;
padding-top: 25px;">Learning HTML using Inline CSS</h3>
Internal CSS:
An Internal stylesheets contains the CSS properties for a webpage in <head> section of HTML
document. To use Internal CSS, we can use class and id attributes.
We can use internal CSS to apply a style for a single HTML page.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
/*Internal CSS using element name*/
body{background-color:lavender;
text-align: center;}
h2{font-style: italic;
font-size: 30px;
color: #f08080;}
p{font-size: 20px;}
/*Internal CSS using class name*/
.blue{color: blue;}
.red{color: red;}
.green{color: green;}
</style>
</head>
<body>
<h2>Learning HTML with internal CSS</h2>
<p class="blue">This is a blue color paragraph</p>
<p class="red">This is a red color paragraph</p>
<p class="green">This is a green color paragraph</p>
</body>
</html>
External CSS:
An external CSS contains a separate CSS file which only contains style code using the class name, id
name, tag name, etc. We can use this CSS file in any HTML file by including it in HTML file using <link>
tag.
If we have multiple HTML pages for an application and which use similar CSS, then we can use external
CSS.
body{
background-color:lavender;
text-align: center;
}
h2{
font-style: italic;
size: 30px;
color: #f08080;
}
p{
font-size: 20px;
}
.blue{
color: blue;
}
.red{
color: red;
}
.green{
color: green;
}
CSS3:
Difference between CSS and CSS3:
S.No CSS CSS3
.
1 CSS is capable of positioning texts and On the other hand, CSS3 is capable of making the web
objects. page more attractive and takes less time to create. CSS3
is backward compatible with CSS.
2 Responsive designing is not supported in CSS CSS3 is the latest version, hence it supports responsive
design.
3 CSS cannot be split into modules. Whereas CSS3 can be breakdown into modules.
4 Using CSS, we cannot build 3D animation But in CSS3 we can perform all kinds of animation and
and transformation. transformations as it supports animation and 3D
transformations.
5 CSS is very slow as compared to CSS3 Whereas CSS3 is faster than CSS.
6 In CSS we have set of standard colors and it Whereas CSS3 has a good collection of HSL RGBA,
uses basic color schemes only. HSLA, and gradient colors.
7 In CSS we can only use single text blocks. But in CSS3 we can use multi-column text blocks
8 CSS does not support media queries. But CSS3 supports media queries
9 CSS codes are not supported by all types of Being the latest version, CSS3 codes are supported by all
modern browsers. modern browsers.
10 In CSS, designers have to manually develop But CSS3 provides advanced codes for setting rounded
rounded gradients and corners. gradients and corners
11 There is no special effect like shadowing text, CSS3 has many advance features like text shadows,
text animation, etc. in CSS. The animation visual effects, and a wide range of font styles and colors.
was coded in jQuery and JavaScript.
12 In CSS, the user can add background colors Whereas CSS3 list has a special display property defined
to list items and lists, set images for the list in it. Even list items also have counter reset properties.
items, etc.
13 CSS was developed in 1996. CSS3 is the latest version of CSS and was released in
2005.
14 CSS is memory intensive. CSS3 memory consumption is low as compared to CSS.
Features in CSS 3
CSS3: CSS3 stands for Cascading Style Sheet level 3, which is the advanced version of CSS. It is used
for structuring, styling, and formatting web pages. Several new features have been added to CSS3
and it is supported by all modern web browsers. The most important feature of CSS3 is the
splitting of CSS standards into separate modules that are simpler to learn and use.
New Selectors: More ways to target HTML Elements
CSS3 has introduced new selectors to target HTML elements to create more
efficient stylesheets. Examples of new Selectores are:
Attribute Selectors: These selectors help you to target elements based on
attributes like class or id.
Child Selectors: These target elements that are direct children of another
element. For example, to target the lists of an ordered list, we use the selector
“ol>li.”
scale(): To resize any HTML element on a 2D plane, we use the scale() function
inCSS3.
translate(): To change the position of any HTML element along the horizontal
or vertical direction, we use the translate() function in CSS3.
Shadow effect
The CSS3 has an important box-shadow property to add shadows to text and
shapes, thus adding a sense of depth to them. Along with the box shadow, we
can add a horizontal and vertical offset, blur amount, shadow color, shadow
spread, and inset. This makes the web pages visually more engaging.
Example:
.container{
box-shadow : 1.5px 1.5px 5px #312577;
}
The above CSS code adds a shadow with a horizontal and vertical offset of
1.5px, 5px blur radius, and #312577 color to an HTML element with the class
name container.
Transitions and Animations: Smooth and Dynamic Visual Effects
CSS3 transitions and animations are an advanced styling feature that allows
web developers to add smooth and dynamic visual effects to their web pages.
While the transition property is used to create gradual changes in CSS property,
with animations, you can create more complex effects by specifying the
keyframes, which in turn target the values of CSS properties at specific time
stamps. Both transitions and animations can be used to create interactive web
pages.
Example:
HTML
<div class=”container”></div>
CSS
.container {
width: 50px;
height: 50px;
background-color: yellow;
transition: width 1s ease-in-out;
animation: rotate 4s linear infinite;
}
@keyframes rotate {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
Setting Opacity
Using rgba colors, the CSS3 opacity property can be applied to alter the opacity
of HTML elements. Instead of editing the picture with the required opacity and
adding it to the HTML file, we can simply write a single line of code in CSS.
Example:
div{
opacity: 0.7;
}
The above example applies an opacity of 0.7 on the targeted div element.
Flexbox: Powerful Layout Capabilities for Responsive Design
CSS3 comes with a very versatile and powerful flexbox property to organize the
contents within an HTML element in an efficient way to create a responsive
layout. The features of Flexbox include the following:
Flexible container: The HTML component containing the flex items can be
adjusted to fill the entire space or shrink as per the requirement.
Flexible items: The flex items can also be positioned as needed.
Direction control: We can change the direction of the Flexbox from column to
row and vice versa using the direction control feature of the Flexbox.
Multi Column Layout
CSS3 multicolumn layout property is used to create column layouts similar to
that of a newspaper or a magazine article. With this property, content can flow
to the next column automatically, depending upon the space available. We can
also define the column width, column count, gap, and property. We can thus
have the content in a more readable and presentable layout.
Media queries: Conditional styling for different screen sizes
HTML Canvas
he HTML <canvas> element is used to draw graphics on a web page.
The graphic to the left is created with <canvas>. It shows four elements: a red rectangle, a gradient
rectangle, a multicolor rectangle, and a multicolor text.
The HTML <canvas> element is used to draw graphics, on the fly, via JavaScript.
The <canvas> element is only a container for graphics. You must use JavaScript to actually draw the
graphics.
Canvas has several methods for drawing paths, boxes, circles, text, and adding images.
The HTML canvas element provides HTML a bitmapped surface to work with. It is used to draw
graphics on the web page.
The HTML 5 <canvas> tag is used to draw graphics using scripting language like JavaScript.
The <canvas> element is only a container for graphics, you must need a scripting language to draw
the graphics. The <canvas> element allows for dynamic and scriptable rendering of 2D shapes and
bitmap images.
It is a low level, procedural model that updates a bitmap and does not have a built-in scene. There
are several methods in canvas to draw paths, boxes, circles, text and add images.
Syntax:
<canvas>
Content...
</canvas>
Canvas Examples
A canvas is a rectangular area on an HTML page. By default, a canvas has no border and no content.
Note: Always specify an id attribute (to be referred to in a script), and a width and height attribute to
define the size of the canvas. To add a border, use the style attribute.
<html>
<body>
</body>
</html>
Add a JavaScript
After creating the rectangular canvas area, you must add a JavaScript to do the drawing.
<!DOCTYPE html>
<html>
<body>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.moveTo(0,0);
ctx.lineTo(200,100);
ctx.stroke();
</script>
</body>
</html>
Draw a Circle
<!DOCTYPE html>
<html>
<body>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.arc(95,50,40,0,2*Math.PI);
ctx.stroke();
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<canvas id="GFG"
width="600"
height="200"
style="border:1px solid #d3d3d3;">
</canvas>
<script>
let g = document.getElementById("GFG");
let geeks = g.getContext("2d");
geeks.font = "30px Arial";
geeks.fillText("vit", 170, 50);
</script>
</body>
</html>
It enables you to incorporate site elements using the drag-and-drop feature to create your desired website layout.
Track the performance of the website using in-house tools and analytics. It offers the possibility of adding tools like
Google Analytics, Google Ads, Facebook Pixel, etc.
You can create an online community that can interact with each other via likes, follows, comments, etc. This is
similar to other popular social media platforms.
Even though you do not get the creative freedom offered by tools that require coding, Wix’s simple process can
help you make a website with brilliant customization.
2. Squarespace
Squarespace is another website-building tool that offers more than 100 website templates to start with. Some
features of Squarespace are as follows:
It provides various functionalities for online shopping centers, such as customer account functionality, inventory
management, abandoned card recovery, and discount codes.
You can duplicate pages or other content to expedite the website building process.
You can provide fine-grain access to your project collaborators. The various access levels are Administrator, Store
Manager, Comment Moderator, Viewer, etc.
The UI of Squarespace itself is amazing, which may be one of the best options for you if you want to build an e-
commerce website.
You can avail a free trial of 2 weeks before subscribing to a paid plan.
Also Read: Overcoming Common Problems While Developing eCommerce Websites
3. Shopify
Shopify is a digital storefront platform that helps businesses create their digital stores. Some features of Shopify
include:
All the digital stores built on Shopify consist of an SSL certificate, and the store owner can purchase the domain
names directly from Shopify.
The platform helps the business owner to market their products using native marketing tools suite and sell more
products by introducing a mature third-party application integration ecosystem.
You can use many analytics tools to assess the digital store’s performance. This data can be further used to make
data-driven decisions for marketing, supply chain, etc.
You can avail of a free trial of Shopify for two weeks before subscribing to a paid plan.
Read More: Tips to Boost Speed of Shopify Website
4. WordPress
WordPress is the most known Content Management System (CMS) that can help you build a website quickly.
Some features of WordPress are as follows:
You can embed any type of media file on the page’s content area. There is also no limit on the number of pages,
posts, etc.
It is an open-source platform where you can find lots of free plugins that can improve the functionality of your
website.
Working with WordPress doesn’t require any prior experience in coding, and this platform is mainly used for
creating blogging websites for individuals or organizations.
Even though the website is open source, there are some costs related to building and running a website on the
WordPress platform.
Read More: Browser Compatibility Check on WordPress Sites
5. Webflow
Webflow is another website designer tool that doesn’t require coding to build websites. If you don’t want to get
involved in coding, Webflow is one of the tremendous website-building platforms. Also, you can add site elements
using the drag-and-drop feature to make a customized design layout.
Some other features of Webflow are as follows:
The Webflow platform includes a comprehensive CMS and web hosting services.
If you have already started building a website on other platforms like Squarespace, Wix, etc., and you want to
move the process to the Webflow platform, you can get in touch with one of the website-building experts approved
by the Webflow team.
You can add customized codes for an entire site, page, or a part of a page if you want to add something that isn’t
already offered by Webflow.
Also Read: 6 Common Web Design Mistakes That Degrade a Website’s User Experience
6. Adobe Dreamweaver
Adobe Dreamweaver is a commercial coding engine that allows you to view a real-time preview of the updated
content as soon as you edit the code. Some features of Dreamweaver are as follows:
Using Dreamweaver, you can build a responsive website application from scratch or use one of the available
templates.
This platform consists of code hints and GitHub support to help you make customized HTML sites such as blogs,
emails, e-commerce websites, portfolio web pages, etc.
You can import files from Adobe PhotoShop, Illustrator, and Sketch.
You can avail a free trial of 30 days before subscribing to a paid plan. You can also subscribe for a plan that
includes the complete Adobe Creative Suite suite, Dreamweaver, XD, and Photoshop.
7. Figma
Figma is an online web designing tool that enables users to edit and prototype website designs. This tool
empowers the collaborative effort of the web designing team. You can collaborate in brainstorming ideas and
create prototypes and share them with other collaborators for feedback using the same tool. Some important
features include:
You can collaborate with developers (for free) at the commencement of the design process to understand the
requirements better.
The API plugin enables collaborators to make their own plugins or use the resources from the user community to
improve the functionality of the tool.
Other features include auto layout, template library, ease of collaboration, etc.
8. Nova
Nova is an updated version of Panic, a website development application used for the Mac Operating System. This
website layout design tool aims to reduce the number of secondary tools needed to develop a web application like
CSS editor, FTP client, and version control system. This, in turn, improves the workflow and functionality of your
development team.
Some features of Nova are:
The platform has a user interface with multiple tabs for text editing, SVN, file transfers, CSS, etc.
Nova offers a range of extensions, for example: ESLint, Prettier, YAML, TypeScript, etc.
The text editor of Nova has many features, including smart autocomplete, mini-map, multiple cursors, editor over-
scroll, etc.
You can purchase the Nova application and own it forever for $99 + taxes.
9. Google Web Designer
Google Web Designer is a website designing platform that helps build interactive and appealing webpage designs
based on HTML 5. The tool also ensures that the webpage designs and motion graphics are running as expected
and can be viewed on various digital devices like computers and smartphones. Some features of this tool are as
follows:
Canva is the most popular design platform. This tool can help you to create visuals for your website. Some
features of Canva are as follows:
This tool allows for adding animations, building design systems, and responsive web designs.
Using Repeat Grid, you can duplicate all types of lists and galleries for different web pages
You can import files from Adobe PhotoShop, Illustrator and Sketch.
You can avail a free started plan of Adobe XD and create a limited number of projects. You can go for a plan that
includes the complete suite of Adobe Creative Suite that includes Dreamweaver, XD, and Photoshop.
You can use BrowserStack’s free Responsive Design checker to check the website’s responsiveness on various
iOS and Android devices.
InVision Studio is a prototyping tool that permits users to visualize their designs and evaluate the user experience.
It makes it easy for multiple collaborators to work on a single web development project. Some features of InVision
Studio include:
Numerous collaborative tools like InVision Freehand to brainstorm ideas and create a template design on the
digital whiteboard.
You can also receive feedback and comments from other collaborators on the platform itself.
The tool eases the transition from the prototyping phase to the development phase.
Some of the other tools that weren’t listed above but are with mentioning are as follows:
Adobe Photoshop
Sketch
Marvel
Mockflow
Adobe Comp
Bootstrap and many others