Module 4 FOC
Module 4 FOC
Example:
The request is sent to the correct web server that hosts the website.
Module-4 1
Reads the HTML Adds headings, images, and text.
Finally, the webpage appears on your screen, ready for you to use!
1. Web Server
A web server is a system that stores and delivers web pages when users request
them through a browser. It acts as an intermediary between the user and the
websiteʼs files. Hereʼs how it works:
When a user enters a website URL in a browser, the browser sends a request
to the web server.
The web server processes the request and retrieves the necessary files (such
as HTML, CSS, JavaScript, images, and videos).
It then sends these files back to the browser, which interprets and displays the
web page to the user.
Web servers also handle multiple requests from different users at the same
web page to the user.
Web servers also handle multiple requests from different users at the same
time, ensuring that websites remain accessible.
Some commonly used web servers include Apache, Nginx, Microsoft IIS, and
LiteSpeed.
2. Web Browser
A web browser is software that allows users to access and interact with websites.
It acts as a bridge between the user and the web server. The main functions of a
web browser include:
Receiving and interpreting files such as HTML (for structure), CSS (for styling),
and JavaScript (for functionality).
Module-4 2
Some popular web browsers include Google Chrome, Mozilla Firefox,
Microsoft Edge, and Safari.
It enables the transfer of website elements like text, images, videos, and
interactive features.
HTTP is not secure, as it does not encrypt data. This means that if sensitive
information (like passwords or credit card details) is transmitted using HTTP,
hackers can intercept and read it.
Authentication Ensures that the website being accessed is legitimate and not
a fake version created by attackers.
Data Integrity Ensures that data is not modified or tampered with during
transmission.
Websites using HTTPS have a padlock icon in the address bar, indicating a
secure connection.
Module-4 3
HTTPS is widely used for online banking, e-commerce, and login pages to
protect user information.
1. Client (Front-End)
What is a Client?
The client is the userʼs web browser Chrome, Firefox, Edge, Safari, etc.).
The client is the userʼs web browser Chrome, Firefox, Edge, Safari, etc.).
CSS Cascading Style Sheets) Adds styling like colors, fonts, and layouts.
Example:
When you enter www.example.com in your browser, it sends a request to the
server to retrieve the webpage.
Module-4 4
The server responds with HTML, CSS, and JavaScript files, which the
browser processes and displays as a webpage.
2. Server (Back-End)
What is a Server?
The server is a powerful computer that stores and delivers website content.
Application Logic The brain of the website that processes user actions,
manages sessions, and enforces business rules.
Example:
When you log into a website, your username and password are sent to the
server.
The server checks the credentials in the database and sends a response.
3. Database
What is a Database?
A database is a system used to store and manage website data securely.
Module-4 5
Types of Databases:
SQL Databases Structured Query Language)
Best for structured data like e-commerce products, orders, and users.
NoSQL Databases
Best for large-scale applications, real-time chat, and social media feeds.
Example:
When you search for a product on an e-commerce website, the database
retrieves matching items based on your query.
4. Request-Response Cycle
4. Request-Response Cycle
How Does the Client Communicate with the Server?
The client and server communicate using a process called the request-response
cycle over HTTP/HTTPS:
If the user submits a form (e.g., login), the browser sends a request with
form data.
Module-4 6
If the request needs data (e.g., user login), the server queries the
database.
The browser receives the response and renders the webpage or displays
a message.
The server checks the database to see if the credentials are correct.
The server checks the database to see if the credentials are correct.
When a user enters a domain name, the DNS server finds the corresponding
IP address and directs the request to the correct web server.
DNS Process:
Module-4 7
The browser connects to the correct web server and loads the website.
Structure of a URL
Protocol: Defines how the browser communicates with the server (e.g., http://,
https://).
https://www.example.com/products/item123
3. Web Hosting
Web hosting is a service that stores website files and makes them accessible
online.
The hosting server delivers web pages to users when requested via a browser.
Shared Hosting
Module-4 8
VPS Virtual Private Server) Hosting
Dedicated Hosting
Cloud Hosting
1. What is HTML?
HTML HyperText Markup Language) is the standard language for creating
web pages.
Module-4 9
Works alongside CSS Cascading Style Sheets) for styling and JavaScript for
interactivity.
!DOCTYPE html>
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
<h1Welcome to My Website</h1
<p>This is a paragraph of text.</p>
<a href="https://www.example.com"Click Here</a>
</body>
<a href="https://www.example.com"Click Here</a>
</body>
</html>
Explanation of Structure:
<title> Sets the title of the webpage (shown in the browser tab).
Module-4 10
Headings: <h1 to <h6 for different heading sizes.
Lists: <ul> (unordered list), <ol> (ordered list), and <li> (list items).
1. Basic Differences
HTML HyperText Markup XHTML Extensible HyperText
Feature
Language) Markup Language)
HTML HyperText Markup XHTML Extensible HyperText
Feature
Language) Markup Language)
Module-4 11
Requires a strict DOCTYPE
Doctype Declaration !DOCTYPE html> (in HTML5 declaration, such as !DOCTYPE
XHTML 1.0 Strict> .
!DOCTYPE html>
<html>
<head>
<title>HTML Example</title>
</head>
<body>
<h1Welcome</h1
<p>This is an HTML page.</p>
<img src="image.jpg">
<p>This is an HTML page.</p>
<img src="image.jpg">
</body>
</html>
XHTML Example:
Module-4 12
</body>
</html>
Example:
<h1Main Title</h1
<h2Subheading</h2
<h3Section Title</h3
<h2Subheading</h2
<h3Section Title</h3
2. Paragraphs ( <p> )
The <p> tag is used for defining paragraphs.
Example:
3. Lists
There are two main types of lists in HTML
Module-4 13
Example:
<ol>
<li>Item 1/li>
<li>Item 2/li>
<li>Item 3/li>
</ol>
Example:
<ul>
<li>Apple</li>
<li>Banana</li>
<li>Cherry</li>
</ul>
</ul>
4. Links ( <a> )
Links allow navigation between pages.
Example:
5. Tables ( <table> )
Tables organize data in rows and columns.
Example:
<table border="1">
<tr>
Module-4 14
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>John</td>
<td>25/td>
</tr>
<tr>
<td>Jane</td>
<td>22/td>
</tr>
</table>
6. Forms ( <form> )
Forms collect user input and send it to a server.
Example:
<label for="email"Email:</label>
<input type="email" id="email" name="email" required>
Module-4 15
<label> associates text with form elements.
7. Images ( <img> )
The <img> tag displays images.
Example:
Example:
<div>
<h2Section Title</h2
<p>This is a paragraph inside a div.</p>
</div>
9. Buttons ( <button> )
The <button> tag creates clickable buttons.
Example:
Module-4 16
10. Horizontal Line ( <hr> ) & Line Break ( <br> )
<hr> adds a horizontal line.
Example:
1. HTML Attributes
Attributes provide additional information about HTML elements. They are added
inside the opening tag and usually follow the attribute="value" format.
Example:
Module-4 17
2. Semantic HTML
Semantic HTML refers to using HTML elements that convey meaning about their
content. It improves accessibility, SEO, and code readability.
Example:
<header>
<h1Website Title</h1
<header>
<h1Website Title</h1
</header>
<nav>
<ul>
<li><a href="home.html"Home</a></li>
<li><a href="about.html"About</a></li>
</ul>
</nav>
<section>
<article>
<h2Blog Post Title</h2
<p>This is an example of a blog post.</p>
</article>
</section>
<footer>
<p>© 2025 My Website</p>
</footer>
Module-4 18
3. Web Accessibility (A11Y)
Web accessibility ensures that websites are usable by everyone, including people
with disabilities.
<form>
<label for="name"Name:</label>
<form>
<label for="name"Name:</label>
<input type="text" id="name" name="name" aria-required="true">
<button type="submit"Submit</button>
</form>
Module-4 19
Example:
a) Text Input
Used for short text input like names or usernames.
<label for="name"Name:</label>
<input type="text" id="name" name="name" required>
b) Email Input
Accepts email addresses with built-in validation.
b) Email Input
Accepts email addresses with built-in validation.
<label for="email"Email:</label>
<input type="email" id="email" name="email" required>
c) Password Input
Masks characters for secure password entry.
<label for="password"Password:</label>
<input type="password" id="password" name="password" required>
d) Number Input
Allows numeric values only.
<label for="age"Age:</label>
Module-4 20
<input type="number" id="age" name="age" min="1" max="100">
e) Radio Buttons
Used for selecting one option from multiple choices.
<label>Gender:</label>
<input type="radio" id="male" name="gender" value="male">
<label for="male"Male</label>
f) Checkboxes
Used for selecting multiple options.
<label>Hobbies:</label>
<input type="checkbox" id="sports" name="hobby" value="sports">
<label>Hobbies:</label>
<input type="checkbox" id="sports" name="hobby" value="sports">
<label for="sports"Sports</label>
<label for="country"Country:</label>
<select id="country" name="country">
<option value="usa"USA/option>
<option value="uk"UK/option>
<option value="india"India</option>
</select>
h) Textarea
Module-4 21
Used for multi-line text input.
<label for="message"Message:</label>
<textarea id="message" name="message" rows="4" cols="30"></textarea>
i) File Upload
Allows users to upload files.
j) Date Picker
Allows users to select a date.
k) Submit Button
Sends form data to the server.
l) Reset Button
Clears all input fields.
a) Placeholder
Displays hint text inside an input field.
Module-4 22
<input type="text" placeholder="Enter your name">
b) Disabled Input
Prevents users from editing the input field.
c) Readonly Input
Displays text that cannot be modified but can be selected.
d) Required Attribute
Ensures the field must be filled before submitting the form.
<label for="email"Email:</label>
<input type="email" id="email" name="email" required><br><br>
<label for="password"Password:</label>
<input type="password" id="password" name="password" required><br>
<br>
<label>Gender:</label>
Module-4 23
<input type="radio" id="male" name="gender" value="male">
<label for="male"Male</label>
<label for="country"Country:</label>
<select id="country" name="country">
<option value="usa"USA/option>
<option value="uk"UK/option>
<option value="india"India</option>
</select><br><br>
<label for="message"Message:</label>
<textarea id="message" name="message" rows="4"></textarea><br><br>
1. What is CSS?
CSS defines how HTML elements should be displayed on a webpage. It controls
aspects like:
Colors
Module-4 24
Fonts
Layouts
Spacing
Animations
Example:
!DOCTYPE html>
<html>
<head>
<style>
h1
color: blue;
font-size: 24px;
}
</style>
</head>
<body>
</head>
<body>
<h1Hello, CSS!/h1
</body>
</html>
In this example, the <h1 element is styled with blue color and a font size of 24px.
Module-4 25
✅ Reducing Code Duplication Centralized stylesheets apply styles to multiple
elements, reducing redundancy.
3. Types of CSS
a) Inline CSS
Applied directly inside an HTML element using the style attribute.
<head>
<style>
<head>
<style>
p{
color: green;
font-size: 16px;
}
</style>
</head>
<head>
<link rel="stylesheet" href="styles.css">
Module-4 26
</head>
selector {
property: value;
}
Example:
h1
color: blue;
font-size: 24px;
}
font-size: 24px;
}
Module-4 27
CSS makes websites responsive using media queries, allowing layouts to adjust
for different devices.
º This changes the background color when the screen width is less than
600px.
1. Inline CSS
1. Inline CSS
✅ Applied directly within an HTML element using the style attribute.
Advantages:
✔ Quick and easy for small changes.
Does not require a separate CSS file.
Disadvantages:
Module-4 28
✅ Defined inside a tag within the
<style> <head> section of an HTML document.
!DOCTYPE html>
<html>
<head>
<style>
h1
color: blue;
text-align: center;
}
p{
font-size: 16px;
color: green;
}
</style>
</head>
</style>
</head>
<body>
<h1Welcome to CSS/h1
<p>This paragraph is styled using internal CSS.</p>
</body>
</html>
Advantages:
Module-4 29
✅ Stored in a separate file and linked to the HTML file using the tag.
.css <link>
Ideal for large websites as it keeps the design consistent across multiple
pages.
Example:
HTML File ( index.html )
!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1Welcome to External CSS/h1
<p>This paragraph is styled using an external CSS file.</p>
</body>
</html>
h1
color: blue;
text-align: center;
}
p{
font-size: 18px;
color: green;
}
Advantages:
✔ Keeps HTML and CSS separate, making code cleaner and easier to maintain.
Allows for consistent styling across multiple pages.
Improves website performance as styles are cached by the browser.
Module-4 30
Disadvantages:
Stored in a
Reusable, keeps Requires an
External CSS separate .css Large websites
HTML clean additional file
file
Selectors, Properties, and Values in CSS
CSS Cascading Style Sheets) is used to style HTML elements by selecting them
and applying properties with specific values.
1. Selectors
A CSS Selector is used to target HTML elements that need to be styled.
Types of Selectors:
Å Element Selector Selects HTML elements by tag name.
p{
color: blue;
}
Module-4 31
Æ Class Selector Selects elements with a specific class ( . ).
.highlight {
background-color: yellow;
}
#header {
font-size: 24px;
}
h1, h2, p {
text-align: center;
h1, h2, p {
text-align: center;
}
a:hover {
color: green;
}
Module-4 32
Changes link color to green when hovered.)
2. Properties
A CSS Property defines what aspect of an element to style.
Examples:
3. Values
A CSS Value is assigned to a property to specify its effect.
3. Values
A CSS Value is assigned to a property to specify its effect.
Examples:
p{
color: blue; /* Property: color, Value: blue */
font-size: 20px; /* Property: font-size, Value: 20px */
background-color: yellow; /* Property: background-color, Value: yellow */
}
Module-4 33
font-size: 28px;
}
!DOCTYPE html>
!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1Welcome to CSS/h1
<p id="main-content"This is a paragraph inside the main content area.</p
>
<p class="highlight"This is a highlighted paragraph.</p>
</body>
</html>
Module-4 34
1. CSS Box Model
The Box Model represents how every HTML element is structured in terms of
spacing and dimensions. It consists of:
.box {
width: 200px;
height: 100px;
padding: 10px;
border: 5px solid black;
margin: 20px;
}
margin: 20px;
}
Module-4 35
' justify-content: Aligns items horizontally (left, center, space-between, etc.).
.container {
display: flex;
flex-direction: row;
justify-content: space-around;
align-items: center;
}
.box {
width: 100px;
height: 100px;
background-color: lightblue;
text-align: center;
background-color: lightblue;
text-align: center;
}
HTML:
<div class="container">
<div class="box"1/div>
<div class="box"2/div>
<div class="box"3/div>
</div>
Module-4 36
' display: grid; Enables Grid on a container.
.grid-container {
display: grid;
grid-template-columns: 1fr 1fr 1fr; /* 3 equal columns */
grid-gap: 10px;
}
.grid-item {
background-color: lightcoral;
text-align: center;
padding: 20px;
text-align: center;
padding: 20px;
}
HTML:
<div class="grid-container">
<div class="grid-item"1/div>
<div class="grid-item"2/div>
<div class="grid-item"3/div>
<div class="grid-item"4/div>
<div class="grid-item"5/div>
<div class="grid-item"6/div>
</div>
Module-4 37
Responsive Design and Media Queries in CSS
Responsive design ensures that web pages look good on all devices, from
desktops to smartphones. Media Queries help apply different styles based on
screen size, resolution, or device type.
@media (condition) {
/* CSS rules */
}
Module-4 38
/* Default styles for larger screens */
.container {
width: 80%;
margin: auto;
}
Ë This adjusts the containerʼs width and font size based on screen size.
3. Common Breakpoints for Responsive Design
Breakpoints define at what screen width the design should change. Here are some
standard breakpoints:
✔ Large Screens Desktops, Laptops) → min-width: 1024px
Module-4 39
/* Default menu for larger screens */
.navbar {
display: flex;
justify-content: space-between;
}
/* Mobile-friendly navigation */
@media (max-width: 600px) {
.navbar {
flex-direction: column;
text-align: center;
}
}
' Use rem or em for font sizes instead of px for better scalability.
img {
max-width: 100%;
height: auto;
}
Module-4 40
Example: Responsive Grid
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 10px;
}
Ë This creates a flexible grid layout that adjusts based on screen width.
Introduction to JavaScript and Its Importance in Web
Development
What is JavaScript?
JavaScript JS is a high-level, interpreted programming language used to make
web pages interactive and dynamic. It runs in the browser and allows developers
to add functionality beyond static HTML and CSS.
to add functionality beyond static HTML and CSS.
Client-Side Functionality Runs in the browser, reducing the need for server
requests.
Event Handling Responds to user actions (clicks, form submissions,
keyboard inputs).
Manipulation of HTML & CSS Changes web page content and styles
dynamically.
Asynchronous Operations Supports AJAX and Fetch API for real-time
updates without reloading the page.
Module-4 41
2. Where is JavaScript Used?
' Front-End Development Adds interactivity (e.g., form validation, animations,
responsive menus).
!DOCTYPE html>
<html lang="en">
<head>
<title>JavaScript Example</title>
</head>
<body>
<h1 id="message"Hello, World!/h1
<button onclick="changeText()"Click Me</button>
<script>
function changeText() {
document.getElementById("message").innerHTML "Hello, JavaScrip
t!";
}
</script>
Module-4 42
</body>
</html>
Ë When the button is clicked, the text changes dynamically using JavaScript.
4. JavaScript Features
✔ Lightweight & Fast Runs directly in the browser without additional setup.
Cross-Platform Works on all modern web browsers.
Object-Oriented Uses objects and prototypes for flexibility.
Asynchronous Programming Supports promises and async/await for non-
blocking execution.
Form validation,
Example Headings, paragraphs Colors, layouts
animations
Module-4 43
JavaScript has many libraries and frameworks that simplify development:
1. Variables in JavaScript
A variable is a container used to store data values.
Declaring Variables
JavaScript provides three ways to declare variables:
var Global or function-scoped (older method, avoid using).
var Global or function-scoped (older method, avoid using).
Example
Module-4 44
✔ Boolean → ortrue false
3. Operators in JavaScript
Operators perform operations on variables and values.
Module-4 45
+ Addition a+b 15
- Subtraction a-b 5
* Multiplication a*b 50
/ Division a/b 2
** Exponentiation a ** 2 100
Example
let sum 10 5; // 15
let product 10 5; // 50
Example ( a 10, b =
Operator Description Result
5)
Example ( a 10, b =
Operator Description Result
5)
== Equal to a == b false
Example
Module-4 46
Logical Operators (Combine multiple conditions)
` ` OR
! NOT !a false
Example
+= x 5 x=x5
-= x 5 x=x5
*= x * 5 x=x*5
/= x / 5 x=x/5
Example
Module-4 47
Syntax
Example
1. Functions in JavaScript
A function is a reusable block of code designed to perform a specific task.
1. Functions in JavaScript
A function is a reusable block of code designed to perform a specific task.
Functions help reduce code duplication and improve readability.
Declaring a Function
Syntax
function functionName(parameters) {
// Code to execute
return value; // Optional
}
function greet(name) {
return "Hello, " + name + "!";
Module-4 48
}
console.log(greet("Alice")); // Output: Hello, Alice!
Types of Functions
Å Function with Parameters and Return Value
function add(a, b) {
return a + b;
}
console.log(add(5, 3)); // Output: 8
Module-4 49
(function() {
console.log("This function runs immediately!");
})();
2. JavaScript Events
An event is an action or occurrence triggered by a user (e.g., clicking, typing) or
the browser (e.g., page load, error).
Module-4 50
Ç Example: Changing Text on Button Click
<button id="changeText"Click Me</button>
<p id="text"Hello!/p>
<script>
document.getElementById("changeText").addEventListener("click", function()
{
document.getElementById("text").innerHTML "Text Changed!";
});
</script>
<script>
let text = document.getElementById("hoverText");
<script>
let text = document.getElementById("hoverText");
text.addEventListener("mouseover", function() {
text.style.color = "red";
});
text.addEventListener("mouseout", function() {
text.style.color = "black";
});
</script>
<script>
Module-4 51
document.getElementById("username").addEventListener("keyup", function()
{
let input = this.value;
let errorMsg = document.getElementById("error");
if (input.length 3
errorMsg.innerHTML "Username must be at least 3 characters!";
errorMsg.style.color = "red";
} else {
errorMsg.innerHTML "";
}
});
</script>
Å getElementById() – Select by ID
Finds a single element using its id .
Module-4 52
Returns a collection (array-like list) of elements with the specified class.
<p>Paragraph 1/p>
<p>Paragraph 2/p>
<p>Paragraph 1/p>
<p>Paragraph 2/p>
Module-4 53
let allItems = document.querySelectorAll(".item");
allItems.forEach(item ⇒ item.style.color = "green");
document.getElementById("image").setAttribute("src", "new-image.jpg");
document.getElementById("box").style.backgroundColor = "lightblue";
Module-4 54
document.getElementById("box").style.fontSize = "20px";
document.getElementById("box").classList.add("new-class");
document.getElementById("box").classList.remove("old-class");
document.getElementById("demo").remove();
Module-4 55
Æ Changing Content on Click
document.getElementById("changeText").addEventListener("click", function()
{
document.getElementById("text").innerText = "Text Changed!";
});
<label for="email"Email:</label>
<input type="email" id="email">
Module-4 56
<small id="emailError" style="color: red;"></small>
<button type="submit"Submit</button>
</form>
Module-4 57
}
});
if (password.length 6
alert("Password must be at least 6 characters long!");
if (password.length 6
alert("Password must be at least 6 characters long!");
}
if (isNaN(age) || age 0
alert("Enter a valid number!");
}
Module-4 58
alert("Enter a 10-digit phone number!");
}
document.getElementById("name").addEventListener("input", function() {
if (this.value.trim() === "") {
document.getElementById("nameError").innerText = "Name cannot be e
mpty!";
} else {
document.getElementById("nameError").innerText = "";
}
});
document.getElementById("myForm").addEventListener("submit", function(ev
ent) {
if !isValid) {
event.preventDefault(); // Stops form from submitting
}
});
Module-4 59
text