UNIT 1: INTRODUCTION TO HTML
1.1 Getting Started with a Simple Web Page
A web page is a document that is shown in a web browser.
HTML is used to create this web page.
HTML uses tags to tell the browser what to display.
Every HTML page must have:
Full HTML Program
<!DOCTYPE html>
<html>
<head>
<title>My First Page</title>
</head>
<body>
<h1>Hello World</h1>
<p>This is a simple HTML web page.</p>
</body>
</html>
Advantages
1.2 Block and Inline Elements
HTML elements are divided into block and inline elements.
Examples
Full HTML Program
<!DOCTYPE html>
<html>
<head>
<title>Block and Inline</title>
</head>
<body>
<h2>Block Elements</h2>
<p>This is a paragraph</p>
<div>This is a div</div>
<h2>Inline Elements</h2>
<p>This is <b>bold</b> and <i>italic</i> text.</p>
</body>
</html>
Advantages
1.3 Presentation and Phrase Elements
Description
These elements are used to format text and give meaning.
Examples
Full HTML Program
<!DOCTYPE html>
<html>
<head>
<title>Presentation and Phrase</title>
</head>
<body>
<b>Bold Text</b><br>
<i>Italic Text</i><br>
H<sub>2</sub>O<br>
x<sup>2</sup><br><br>
<strong>Important Text</strong><br>
<em>Emphasized Text</em><br>
<mark>Highlighted Text</mark>
</body>
</html>
Advantages
1.4 Empty and Non-Empty Elements
Examples
Full HTML Program
<!DOCTYPE html>
<html>
<head>
<title>Empty and Non Empty</title>
</head>
<body>
<p>This is a paragraph</p>
Line one<br>
Line two
<hr>
<img src=”image.jpg” width=”150″>
</body>
</html>
Advantages
1.5 HTML Character Entities
Some characters have special meaning in HTML.
To display them correctly, character entities are used.
Examples
Full HTML Program
<!DOCTYPE html>
<html>
<head>
<title>Character Entities</title>
</head>
<body>
<p>5 < 10</p>
<p>10 > 5</p>
<p>AT&T Company</p>
<p>Copyright © 2026</p>
</body>
</html>
Advantages
1.6 HTML List, Table, and Links
Types
Full HTML Program
<!DOCTYPE html>
<html>
<head>
<title>Lists Tables Links</title>
</head>
<body>
<h3>Unordered List</h3>
<ul>
<li>HTML</li>
<li>CSS</li>
</ul>
<h3>Table</h3>
<table border=”1″>
<tr>
<th>Name</th>
<th>Marks</th>
</tr>
<tr>
<td>Rahul</td>
<td>85</td>
</tr>
</table>
<h3>Links</h3>
<a href=”page.html”>Internal Link</a><br>
<a href=”https://www.google.com”>External Link</a>
</body>
</html>
Advantages
1.7 Multimedia Contents
Multimedia makes web pages attractive by adding:
Full HTML Program
<!DOCTYPE html>
<html>
<head>
<title>Multimedia</title>
</head>
<body>
<h3>Image</h3>
<img src=”image.jpg” width=”200″><br><br>
<h3>Audio</h3>
<audio controls>
<source src=”audio.mp3″>
</audio><br><br>
<h3>Video</h3>
<video controls width=”250″>
<source src=”video.mp4″>
</video><br><br>
<h3>YouTube Video</h3>
<iframe width=”250″ height=”180″
src=”https://www.youtube.com/embed/VIDEO_ID”>
</iframe>
</body>
</html>
Advantages
1.8 Form Elements
Forms are used to collect information from users such as name, password, email, etc.
Common Form Elements
Text, password, email, date, file, radio, checkbox, textarea, hidden, select, button
Full HTML Program
<!DOCTYPE html>
<html>
<head>
<title>Form Elements</title>
</head>
<body>
<form>
Name: <input type=”text”><br><br>
Password: <input type=”password”><br><br>
Email: <input type=”email”><br><br>
Date: <input type=”date”><br><br>
File: <input type=”file”><br><br>
Gender:
<input type=”radio” name=”g”>Male
<input type=”radio” name=”g”>Female<br><br>
Hobbies:
<input type=”checkbox”>Reading
<input type=”checkbox”>Sports<br><br>
Address:<br>
<textarea rows=”4″ cols=”30″></textarea><br><br>
Country:
<select>
<option>India</option>
<option>USA</option>
</select><br><br>
<input type=”hidden” value=”001″>
<button type=”submit”>Submit</button>
</form>
</body>
</html>
Advantages
UNIT 2: CASCADING STYLE SHEET (CSS)
2.1 How CSS Fits with HTML Page
CSS (Cascading Style Sheet) is used to style HTML elements.
HTML creates the structure of a page, while CSS controls:
CSS works with HTML, not alone.
Program
<!DOCTYPE html>
<html>
<head>
<title>CSS with HTML</title>
<style>
h1 {
color: blue;
}
p {
font-size: 18px;
}
</style>
</head>
<body>
<h1>CSS with HTML</h1>
<p>This paragraph is styled using CSS.</p>
</body>
</html>
Advantages
2.2 Inline, Internal and External CSS
CSS can be applied in three ways:
Program (All Three Types)
<!DOCTYPE html>
<html>
<head>
<title>Types of CSS</title>
<!– Internal CSS –>
<style>
h2 {
color: green;
}
</style>
<!– External CSS –>
<link rel=”stylesheet” href=”style.css”>
</head>
<body>
<!– Inline CSS –>
<h1 style=”color:red;”>Inline CSS</h1>
<h2>Internal CSS</h2>
<p class=”ext”>External CSS Example</p>
</body>
</html>
style.css
.ext {
color: blue;
font-size: 20px;
}
Advantages
2.3 CSS Selectors
CSS selectors select HTML elements to apply styles.
Types
Program
<!DOCTYPE html>
<html>
<head>
<title>CSS Selectors</title>
<style>
p {
color: blue;
}
.class1 {
color: green;
}
#id1 {
color: red;
}
* {
font-family: Arial;
}
</style>
</head>
<body>
<p>Element Selector</p>
<p class=”class1″>Class Selector</p>
<p id=”id1″>ID Selector</p>
</body>
</html>
Advantages
2.4 CSS Properties (Text, List, Table, Background, Link)
CSS properties control the appearance of elements.
Program
<!DOCTYPE html>
<html>
<head>
<title>CSS Properties</title>
<style>
p {
color: blue;
text-align: center;
}
ul {
list-style-type: square;
}
table {
border-collapse: collapse;
width: 50%;
}
td, th {
border: 1px solid black;
padding: 5px;
}
body {
background-color: lightyellow;
}
a {
color: red;
text-decoration: none;
}
</style>
</head>
<body>
<p>Text Formatting</p>
<ul>
<li>HTML</li>
<li>CSS</li>
</ul>
<table>
<tr>
<th>Name</th>
<th>Marks</th>
</tr>
<tr>
<td>Ravi</td>
<td>80</td>
</tr>
</table>
<a href=”#”>Styled Link</a>
</body>
</html>
Advantages
2.5 Pseudo Classes & Elements
Pseudo classes and elements style special states of elements.
Types
Full HTML Program
<!DOCTYPE html>
<html>
<head>
<title>Pseudo Classes</title>
<style>
p::first-letter {
font-size: 30px;
color: red;
}
p::first-line {
color: blue;
}
h1::before {
content: “★ “;
}
h1::after {
content: ” ★”;
}
a:hover {
color: green;
}
input:focus {
background-color: lightblue;
}
a:active {
color: red;
}
</style>
</head>
<body>
<h1>Welcome</h1>
<p>This is a paragraph example for pseudo elements.</p>
<a href=”#”>Hover Me</a><br><br>
<input type=”text” placeholder=”Focus here”>
</body>
</html>
Advantages
2.6 Custom List Numbering Using Content Property
Description
CSS content property is used with ::before to create custom numbering.
Full HTML Program
<!DOCTYPE html>
<html>
<head>
<title>Custom List</title>
<style>
ol {
list-style: none;
}
li::before {
content: “ “;
color: green;
}
</style>
</head>
<body>
<ol>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ol>
</body>
</html>
Advantages
2.7 CSS Box Model
Description
CSS Box Model consists of:
Full HTML Program
<!DOCTYPE html>
<html>
<head>
<title>Box Model</title>
<style>
div {
width: 200px;
padding: 20px;
border: 5px solid blue;
margin: 30px;
background-color: lightgray;
}
</style>
</head>
<body>
<div>This is CSS Box Model</div>
</body>
</html>
Advantages
2.8 Creating Layouts (Display, Position, Float)
Description
CSS layout properties control element positioning.
Properties
Full HTML Program
<!DOCTYPE html>
<html>
<head>
<title>CSS Layout</title>
<style>
.box1 {
float: left;
width: 40%;
background: lightblue;
padding: 10px;
}
.box2 {
float: right;
width: 40%;
background: lightgreen;
padding: 10px;
}
</style>
</head>
<body>
<div class=”box1″>Left Box</div>
<div class=”box2″>Right Box</div>
</body>
</html>
Advantages
2.9 Fixed and Liquid Design
Full HTML Program
<!DOCTYPE html>
<html>
<head>
<title>Fixed and Liquid</title>
<style>
.fixed {
width: 300px;
background-color: lightcoral;
padding: 10px;
}
.liquid {
width: 60%;
background-color: lightseagreen;
padding: 10px;
}
</style>
</head>
<body>
<div class=”fixed”>Fixed Width Box</div><br>
<div class=”liquid”>Liquid Width Box</div>
</body>
</html>
Advantages
UNIT 3: CLIENT SIDE PROGRAMMING WITH JAVASCRIPT
3.1 How JavaScript Fits into a Web Page
JavaScript is a client-side scripting language.
It runs inside the web browser and makes web pages interactive.
HTML → structure
CSS → design
JavaScript → behavior (actions)
JavaScript can be written:
Full HTML Program
<!DOCTYPE html>
<html>
<head>
<title>JavaScript in Web Page</title>
<script>
function showMessage() {
alert(“JavaScript is working!”);
}
</script>
</head>
<body>
<h2>JavaScript Example</h2>
<button onclick=”showMessage()”>Click Me</button>
</body>
</html>
Advantages
3.2 JavaScript Basics: Variables and Operators
Variables
Variables store data values.
Keywords:
Operators
Used to perform operations.
Types:
Program
<!DOCTYPE html>
<html>
<head>
<title>Variables and Operators</title>
<script>
function calculate() {
let a = 10;
let b = 5;
let sum = a + b;
document.getElementById(“result”).innerHTML = “Sum = ” + sum;
}
</script>
</head>
<body>
<h2>JavaScript Variables</h2>
<button onclick=”calculate()”>Calculate</button>
<p id=”result”></p>
</body>
</html>
Advantages
3.3 Understanding the Document Object Model (DOM)
DOM represents the HTML page as objects.
JavaScript uses DOM to:
HTML elements become objects in DOM.
Program
<!DOCTYPE html>
<html>
<head>
<title>DOM Example</title>
<script>
function changeText() {
document.getElementById(“msg”).innerHTML = “Text Changed!”;
}
</script>
</head>
<body>
<h2 id=”msg”>Original Text</h2>
<button onclick=”changeText()”>Change Text</button>
</body>
</html>
Advantages
3.4 Accessing HTML Elements
JavaScript accesses HTML elements using DOM methods.
Methods
Program
<!DOCTYPE html>
<html>
<head>
<title>Access Elements</title>
<script>
function accessElements() {
document.getElementById(“id1”).style.color = “red”;
let c = document.getElementsByClassName(“cls”);
c[0].style.color = “blue”;
let t = document.getElementsByTagName(“p”);
t[1].style.color = “green”;
}
</script>
</head>
<body>
<h2 id=”id1″>By ID</h2>
<p class=”cls”>By Class</p>
<p>By Tag</p>
<button onclick=”accessElements()”>Apply</button>
</body>
</html>
Advantages
3.5 JavaScript Objects
Objects store properties and methods.
Common Objects
Program
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Objects</title>
<script>
function showObjects() {
let arr = [“HTML”, “CSS”, “JS”];
let today = new Date();
let num = Math.sqrt(16);
document.getElementById(“out”).innerHTML =
“Array: ” + arr +
“<br>Date: ” + today +
“<br>Square Root: ” + num;
}
</script>
</head>
<body>
<h2>JavaScript Objects</h2>
<button onclick=”showObjects()”>Show</button>
<p id=”out”></p>
</body>
</html>
Advantages
3.6 Writing Scripts to Handle Events
Events occur when user performs actions like:
JavaScript handles events using event handlers.
Program
<!DOCTYPE html>
<html>
<head>
<title>Event Handling</title>
<script>
function showAlert() {
alert(“Button Clicked!”);
}
</script>
</head>
<body>
<h2>Event Handling Example</h2>
<button onclick=”showAlert()”>Click Me</button>
</body>
</html>
Advantages
3.7 Using JavaScript to Validate User Inputs
Validation checks user input before submitting a form.
Examples:
Validation improves data accuracy.
Program
<!DOCTYPE html>
<html>
<head>
<title>Form Validation</title>
<script>
function validateForm() {
let name = document.getElementById(“name”).value;
if (name == “”) {
alert(“Name must be filled out”);
return false;
}
alert(“Form Submitted Successfully”);
return true;
}
</script>
</head>
<body>
<h2>Form Validation</h2>
<form onsubmit=”return validateForm()”>
Name: <input type=”text” id=”name”><br><br>
<input type=”submit” value=”Submit”>
</form>
</body>
</html>
Advantages
prompt() → always returns a string
parseInt() → converts to integer
parseFloat() → converts to decimal / double
Number() → can also be used for both integer and decimal
<!DOCTYPE html>
<html>
<body>
<script>
var name = prompt(“Enter your name”);
document.write(“Hello ” + name);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<script>
var num = parseInt(prompt(“Enter a number”));
if (num % 2 == 0)
document.write(num + ” is Even”);
else
document.write(num + ” is Odd”);
</script>
</body>
</html>
Factorial program in javascript
<!DOCTYPE html>
<html>
<head>
<title>Factorial using Recursion</title>
<script>
function fact(n) {
if (n == 0)
return 1;
else
return n * fact(n – 1);
}
var num = 5; // number whose factorial is to be found
var result = fact(num);
document.write(“Factorial of ” + num + ” is ” + result);
</script>
</head>
<body>
</body>
</html>
The DOM (Document Object Model) is a tree-like structure that represents an HTML document. JavaScript uses the DOM to access, change, add, or delete HTML elements dynamically.
Document
└── html
├── head
└── body
├── h1
└── p
document.getElementById
<!DOCTYPE html>
<html>
<body>
<h2 id=”msg”>Hello World</h2>
<button onclick=”changeText()”>Click</button>
<script>
function changeText() {
document.getElementById(“msg”).innerHTML = “Hello JavaScript!”;
}
</script>
</body>
</html>
<p class=”text”>First Paragraph</p>
<p class=”text”>Second Paragraph</p>
<button onclick=”changeText()”>Click Me</button>
document.getElementsByClassName()
<script>
function changeText() {
document.getElementsByClassName(“text”)[0].style.color = “red”;
}
</script>
document.getElementsByTagName()
<h1>Heading 1</h1>
<h1>Heading 2</h1>
<button onclick=”changeHeading()”>Click Me</button>
<script>
function changeHeading() {
document.getElementsByTagName(“h1”)[0].innerHTML = “Changed Heading”;
}
</script>
Event Handling
Event handling is a way to make a web page respond to user actions, like:
Click Event
<!DOCTYPE html>
<html>
<body>
<button onclick=”showMessage()”>Click Me</button>
<script>
function showMessage() {
alert(“Button was clicked!”);
}
</script>
</body>
</html>
Using addEventListener() (Modern Way)
<button id=”btn”>Click Me</button>
<script>
document.getElementById(“btn”).addEventListener(“click”, function() {
alert(“Button clicked using addEventListener!”);
});
</script>