Unit 1
Unit 1
• Tags: An HTML tag surrounds the content and apply meaning to it.
It is written between < and > brackets.
<!DOCTYPE html>
<html>
<body>
<body style="background-color:red;"> // background colours
</body>
</html>
HTML Styles
• The HTML style attribute is used to add styles to an element, such as color, font, size, and more.
<!DOCTYPE html>
<html>
<body>
<p>I am normal</p>
<p style="color:red;">I am red</p>
<p style="color:blue;">I am blue</p>
<p style="font-size:50px;">I am big</p>
</body>
</html>
HTML Comments
• HTML comments are not displayed in the browser, but they can help document
your HTML source code.
<!DOCTYPE html>
<html>
<body>
</body>
</html>
HTML Lists
• HTML Lists are used to specify lists of information. All lists may
contain one or more list elements.
• There are three different types of HTML lists:
• If you want a bullet list inside a numbered list then such type of list
will called as nested list
HTML Forms
• An HTML form is used to collect user input.
• The user input is most often sent to a server for processing.
<!DOCTYPE html>
<html>
<body>
<h2>HTML Forms</h2>
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value=“Mohamed"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value=“Divan"><br><br>
<input type="submit" value="Submit">
</form>
<p>If you click the "Submit" button, the form-data will be sent to a page called "/action_page.php".</p>
</body>
</html>
The <form> Element
The HTML <form> element is used to create an HTML form for user input:
Syntax
<form>
.
form elements
.
</form>
The <form> element is a container for different types of input elements, such as: text fields, checkboxes, radio buttons, submit
buttons, etc.
The <label> Element
• The <label> element is beneficial for screen-reader users, because the screen-reader will read out loud
• The <label> element also helps users, who have difficulty clicking on very small regions (such as radio
buttons or checkboxes)
• The for attribute of the <label> tag should be equal to the id attribute of the <input> element to bind
them together.
Radio Buttons
<h2>Radio Buttons</h2>
<form>
Output:-
<input type="radio" id="html" name="fav_language" value="HTML"> Choose your favorite Web language:
<label for="html">HTML</label><br> HTML
<input type="radio" id="css" name="fav_language" value="CSS"> CSS
JavaScript
<label for="css">CSS</label><br>
<input type="radio" id="javascript" name="fav_language" value="JavaScript">
<label for="javascript">JavaScript</label>
</form>
</body>
</html>
Checkboxes
• The <input type="checkbox"> defines a checkbox.
• Checkboxes let a user select ZERO or MORE options of a limited number of choices.
Example
A form with checkboxes:
<form>
<input type="checkbox" id="vehicle1" name="vehicle1" value="Bike"> Output:-
<label for="vehicle1"> I have a bike</label><br>
This is how the HTML code above will be displayed
<input type="checkbox" id="vehicle2" name="vehicle2" value="Car"> in a browser:
<label for="vehicle2"> I have a car</label><br>
I have a bike
<input type="checkbox" id="vehicle3" name="vehicle3" value="Boat">
I have a car
<label for="vehicle3"> I have a boat</label> I have a boat
</form>
HTML Multimedia
• Multimedia on the web is sound, music, videos, movies, and animations.
What is Multimedia?
• It can be almost anything you can hear or see, like images, music, sound, videos, records, films,
animations, and more.
• Web pages often contain multimedia elements of different types and formats.
Browser Support
• The first web browsers had support for text only, limited to a single font in a single color.
• Later came browsers with support for colors, fonts, images, and multimedia!
Multimedia Formats
• The most common way to discover the type of a file, is to look at the file extension.
What is CSS?
• With CSS, you can control the color, font, the size of text, the spacing between elements, how
elements are positioned and laid out, what background images or background colors are to be
used, different displays for different devices and screen sizes, and much more.
Using CSS
• The most common way to add CSS, is to keep the styles in external CSS files.
Inline CSS
• The following example sets the text color of the <h1> element to blue, and the text color of the
<p> element to red:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Internal CSS
• An internal CSS is used to define a style for a single HTML page.
• An internal CSS is defined in the <head> section of an HTML page, within a <style> element.
• The following example sets the text color of ALL the <h1> elements (on that page) to blue, and the text
color of ALL the <p> elements to red. In addition, the page will be displayed with a "powderblue"
background color: <html>
<head>
<style>
body {background-color: powderblue;}
h1 {color: blue;}
p {color: red;}
</style></head><body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
External CSS
• An external style sheet is used to define the style for many HTML pages.
• To use an external style sheet, add a link to it in the <head> section of each
HTML page:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
CSS Colors, Fonts and Sizes
• Here, we will demonstrate some commonly used CSS properties. You will learn more
about them later.
Example
Use of CSS border property:
p{
border: 2px solid powderblue;
}
CSS Padding
The CSS padding property defines a padding (space) between the text and
the border.
Example
Use of CSS border and padding properties:
p{
border: 2px solid powderblue;
padding: 30px;
}
CSS Margin
The CSS margin property defines a margin (space) outside the border.
Example
Use of CSS border and margin properties:
p{
border: 2px solid powderblue;
margin: 50px;
}
JavaScript
• JavaScript is an object-based scripting language which is lightweight and cross-
platform.
• The JavaScript Translator (embedded in the browser) is responsible for translating the
JavaScript code for the web browser.
Features of JavaScript
There are following features of JavaScript:
1. All popular web browsers support JavaScript as they provide built-in execution environments.
2. JavaScript follows the syntax and structure of the C programming language. Thus, it is a structured
programming language.
3. JavaScript is a weakly typed language, where certain types are indirectly cast (depending on the
operation). (send the data indirectly to server)
4. JavaScript is an object-oriented programming language that uses prototypes rather than using classes
for inheritance.
6. It is a case-sensitive language.
• Client-side validation,
• Displaying pop-up windows and dialog boxes (like an alert dialog box, confirm
dialog box and prompt dialog box),
<script>
</script>
JavaScript Functions
• Less coding: It makes our program compact. We don’t need to write many lines of
//code to be executed
<html>
<body>
<script>
function msg(){
</script>
</body>
</html>
JavaScript Function Object
• It executes the code globally. However, if we call the constructor directly, a function is created dynamically
but in an unsecured way.
Syntax
<html>
<body>
<script>
document.writeln(add(2,5));
</script>
</body>
</html>
JavaScript Objects
• A javaScript object is an entity having state and behavior (properties and method). For
• JavaScript is template based not class based. Here, we don't create class to get the object.
object={property1:value1,property2:value2.....propertyN:valueN}
<html>
<body>
<script>
emp={id:102,name:"Shyam Kumar",salary:40000}
</script>
</body>
</html>
By creating instance of Object
<html>
<body>
<script>
var emp=new Object();
emp.id=101;
emp.name="Ravi Malik";
emp.salary=50000;
document.write(emp.id+" "+emp.name+" "+emp.salary);
</script>
</body>
</html>
By using an Object constructor
• Each argument value can be assigned in the current object by using this keyword.
1. If Statement
2. If else statement
3. if else if statement
JavaScript If statement
It evaluates the content only if expression is true. The signature of JavaScript if statement is given below.
if(expression){
//content to be evaluated
}
Example program
<html>
<body>
<script>
var a=20;
if(a>10){
</script>
</body>
</html>
JavaScript If...else Statement
<html>
<body>
<script>
var a=20;
if(a%2==0){
else{
</script>
</body>
</html>
JavaScript If...else if statement
• It evaluates the content only if expression is true from several expressions. The signature of JavaScript if else
if statement is given below.
if(expression1){
//content to be evaluated if expression1 is true
}
else if(expression2){
//content to be evaluated if expression2 is true
}
else if(expression3){
//content to be evaluated if expression3 is true
}
else{
//content to be evaluated if no expression is true
}
<html>
<body>
<script>
var a=20;
if(a==10){
else if(a==15){
else if(a==20){
else{
</script>
</body>
</html>