Lab Manual
Lab Manual
WEB TECHNOLOGIES
Submitted to:
MR ARBAB HAIDER
Submitted by:
Abdullah Amir
Section:
Roll Number:
2023-BSCS-151
• To learn the purpose of HTML tags like <html>, <head>, <title>, <body>, <h1>–<h6>, <p>
• To create, save, and run a simple webpage
• To practice modifying content and structure in HTML
Theoretical Description:
What is HTML?
HTML (HyperText Markup Language) is the standard language used to create webpages. It
was introduced by Tim Berners-Lee in 1991 and is the base of web development.
Key Features:
Uses tags to structure content.
Works on all operating systems with a browser.
Defines structure only (design and logic come from CSS & JavaScript).
Can be combined with other web technologies.
Basic Structure of an HTML Page
<!DOCTYPE html> → Defines HTML5.
<html> → Root element of the page.
<head> → Metadata and title (not visible).
<title> → Browser tab title.
<body> → Visible page content.
<h1> to <h6> → Headings, from large to small.
<p> → Paragraph text.
Lab Task(s)
Task 1: Creating Your First Webpage:
Abdullah Amir
2023--BSCS--151
My first webpage is designed using the basic structure of HTML. The head section includes a
title that appears on the browser tab. The body section contains the visible content of the
page. It starts with a main heading, followed by a short paragraph of text, and also includes a
link that opens another website when clicked. This simple example explains how HTML can
be used to create a basic webpage.
Example Explanation:
The heading at the top is like a page title shown in big and bold letters (e.g., Welcome
to My Webpage).
The paragraph is normal text that explains or gives information (e.g., This is my first
paragraph in HTML).
Abdullah Amir
2023--BSCS--151
Headings are used to organize and highlight content on a webpage. They make the text look
bigger and more important so that readers can quickly understand the main subject. Headings
also improve the design of the page and help in dividing information into clear sections.
Example Explanation:
The main heading is shown at the top in large bold letters (e.g., Welcome to My
Webpage).
Subheadings can be added under the main heading to divide topics.
Together, headings guide the reader and make the page easy to follow
Abdullah Amir
2023--BSCS--151
Paragraphs allow us to write text in a clear and organized way. Each paragraph starts on a
new line, which makes the content easier to read. Using multiple paragraphs helps separate
different ideas so that the page does not look messy or confusing.
Example Explanation:
One paragraph can introduce a topic (e.g., About Myself).
Another paragraph can explain more details about that topic.
Multiple paragraphs together make the content smooth and easy to understand.
Headings and paragraphs are often used together to create a well-structured webpage. A
heading introduces the main idea, while the paragraph explains it in detail. This combination
helps both in design and readability of the page.
Example Explanation
Abdullah Amir
2023--BSCS--151
The title of a webpage is shown on the browser tab. It tells the user what the page is about,
even before opening it. In this activity, only the title was changed, while the rest of the page
remained the same.
Example Explanation:
A title like About My City appears on the tab at the top.
Changing it to About Me shows a new name on the tab.
The title is small but important because it represents the whole page.
Abdullah Amir
2023--BSCS--151
In this activity, personal details were added to the webpage. Writing information such as
name, hobbies, and education made the page unique and personalized. It was a simple task
but useful to practice real-life content in HTML.
Example Explanation:
The name introduces the student (e.g., my name is Abdullah).
Hobbies describe interests like doing coding, reading, and playing cricket.
Education details show the background, such as grade or subjects studied.
Conclusion:
In these tasks, I learned how to make simple webpages using HTML. First, I created my first
webpage to understand the basic structure. Then I tried all six heading levels and saw their
size differences. I also added many paragraphs to practice writing content. After that, I
combined headings and paragraphs in one page. I changed the title tag to see how it updates
the browser tab. In the end, I made a profile page with my name, education, and hobbies.
Formatting Tags:
Used to style or separate text:
Bold, italic, underline, line breaks, and horizontal lines help structure and emphasize
content.
Lists:
Ordered lists show numbered items.
Unordered lists show bullet points.
Each item in a list is written as a list item.
Table-Based Layouts:
Tables organize content into rows and columns.
A table contains rows, and each row has header or data cells.
Tables can be used to design simple webpage layouts.
Lab Tasks:
Create a webpage that uses headings, paragraphs, bold, italic, and underline tags.
Insert an image with src, alt, width, and height attributes.
Add hyperlinks to at least two external websites (e.g., Google, YouTube).
<!DOCTYPE html>
<html>
<head>
<title>Practice Tags</title>
</head>
<body>
<h1>Welcome to My Page</h1>
<u>practicing tags</u>.</p>
</a> or <a
href="[Link]
</body>
</html>
Output:
ABDULLAH BIN AMIR
2023-CS-151
Explanation:
<h1>, <h2>, <h3>: Used for different heading levels.
<p>: Defines paragraphs of text.
<b>, <i>, <u>: Add bold, italic, and underline formatting.
<img>: Displays an image using src, alt, width, and height.
<a>: Creates hyperlinks to external websites.
Explanation:
This HTML document creates a Student Record Table with columns for Name, Roll No,
Course, and [Link] uses a <table> with a border and specified width, displaying four
student [Link] <tr> represents a row, and <th> tags define the table headers.
Explanation:
This HTML document creates a basic homepage layout using a table. It includes a header, a
left-side navigation menu, a main content area, and a footer. The page title is set to
"Homepage Layout", and the content includes links, a welcome message, and an image. The
table ensures all sections are aligned properly within a bordered structure.
Summary:
Lab 2 focused on practicing basic HTML tags, attributes, and layouts. Students learned to use
formatting tags like <b>, <i>, and <u>, and added images and hyperlinks using the <img>
and <a> tags. Ordered (<ol>) and unordered (<ul>) lists were created to organize content. A
student record table was designed using <table>, <tr>, <td>, and <th>. Finally, a simple
homepage layout was built using a table-based structure with navigation, content, and footer
sections. This lab built foundational skills for creating structured HTML webpages.
Lab 03
Inserting Images, Hyperlinks, and Applying Inline CSS
Objectives
To learn inserting and formatting images in webpages.
To explore different types of hyperlinks (internal, external, email, image links).
To apply inline CSS for controlling text, images, and layout.
To build a mini personal webpage combining images, links, and inline styling.
Theoretical Description:
Images in HTML
Images are added using the <img> tag.
Key attributes:
src – specifies the image path
alt – alternative text for accessibility
width and height – control image size
style – allows inline styling
To make an image clickable, wrap it inside an <a> tag.
Hyperlinks
Internal Links: Navigate to other pages within the same website or project folder.
External Links: Direct users to external websites using full URLs.
Email Links: Open the user's email app using [Link]
Image Links: Turn an image into a link by nesting it inside <a>
Inline CSS
Used with the style attribute to apply styles directly to HTML tags.
Common uses include changing text color, font, size, background color, borders, alignment,
and spacing.
Example:<p style="color: blue; font-size: 18px;">Styled text</p>
Lab Tasks
Task 1: Images with Inline CSS
• Insert two images:
o A local image with border and rounded corners.
o An online image resized using inline CSS.
• Align images (left/right) using inline CSS.
• Add alternate text for accessibility.
<!DOCTYPE html>
<html>
<head>
<title>Images with Inline CSS</title>
</head>
<body>
<img src="C:\Users\HP\Pictures\Saved Pictures\[Link]" alt="Local landscape photo"
style="border: 3px solid #555; border-radius: 10px; float: left;
width: 200px; margin-right: 15px;">
<img src="C:\Users\HP\Pictures\Saved Pictures\wallpaperflare.com_wallpaper (4).jpg"
alt="Placeholder image"
style="width: 200px; height: auto; float: right;">
</body>
</html>
Explanation:
The first image is a local file styled with a border, rounded corners, and aligned to the left
using float: left. The second is an online image, resized with width, and aligned to the right
using float: right. alt text improves accessibility by describing each image if it fails to load.
Explanation:
Internal link points to a local page [Link]. External links open in a new tab
(target="_blank") for safety and better UX. mailto: opens the user’s default email client with
the email address [Link] image wrapped inside an <a> tag makes it clickable, linking
to YouTube.
Explanation:
The header is styled with color and large font [Link] profile image has a solid border and
rounded to a [Link] intro paragraph uses background color and padding for
[Link] websites are listed with external links opening in new [Link] footer
includes an email link and copyright notice.
Summary:
Task 1: Added a local image with border and rounded corners, and an online image resized
and aligned using inline CSS with proper alt text. Task 2: Created internal, external, email,
and image-based hyperlinks for navigation and interaction. Task 3: Built a personal profile
page with a styled header, profile image, intro paragraph, and favorite website [Link]
a footer with an email link and copyright [Link] inline CSS throughout to apply layout,
styling, and formatting directly within HTML elements.
Sure. Here’s a shorter and completely rephrased version of your **Lab 04: Exploring CSS
Selectors and Internal CSS**, written simply and differently so it doesn’t match the original
or previous one:
What is CSS?
CSS (Cascading Style Sheets) controls how HTML elements look on a [Link] gives
structure (like headings or paragraphs), while CSS handles design such as color, font, size,
and layout.
html
<style>
p { color: blue; }
</style>
2. Class Selector:
Used for multiple elements with the same class name (use `.`).
css
.note { background: yellow; }
3. ID Selector:
Used for one specific element (use `#`).
css
#mainTitle { text-align: center; color: red; }
4. Group Selector:
Applies one style to several tags.
css
h1, h2, p { color: purple; }
5. Descendant Selector:
Targets elements inside another element.
css
div p { color: orange; }
Explanation:
ID Selector (#main-heading): Used to style one unique element such as the main title.
Added color, larger font, and underline.
Class Selectors (.info, .highlight):
Text & Borders: The heading is underlined, and paragraphs have rounded borders with
spacing inside.
Task 1: Built lab4_task1.html using internal CSS to style the body, headings, and paragraphs
with custom colors, fonts, and layout improvements.
Task 3: Designed [Link] featuring personal details with group and descendant selectors,
link hover effects, and a styled container with padding, color, and rounded corners.
Here’s a completely rewritten and shorter **unique version** of your **Lab 05: Div-Based
Layouts Using Box Model and External CSS** — same meaning, fresh wording, and more
natural flow:
Lab 05: Div-Based Layouts with Box Model and External CSS
Objectives
Understand how the CSS Box Model works.
Build webpage layouts using div containers.
Use external CSS for cleaner and reusable styling.
Learn how margins, borders, padding, and dimensions affect layout design.
Concept Overview
Div-Based Layouts:
In modern web development, the `<div>` tag is the main container used to organize and
group webpage content.
It’s a block-level element, meaning it stretches across the page’s full width and always
begins on a new line.
A `<div>` can include many types of content, such as:
Text and headings
Images or icons
Forms and input fields
Other HTML elements
External CSS:
External CSS keeps the webpage clean by separating design from structure.
You write the CSS in a separate file (e.g., `[Link]`) and connect it to the HTML using the
<link> tag:
html
<link rel="stylesheet" href="[Link]">
This approach makes it easier to update or reuse styles across multiple webpages.
Abdullah [Link]:
<!DOCTYPE html>
<div id="main">
<html lang="en">
<div id="content">
<head>
<h2>Main Content</h2>
<meta charset="UTF-8">
<p>Hy My name is Abdullah
<meta name="viewport"
Amir. How loves to do something creative
content="width=device-width, initial-
and learning skills </p>
scale=1.0">
</div>
<title>Lab 05 - Div Layout</title>
<link rel="stylesheet" href="Abdullah
<div id="sidebar">
[Link]">
<h3>Sidebar</h3>
</head>
<p>Follow me on Instagram.</p>
<body>
<p>Follow me on X.</p>
<p>Follow me on Facebook.</p>
<div id="header">
<p>Message me on Whatsapp.
<h1>My Website</h1>
Here is my Number</p>
</div>
</div>
</div>
<div id="nav">
<ul>
<div id="footer">
<li><a href="#">Home</a></li>
<p>© 2025 Abdullah Amir
<li><a href="#">About</a></li>
Website. All rights reserved.</p>
<li><a href="#">Services</a></li>
</div>
<li><a href="#">Contact</a></li>
</ul>
</body>
</div>
</html>
Abdullah [Link]:
/* General body styling */ font-family: Arial, sans-serif;
body { background-color: #f8f8f8;
margin: 0; }
/* Header */ /* Main content and sidebar layout */
#header { #main {
background-color: #0b97e7; display: flex;
color: white; margin: 20px;
text-align: center; gap: 20px;
padding: 20px; }
}
/* Content area */
/* Navigation bar */ #content {
#nav { flex: 3;
background-color: #333; background-color: #fff;
} padding: 20px;
border: 1px solid #ccc;
#nav ul { border-radius: 8px;
list-style-type: none; }
margin: 0;
padding: 0; /* Sidebar */
overflow: hidden; #sidebar {
} flex: 1;
background-color: #f1f1f1;
#nav li { padding: 20px;
float: left; border: 1px solid #ccc;
} border-radius: 8px;
}
#nav li a {
display: block; /* Footer */
color: white; #footer {
padding: 14px 20px; background-color: #333;
text-decoration: none; color: white;
} text-align: center;
padding: 15px;
#nav li a:hover { margin-top: 20px;
background-color: #111; }
}
Explanation:
You set up the page structure by using separate <div> blocks for the header, navigation bar,
main content, sidebar, and footer.
Each part is placed in its own section so the page stays organized.
The main content and sidebar sit next to each other because of CSS floats.
The footer is pushed to the bottom with a clear rule so it doesn’t overlap.
All styling is moved to an external CSS file to keep the HTML clean.
Task 2: Style the Layout with External CSS and Box Model:
In the [Link] file, every <div> is styled using Box Model properties.
You control the layout by setting width, padding, borders, and margins.
Different background colors help you see how each section is spaced.
Extra text and font styling improves readability.
Changing padding and margin values helps you understand how spacing affects the page
layout.
[Link]:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Website</title>
<link rel="stylesheet" href="Abdullah [Link]">
</head>
<body>
<div class="header">
<h1>My Website</h1>
</div>
<div class="navbar">
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Services</a>
<a href="#">Contact</a>
</div>
<div class="content">
<h2>Welcome to My Website</h2>
<p>External CSS allows designers to keep HTML separate from styling rules.</p>
</div>
<div class="sidebar">
<h3>Sidebar</h3>
<p>MNS-UET.</p>
</div>
<div class="footer">
© 2025 My Website. ABDULLAH AMIR.
</div>
</body>
</html>
[Link]:
/* General Reset */
body {
margin: 0;
font-family: Arial, sans-serif;
background: #ffffff;
}
/* Header */
.header {
background: #44a1f1;
color: white;
text-align: center;
padding: 20px 0;
}
/* Navigation Bar */
.navbar {
background: #4c75a0;
text-align: center;
padding: 10px 0;
}
.navbar a {
color: white;
margin: 0 15px;
text-decoration: none;
font-weight: bold;
}
/* Main Content */
.content {
width: 65%;
float: left;
padding: 15px;
background: white;
border-right: 1px solid #ddd;
min-height: 160px; /* Short height */
}
/* Sidebar */
.sidebar {
width: 30%;
float: right;
padding: 15px;
background: #f2f2f2;
min-height: 160px; /* Short height */
}
/* Footer */
.footer {
clear: both;
background: #65adec;
color: white;
text-align: center;
padding: 15px;
margin-top: 10px;
Explanation:
The webpage uses divs for the header, navbar, main content, sidebar, and footer. The header
and navbar have dark blue backgrounds with centered text. Main content and sidebar sit side
by side, with content on the left and a light sidebar on the right. Padding and colors keep it
neat, and the footer clears floats. All styling is in external CSS for organization and easy
maintenance.
Task 3: Responsive Div-Based Layout:
Divide the page into a two-column layout one for content and one for sidebar.
Use CSS float or flexbox to align divs side by side.
Add a header and footer that stretch across the full width.
Use external CSS classes to style similar elements consistently.
Test your webpage in a browser to ensure the layout adjusts properly and looks neat.
[Link]:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Div Layout</title>
<link rel="stylesheet" href="Abdullah [Link]">
</head>
<body>
<header class="main-header">
<h1>My Portfolio</h1>
</header>
<div class="container">
<div class="content">
<h2>Main Content Area</h2>
<p>
Hy, My name is Abdullah Amir. I am a student of CS 2023. I love coding and
design
</p>
</div>
<aside class="sidebar">
<h3>Sidebar</h3>
<p>MNS UET.</p>
<p>CS.</p>
</aside>
</div>
<footer class="main-footer">
<p>© 2025 Abdullah Amir. All Rights Reserved.</p>
</footer>
</body>
</html>
[Link]:
body {
margin: 0;
font-family: "Poppins", sans-serif;
background: #faf7f2; /* very soft cream */
}
.main-footer {
border-top: 3px solid #e6c1ad;
}
/* Page Layout */
.container {
display: flex;
gap: 22px;
padding: 25px;
}
/* Main Content */
.content {
flex: 3;
background: #ffffff;
padding: 20px;
border-radius: 8px;
border-left: 5px solid #f2d6c3;
box-shadow: 0 4px 12px rgba(0,0,0,0.04);
color: #4a4a4a;
}
/* Sidebar */
.sidebar {
flex: 1;
background: #e8f3f1; /* soft mint-teal */
padding: 20px;
border-radius: 8px;
border: 2px solid #c9e1de; /* very gentle teal-grey border */
box-shadow: 0 4px 12px rgba(0,0,0,0.04);
color: #3f5050;
}
/* Responsive for Mobile */
@media (max-width: 768px) {
.container {
flex-direction: column;
}
}
Summary:
Task 1:
The page layout was created using several div containers to organize each section.
Styling was handled through external CSS, where colors, spacing, and layout adjustments
were applied. Float properties placed the main content and sidebar next to each other, while
the footer stayed in place using clear. Keeping structure in HTML and design in CSS made
the code easier to maintain.
Concept Overview
CSS positioning controls where elements appear on a webpage and how they interact with
other elements.
The main types include:
Static: Default positioning; elements follow the normal flow of the page.
Relative: Moves the element relative to its normal position using top, bottom, left, or right.
Absolute: Places the element relative to the nearest positioned ancestor, or the page if none
exists.
Fixed: Keeps the element in a fixed spot on the screen, visible even while scrolling.
Dropdown Menu:
A dropdown menu allows users to select from a hidden list that appears on hover or click.
It is commonly used in website navigation bars to organize links neatly and improve user
experience.
Tools Used:
Text Editor: Visual Studio Code
Browser: Google Chrome
Languages: HTML5 and CSS3
Abdullah [Link]:
body { width: 150px;
font-family: Arial, sans-serif; height: 80px;
margin: 20px; margin: 15px 0;
} padding: 10px;
color: white;
/* Box styling for positioning */ font-weight: bold;
.box { text-align: center;
line-height: 60px;
border-radius: 5px; /* Dropdown Menu */
} .dropdown {
position: relative;
/* Positioning examples */ display: inline-block;
.static { margin-top: 40px;
position: static; }
background-color: #4CAF50;
} .dropbtn {
background-color: #333;
.relative { color: white;
position: relative; padding: 12px 20px;
top: 20px; font-size: 16px;
left: 30px; border: none;
background-color: #2196F3; cursor: pointer;
} border-radius: 4px;
}
.absolute {
position: absolute; .dropdown-content {
top: 100px; display: none;
right: 50px; position: absolute;
background-color: #FF5722; background-color: #f9f9f9;
} min-width: 140px;
box-shadow: 0px 8px 16px
rgba(0,0,0,0.2);
.fixed {
z-index: 1;
position: fixed;
border-radius: 4px;
bottom: 20px;
}
right: 20px;
background-color: #9C27B0;
.dropdown-content a {
}
color: black;
padding: 10px 14px; display: block;
text-decoration: none; }
display: block; .dropdown:hover .dropbtn {
} background-color: #555;
}
.dropdown-content a:hover {
background-color: #ddd;
}
.dropdown:hover .dropdown-content {
Explanation:
Four <div> boxes demonstrate static, relative, absolute, and fixed positioning.
Static: Follows normal page flow.
Relative: Moves from its original position without affecting other elements.
Absolute: Positioned relative to the nearest positioned ancestor.
Fixed: Stays visible even when scrolling.
<nav class="navbar">
Abdullah [Link]:
<ul>
/* General body styling */
<li><a href="#">Home</a></li>
body {
<li><a href="#">About</a></li>
margin: 0;
<li><a href="#">Services</a></li>
font-family: Arial, sans-serif;
<li><a href="#">Contact</a></li>
}
</ul>
</nav>
/* Fixed Navigation Bar */
.navbar { .navbar a {
z-index: 1000; }
padding: 0; }
display: flex;
} .content {
Abdullah .html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lab 06 - Positioning & Dropdown</title>
<link rel="stylesheet" href="Abdullah [Link]">
</head>
<body>
<!-- Fixed Navigation Bar -->
<nav class="navbar">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<!-- Dropdown Menu -->
<li class="dropdown">
<a href="#">Services</a>
<ul class="dropdown-content">
<li><a href="#">Web Design</a></li>
<li><a href="#">Web Development</a></li>
<li><a href="#">SEO</a></li>
</ul>
</li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
<!-- Content -->
<div class="content">
<h1>Welcome to Our Website</h1>
<p>Scroll down to observe fixed positioning and interact with the dropdown menu
under Services.</p>
<div style="height: 800px;"></div>
</div>
</body>
</html>
[Link]:
/* General Body */
body {
margin: 0;
font-family: Arial, sans-serif;
}
/* Fixed Navigation */
.navbar {
position: fixed;
top: 0;
width: 100%;
background-color: #333;
padding: 12px 0;
z-index: 1000;
}
.navbar ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
}
.navbar li {
position: relative; /* Required for dropdown positioning */
margin: 0 15px;
}
.navbar a {
color: white;
text-decoration: none;
padding: 8px 12px;
display: block;
transition: background-color 0.3s;
}
.navbar a:hover {
background-color: #555;
border-radius: 4px;
}
/* Dropdown Menu */
.dropdown-content {
display: none;
position: absolute;
top: 100%;
left: 0;
background-color: #444;
min-width: 160px;
border-radius: 4px;
overflow: hidden;
transition: all 0.3s ease;
}
.dropdown-content li a {
padding: 10px 14px;
color: white;}
.dropdown-content li a:hover {
background-color: #666;}
.dropdown:hover .dropdown-content {
display: block; }
/* Content Below Navbar */
.content {
margin-top: 60px; /* Offset for fixed navbar */ padding: 20px;}
Task 3:
The “Services” menu has a hidden list (<ul> and <li>) that appears on hover using CSS.
Smooth transitions improve user experience.
Links inside the dropdown highlight on hover for clarity and interactivity.
Theoretical Overview
1. Shadows:
CSS3 provides two main types of shadow effects:
Text Shadow: Adds colored or blurred shadows behind text.
Box Shadow: Creates soft, lifted, or glowing effects around elements like cards or
containers.
2. Gradients:
Gradients blend multiple colors smoothly and remove the need for background images.
Linear Gradient: Color flow happens in a straight direction (vertical, horizontal, diagonal).
Radial Gradient: Colors spread outward from a center point.
3. Transitions:
Transitions allow CSS properties to animate smoothly when the user interacts with an
[Link] can transition color changes, size adjustments, rotations, or hover effects.
Tools Used:
VS Code
Chrome / Edge
HTML5 + CSS3
Lab Tasks
Task 1 – Working With Shadows:
You will create headings and boxes, then apply different shadow styles to produce depth and
3D effects.
[Link]:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Lab 07 - CSS Shadows</title>
<link rel="stylesheet" href="[Link]">
</head>
<body>
<h1 class="shadow-title">CSS3 Shadow Effects</h1>
<h2 class="soft-text">Soft Text Shadow Example</h2>
<div class="card basic-shadow">
Simple box shadow applied to this container.
</div>
<div class="card glow-shadow">
Glowing shadow effect using multiple layers.
</div>
</body>
</html>
[Link]:
body {
font-family: Arial, sans-serif;
padding: 30px;
}
/* Text Shadows */
.shadow-title {
font-size: 40px;
text-shadow: 3px 3px 8px rgba(0,0,0,0.4);
}
.soft-text {
text-shadow: 1px 1px 4px #888;
}
/* Box Shadows */
.card {
width: 300px;
padding: 20px;
margin: 20px 0;
background: #fafafa;
border-radius: 8px;
}
/* Basic Shadow */
.basic-shadow {
box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}
/* Glowing Multiple Shadow Effect */
.glow-shadow {
box-shadow:
0 0 10px #7f5cff,
0 0 20px #7f5cff,
0 0 30px #7f5cff;}
Task 1 Explanation:
Text shadows are applied with different blur levels and offsets.
Box shadows range from soft elevation to glowing neon effects.
Multiple shadows create a 3D or luminous look.
[Link]:
Html is same as the task 1
[Link]:
body {
font-family: Arial, sans-serif;
padding: 30px;
}
/* Linear Gradient Header */
.header-gradient {
padding: 25px;
text-align: center;
font-size: 26px;
color: white;
background: linear-gradient(to right, #ff512f, #dd2476, #4b2cf1);
border-radius: 8px;
}
/* Button Gradient */
.btn-gradient {
padding: 12px 30px;
border: none;
margin-top: 20px;
cursor: pointer;
color: white;
border-radius: 6px;
background: linear-gradient(to bottom, #1e9600, #fff200, #ff0000);
}
Task 2 Explanation:
A linear gradient creates smooth color flow across the header.
A button is styled with three color stops for a professional look.
A radial gradient produces a circular blended color effect.
[Link]:
Html is same as the task 1
[Link]:
/* Transition Button */
.transition-btn {
padding: 12px 25px;
background: #3498db;
color: white;
border: none;
border-radius: 6px;
transition: all 0.4s ease;
cursor: pointer;
display: inline-block;
margin-top: 20px;
}
.transition-btn:hover {
background: #2ecc71;
transform: scale(1.1);
border-radius: 20px;
}
/* Transition Card */
.transition-card {
width: 300px;
padding: 20px;
margin-top: 30px;
background: #f0f0f0;
border-radius: 8px;
transition: box-shadow 0.5s, transform 0.5s;
}
.transition-card:hover {
box-shadow: 0 10px 20px rgba(0,0,0,0.3);
transform: translateY(-10px);
}
Task 3 Explanation:
The button changes color, size, and shape smoothly on hover.
The card lifts up and gains a stronger shadow, creating a floating effect.
transition-duration and timing-function make the animations smooth.
Concept Overview:
Normally, CSS handles static design. Colors, spacing, and fonts stay the same unless the page
reloads. JavaScript adds flexibility by allowing style changes while the page is running. This
is done through the DOM, which gives JavaScript access to every element on the page.
For example, clicking a button can switch its background color, or hovering over a paragraph
can increase its font size. These changes happen immediately because JavaScript is
modifying the CSS in response to the user.
Tools Used:
• Text Editor: Visual Studio Code
• Browser: Google Chrome or Microsoft Edge
• Languages: HTML5, CSS3, JavaScript (ES6)
LAB TASK:
Task 1: Updating CSS Styles with JavaScript:
Start by creating a new project folder and name it “Lab08_JS_CSS”.
Add three files inside this folder: [Link], [Link], and [Link].
In the HTML file, place a heading, a short paragraph, and a button on the page.
Write a JavaScript function that will change the text color and font size as soon as the
user clicks the button.
Run the page in your browser and watch how the style updates immediately without a
reload.
[Link]:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lab 08 JS + CSS</title>
<link rel="stylesheet" href="Abdullah [Link]">
</head>
<body>
<h1 id="mainHeading">Welcome to Dynamic Styling</h1>
<p id="textPara">This text will change when you click the button.</p>
<button id="styleBtn">Change Style</button>
<script src="Abdullah [Link]"></script>
</body>
</html>
[Link]:
body {font-family: Arial, sans-serif;
padding: 20px;}
#styleBtn { padding: 10px 18px;
cursor: pointer;}
[Link]:
[Link]("styleBtn").addEventListener("click", function () {
const heading = [Link]("mainHeading");
const para = [Link]("textPara");
[Link] = "Teal";
[Link] = "36px";
[Link] = "brown";
[Link] = "22px";});
Task 2: Adding and Removing CSS Classes:
Open your [Link] file and create two separate classes, such as. theme-light and
.theme-dark, each with its own color style.
Add a new button in your HTML page with the label “Switch Theme”.
In your JavaScript file, write code that switches between the two classes whenever the
button is pressed.
Load the page and check if the background and text colors shift smoothly when you
click the button.
This gives you a basic idea of how websites create light and dark mode experiences.
Lab 8 task [Link]:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Theme Toggle Example</title>
<link rel="stylesheet" href="Abdullah [Link]">
</head>
<body id="pageBody" class="theme-light">
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Interactive Boxes</title>
</head>
<body>
</body>
</html>
lab 8 task [Link]:
body {
padding: 20px;}
.box {
width: 150px;
height: 150px;
margin: 15px;
display: inline-block;
background-color: #f0f0f0;
line-height: 150px;
text-align: center;
font-weight: bold;
cursor: pointer;
.box:hover {
[Link](box => {
[Link]("mouseover", function() {
});
[Link]("mouseout", function() {
});
[Link]("click", function() {
});
Explanation:
Dynamic Text Styling:
Clicking “Change Text Style” updates the heading and paragraph colors and font sizes
instantly.
Theme Toggle:
Clicking “Switch Theme” toggles between light and dark mode.
Smooth background and text color transitions are applied.
Interactive Boxes:
Each of the three boxes changes to a different color on hover.
Hover effect includes a slight zoom for better visual feedback.
Clicking any box shows an alert with its name.
Summary:
You created a webpage that shows how CSS and JavaScript work together for dynamic
styling. First, you made a button that changes the text color and font size instantly through
JavaScript. After that, you built two themes and used a theme switch button to toggle their
CSS classes, giving a light and dark mode effect. Finally, you added multiple interactive
elements and used events like hover and click to change their styles, with transitions to keep
everything smooth and responsive.
Event Handling:
JavaScript detects user actions and calls functions in response.
Popular events include click, mouseover, mouseout, keydown, and submit.
Events make the page feel interactive and dynamic.
Tools Used:
Visual Studio Code for writing code.
Google Chrome / Microsoft Edge for testing the output.
HTML, CSS, JavaScript for structure, styling, and functionality.
Task 1:
1. Create a new folder named "Lab09_DOM" to store the project files.
2. Inside the folder, add three files: [Link], [Link], and [Link].
3. Add several basic elements in the HTML file such as headings, paragraphs, and a
button.
4. Use different DOM selection methods inside JavaScript to target these elements.
5. When the page loads, update the text, background color, and font size of selected
elements.
6. Notice how these updates appear immediately because JavaScript interacts directly
with the DOM.
[Link]:
<!DOCTYPE html>
<html>
<head>
<title>Lab 09 DOM</title>
<link rel="stylesheet" href="lab 9 task [Link]">
</head>
<body>
<h1 id="header">Original Heading</h1>
<p class="para">My name is Abdullah.</p>
<p class="para">This is My code.</p>
<button id="btn">Change Heading Color</button>
<script src="lab 9 task [Link]"></script>
</body>
</html>
[Link]:
body {
font-family: Arial, Helvetica, sans-serif;}
[Link]:
// Selecting elements
const header = [Link]("header");
const paragraphs = [Link]("para");
const button = [Link]("#btn");
// Apply changes when the page loads
[Link] = () => {
[Link] = "DOM Manipulation Example";
[Link] = "skyblue";
[Link] = "32px";
paragraphs[0].textContent = "This text was updated using class selection.";
paragraphs[1].[Link] = "purple";
};
// Extra action on button click
[Link]("click", () => {
[Link] = "purple";
});
Explanation:
You create a folder with three files: HTML, CSS, and JavaScript.
The HTML page has headings, paragraphs, and buttons.
In JavaScript, you select these elements using methods like getElementById, querySelector,
and others.
When the page loads, the script changes text, colors, and font sizes so you can see how the
DOM updates elements directly.
Task 2:
1. Add several buttons to your HTML page with labels such as "Change Color",
"Change Text", and "Hide Element".
2. Inside your JavaScript file, create separate functions that react when each button is
pressed.
3. Each button should perform a different action, for example:
The Change Color button updates the background color of a paragraph.
The Change Text button replaces the text inside a heading.
The Hide Element button toggles the visibility of a chosen element.
4. Use the addEventListener() method to attach the click events, which keeps the code
structured and easy to maintain.
5. Test each button to see how clicking triggers instant changes on the webpage.
[Link]:
<!DOCTYPE html>
<html>
<head>
<title>Task 2 - Click Events</title>
<link rel="stylesheet" href="lab 9 task [Link]">
</head>
<body>
<h2 id="title2">Click Event Demonstration</h2>
<p id="box">My name is Abdullah.</p>
<div class="button-row">
<button id="btnColor">Change Background</button>
<button id="btnText">Change Heading Text</button>
<button id="btnHide">Toggle Visibility</button>
</div>
<script src="lab 9 task [Link]"></script>
</body>
</html>
[Link]:
// Selecting elements
const heading = [Link]("title2");
const paragraph = [Link]("box");
const btnColor = [Link]("btnColor");
const btnText = [Link]("btnText");
const btnHide = [Link]("btnHide");
// Change paragraph background color
[Link]("click", () => {
[Link] = "#6f966fff";
});
// Change heading text
[Link]("click", () => {
[Link] = "Hy i am Changed!";
});
// Hide or show the paragraph
[Link]("click", () => {
if ([Link] === "none") {
[Link] = "block";
[Link] = "Hide Element";
} else {
[Link] = "none";
[Link] = "Show Element";}});
[Link]:
body {
font-family: Arial, sans-serif;
padding: 20px;}
#box {
padding: 12px;
background-color: #f5eeee;
margin-bottom: 20px;
border-radius: 5px;}
.button-row button {
padding: 10px 14px;
margin-right: 8px;
cursor: pointer;}
Explanation:
You add buttons such as Change Color, Change Text, and Hide Element.
Each button triggers a different function when clicked.
You use addEventListener to attach these actions cleanly.
This shows how clicks can change styles, update text, or hide parts of the page.
Task 3:
1. Add an input box and a button labeled *"Show Greeting"* to the page.
2. When the user types their name and clicks the button, your JavaScript should display
a personalized greeting.
3. Use the value property to collect whatever the user typed in the input field.
4. Use textContent or innerHTML to display the greeting message on the page.
5. Add simple CSS to style the input, button, and greeting to make the interface look
clean and pleasant.
6. This shows how user input and DOM manipulation work together to create real,
interactive features.
[Link]:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Greeting App</title>
<link rel="stylesheet" href="lab 9 task [Link]">
</head>
<body>
<h2>Greeting App</h2>
<input id="nameInput" type="text" placeholder="Enter your name">
<button id="showBtn">Show Greeting</button>
<p id="greeting"></p>
<script src="lab 9 task [Link]"></script>
</body>
</html>
[Link]:
body {
font-family: Arial, sans-serif;
padding: 40px;}
input {
padding: 8px 10px;
font-size: 16px;
margin-right: 8px;}
button {
padding: 9px 14px;
font-size: 16px;
cursor: pointer;}
#greeting {
margin-top: 20px;
font-size: 20px;
color: #252121;}
[Link]:
const btn = [Link]("showBtn");
const input = [Link]("nameInput");
const greetingBox = [Link]("greeting");
[Link]("click", function () {
const name = [Link]();
if (name === "") {
[Link] = "Please type your name.";
return;}
[Link] = "Hello " + name + "! Nice to see you.";});
Explanation:
You create an input box and a Show Greeting button.
The script reads the user’s name with the value property and displays a greeting using
innerHTML or textContent.
Simple styling makes the form look better.
This demonstrates how user input and events work together.
Summary:
Across these tasks you work with the most important parts of the DOM.
You start by selecting elements and changing their text, colours, and sizes, which helps you
understand how JavaScript controls the content of a page.
Then you move to event handling, where buttons respond to clicks and trigger different
updates, showing how users can interact with the page in real time.
Finally, you connect input fields with output, letting users type information and see
personalized results. Together, these steps give you a solid foundation in building interactive
pages that react to user actions and update themselves through JavaScript.
Lab 10: Title: Creating Animations and Interactive Elements with
DOM Methods
Objectives
• Understand how to use JavaScript DOM methods to create animation effects.
• Learn how to control an element’s position, size, and opacity through dynamic style
changes.
• Create interactive visual behavior that responds to user clicks and actions.
• Practice using timing tools such as setInterval() and setTimeout().
Concept Overview
Adding motion to elements on a webpage makes the experience more lively and interactive.
With the DOM, JavaScript can update an element’s style while the page is running. By
repeatedly adjusting properties like left, top, width, or opacity, you can create smooth
animation effects.
JavaScript provides timing functions that help run code at specific intervals:
• setInterval() runs a block of code again and again after a fixed delay.
• setTimeout() runs code once after a given time.
• You can also activate CSS transitions by changing classes or styles with JavaScript.
These tools let you animate elements without relying on external libraries.
Tools Used
• Editor: Visual Studio Code
• Browser: Google Chrome
• Languages: HTML, CSS, JavaScript
let position = 0;
let animationId = null;
[Link]("click", function () {
if (animationId === null) {
animationId = setInterval(moveBox, 10);
}
});
[Link]("click", function () {
clearInterval(animationId);
animationId = null;
});
function moveBox() {
position += 2;
[Link] = position + "px";
[Link]:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="container">
<div class="buttons">
</div>
</div>
</body>
</html>
[Link]:
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
padding-top: 40px;}
.container {
text-align: center;}
#photo {
width: 200px;
height: auto;
transition: width 0.3s ease;}
button {
padding: 8px 14px;
margin: 10px;
cursor: pointer;
font-size: 15px;}
[Link]:
const img = [Link]('photo');
const grow = [Link]('growBtn');
const shrink = [Link]('shrinkBtn');
[Link]('click', () => {
let current = [Link];
[Link] = current + 20 + "px";
});
[Link]('click', () => {
let current = [Link];
if (current > 60) {
[Link] = current - 20 + "px";}});
Explanation:
In this task you place an image on the page and connect two buttons to it. When the Increase
button is pressed, the JavaScript code raises the image width by a small amount. Pressing the
Decrease button does the opposite, but only until the image reaches a reasonable minimum.
The CSS uses a transition so the size change looks smooth instead of instantly jumping. This
lets you resize the image interactively in a gradual and clean way.
1. Add a paragraph to the page and include any short text inside it.
2. Use setInterval() to slowly lower the text’s opacity from fully visible to completely
transparent.
3. After it fades out, bring the opacity back up so the text becomes visible again,
repeating this cycle continuously.
4. Use a mix of style updates and timing functions to keep the fade transition smooth
and steady.
[Link]:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="lab 10 task [Link]">
</head>
<body>
<p id="fadeText">Hy, It is Abdullah Amir.</p>
<script src="lab 10 task [Link]"></script>
</body>
</html>
[Link]:
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
padding-top: 60px;}
#fadeText {
font-size: 22px;
opacity: 1;
transition: opacity 0.3s ease;}
[Link]:
let text = [Link]("fadeText");
let opacity = 1;
let fadingOut = true;
setInterval(() => {
if (fadingOut) {
opacity -= 0.02;
if (opacity <= 0) {
opacity = 0;
fadingOut = false;}
} else {
opacity += 0.02;
if (opacity >= 1) {
opacity = 1;
fadingOut = true;}}
[Link] = opacity;}, 30);
Explanation:
In this activity you add a paragraph to the page and then use JavaScript to shift its opacity up
and down. The setInterval() function runs repeatedly, slowly lowering the opacity until the
text becomes invisible. Once it reaches zero, the code increases the opacity again, making the
text appear. The CSS transition helps keep the fade motion smooth instead of sharp. This
loop creates a continuous fade-out and fade-in effect.
Summary:
In these exercises, you first create a colored box that moves horizontally across the screen
using setInterval(), controlled with Start and Stop buttons, showing live position changes in
the DOM. Next, you place an image with “Increase Size” and “Decrease Size” buttons, using
JavaScript to dynamically adjust its width while CSS transitions make the resizing smooth.
Finally, you add a paragraph whose opacity is gradually changed in a loop with setInterval(),
creating a continuous fade-out and fade-in effect, with CSS transitions ensuring the text fades
smoothly.
Objectives:
Gain a foundational understanding of the Bootstrap framework.
Learn how to use the grid system to build layouts that adapt to different screen sizes.
Utilize pre-designed Bootstrap components to craft visually appealing web pages.
Develop webpages that automatically adjust their layout across desktops, tablets, and mobile
devices.
Theoretical Overview:
Bootstrap is an open-source CSS toolkit that allows developers to create responsive, mobile-
friendly websites efficiently. It offers pre-styled elements, layouts, and components such as
buttons, navigation bars, forms, modals, and cards.
The Bootstrap Grid System splits a webpage into 12 columns, making it easy to align and
resize content for various devices.
Using Bootstrap minimizes the need for extensive custom CSS and ensures a consistent,
polished look across all screen sizes.
[Link]:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bootstrap Layout Example</title>
<!-- Bootstrap 5 CDN -->
<link href="[Link]
rel="stylesheet">
<link rel="stylesheet" href="lab 11 task [Link]">
</head>
<body>
<div class="container">
<header class="bg-primary text-white text-center p-3">
<h1>My Responsive Page</h1>
</header>
<div class="row my-3">
<div class="col-md-8 bg-light p-3">
<p>Abdullah Amir</p>
</div>
<div class="col-md-4 bg-secondary text-white p-3">
<p>Designer </p>
</div>
</div>
<footer class="bg-dark text-white text-center p-3">
<p>Footer Section</p>
</footer>
</div>
</body>
</html>
[Link]:
body {
font-family: Arial, sans-serif;}
header, footer {
border-radius: 5px;}
.row > div {
border-radius: 5px;}
Explanation
In this exercise, a new HTML page is created with the Bootstrap 5 framework linked via
CDN. The layout includes a header at the top, two columns in the middle (a main content
area and a sidebar), and a footer at the bottom. The .container class keeps the content
centered, .row defines horizontal groups of columns, and .col-md-* sets the column widths
for medium and larger screens. When you resize the browser, the columns stack
automatically on smaller screens, demonstrating Bootstrap’s responsive grid system.
Task 2
Create a simple top navigation menu using Bootstrap. Include links for Home, About, and
Contact. Apply Bootstrap color utilities to adjust the look, and make sure the menu turns into
a collapsible toggle button on smaller screens.
[Link]:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bootstrap Navbar</title>
<link href="[Link]
rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-dark custom-nav">
<div class="container">
<a class="navbar-brand text-white" href="#">Abdullah Amir</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-
target="#mainNav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="mainNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link text-white" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="#">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
<script src="[Link]
script>
</body>
</html>
Explanation:
This navigation bar uses Bootstrap’s built-in navbar component. The navbar-expand-lg class
makes the menu collapse on smaller screens and expand normally on larger devices. The
links for Home, About, and Contact are placed inside a ul aligned to the right. The
background is set using Bootstrap’s bg-dark, and text colors are kept white for contrast. The
CSS adds a light hover effect and bolds the site title.
Task 3:
Build a responsive section that displays cards using Bootstrap. Each card should show an
image, a title and a short description. Arrange the cards in a row that adjusts nicely on
different screen sizes.
[Link]:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bootstrap Cards</title>
<link href="[Link]
rel="stylesheet">
</head>
<body>
<div class="container my-5">
<div class="row g-4">
<div class="col-md-4">
<div class="card h-100">
<img src="C:\Users\HP\Pictures\Saved Pictures\[Link]" class="card-img-top"
alt="Image 1">
<div class="card-body">
<h5 class="card-title">Info</h5>
<p class="card-text">Hy My name is Abdullah Amir.</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card h-100">
<img src="C:\Users\HP\Desktop\CV and works\best [Link]" class="card-img-
top" alt="Image 2">
<div class="card-body">
<h5 class="card-title">Work</h5>
<p class="card-text">Here is the design i made recently for my client.</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card h-100">
<img src="C:\Users\HP\Desktop\CV and works\Work\[Link]" class="card-img-top"
alt="Image 3">
<div class="card-body">
<h5 class="card-title">Work</h5>
<p class="card-text">An Ai thmubnail i made for my client for his Youtube
video.</p>
</div>
</div>
</div>
</div>
</div>
<script src="[Link]
script>
</body>
</html>
Explanation:
This layout uses Bootstrap’s grid system to place the cards in three equal columns on desktop.
Each card includes an image, a title and a short paragraph. The row and col-md-4 classes
allow the cards to stack automatically on smaller screens like tablets and phones. The
optional CSS only makes sure images stay neatly cropped. If you skip the CSS, everything
still works.
Summary:
In the first task you set up a basic page using Bootstrap’s grid system. You created a header, a
two-column layout and a footer. Those sections respond to screen size changes because of
Bootstrap classes like container, row and different column sizes.
In the second task you added a navigation bar at the top of the page. You used Bootstrap’s
navbar component to include links for Home, About and Contact. You applied built-in color
classes and made sure the menu switches to a toggle button on smaller screens.
In the third task you built a section that shows multiple cards. Each card includes an image, a
title and a short description. The cards sit in a responsive row so they adjust automatically on
desktop, tablet and mobile.
[Link]:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Registration Form</title>
<link rel="stylesheet" href="lab 12 task [Link]">
</head>
<body>
<h2 class="heading">User Registration</h2>
<p id="error-summary" class="error-summary"></p>
<form id="regForm">
<div class="input-group">
<label>Full Name</label>
<input type="text" id="name">
<small class="error"></small>
</div>
<div class="input-group">
<label>Email Address</label>
<input type="email" id="email">
<small class="error"></small>
</div>
<div class="input-group">
<label>Password</label>
<input type="password" id="password">
<small class="error"></small>
</div>
<div class="input-group">
<label>Confirm Password</label>
<input type="password" id="confirmPassword">
<small class="error"></small>
</div>
<div class="input-group">
<label>Gender</label>
<input type="radio" name="gender" value="Male"> Male
<input type="radio" name="gender" value="Female"> Female
<small class="error"></small>
</div>
<div class="input-group">
<label>Age</label>
<input type="number" id="age">
<small class="error"></small>
</div>
<button type="submit" id="submitBtn">Submit</button>
<button type="button" id="resetBtn">Reset</button>
<button type="button" id="demoBtn">Demo Fill</button>
</form>
<p id="result"></p>
<script src="lab 12 task [Link]"></script>
</body>
</html>
[Link]:
body {
font-family: Arial, sans-serif;
background: #e5ffea; /* light green background */
padding: 20px;}
.heading {
color: #2d7a39;}
.input-group {
margin-bottom: 15px;}
input {
width: 100%;
padding: 7px;
border: 2px solid #8cd48a;
border-radius: 5px;}
button {
padding: 8px 15px;
margin-right: 10px;
background: #8cd48a;
border: none;
border-radius: 5px;
cursor: pointer;}
button:hover {
background: #6fbf6d;}
.error {
color: red;
font-size: 13px;}
.error-summary {
color: red;
font-weight: bold;}
[Link]:
[Link]("regForm").addEventListener("submit", validateForm);
function validateForm(event) {
[Link]();
let isValid = true;
let summary = [];
clearErrors();
let name = [Link]("name");
let email = [Link]("email");
let pass = [Link]("password");
let confirm = [Link]("confirmPassword");
let age = [Link]("age");
let gender = [Link]("input[name='gender']:checked");
if ([Link]() === "") {
setError(name, "Name cannot be empty");
[Link]("Name is missing");
isValid = false;
}
let emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if () {
setError(email, "Invalid email format");
[Link]("Email is invalid");
isValid = false;
}
if ([Link] < 6) {
setError(pass, "Password must be at least 6 characters");
[Link]("Password is too short");
isValid = false;
}
if ([Link] !== [Link]) {
setError(confirm, "Passwords do not match");
[Link]("Password mismatch");
isValid = false;
}
if ([Link] < 13 || [Link] === "") {
setError(age, "Age must be 13 or above");
[Link]("Age requirement not met");
isValid = false;
}
if (!gender) {
[Link](".input-group")[4].querySelector(".error").innerText =
"Select gender";
[Link]("Gender not selected");
isValid = false;
}
[Link]("error-summary").innerText = [Link](" | ");
if (isValid) {
submitForm();}}
function setError(input, message) {
[Link] = message;
}
function clearErrors() {
[Link](".error").forEach(e => [Link] = "");
[Link]("error-summary").innerText = "";}
EXPLANATION:
In this task, we create a complete registration form and connect it with JavaScript. Every field
is validated to ensure the user enters correct information. The script checks empty fields,
invalid emails, weak passwords, mismatched passwords, wrong age, and missing gender.
[Link]:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Task 2 - Form Submission</title>
<link rel="stylesheet" href="lab 12 task [Link]">
</head>
<body>
<h1>Registration Form</h1>
<div id="message"></div>
<form id="registrationForm">
<label for="name">Name:</label>
<input type="text" id="name"><br>
<label for="email">Email:</label>
<input type="text" id="email"><br>
<label for="age">Age:</label>
<input type="number" id="age"><br>
<label>Gender:</label>
<input type="radio" name="gender" value="Male" id="male"> Male
<input type="radio" name="gender" value="Female" id="female"> Female<br>
<button type="submit" id="submitBtn">Submit</button>
<span id="loading" style="display:none;">Submitting...</span>
</form>
<script src="lab 12 task [Link]"></script>
</body>
</html>
[Link]:
body {
font-family: Arial, sans-serif;
padding: 20px;
background-color: #e5ffea; /* very light green background */}
label {
display: inline-block;
width: 80px;
margin-top: 10px;}
input {
margin-bottom: 10px;}
#message {
margin-bottom: 15px;
font-weight: bold;
color: green; /* light green success messages */}
#loading {
margin-left: 10px;
color: blue;}
[Link]:
[Link]('registrationForm').addEventListener('submit', handleSubmit);
function handleSubmit(event) {
[Link]();
submitForm();}
function submitForm() {
const submitBtn = [Link]('submitBtn');
const loading = [Link]('loading');
const messageDiv = [Link]('message');
// Disable button and show loading
[Link] = true;
[Link] = 'inline';
[Link] = '';
const name = [Link]('name').[Link]();
const email = [Link]('email').[Link]();
const age = [Link]('age').[Link]();
const gender = [Link]('input[name="gender"]:checked')?.value;
const payload = { name, email, age, gender };
fetch('[Link] {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: [Link](payload)})
.then(response => [Link]())
.then(data => {
[Link] = 'green';
[Link] = `Success! ID: ${[Link]}, Name: ${[Link]}`;})
.catch(error => {
[Link] = 'red';
[Link] = 'Submission failed. Try again.'; })
.finally(() => {
[Link] = false;
[Link] = 'none'; });}
EXPLANATION:
This task teaches how to send form data to a test server using a POST request. The Fetch API
sends your form details as JSON and returns a fake ID. During the process, the button is
disabled and shows a loading message to prevent duplicate submissions. Once the response
arrives, the page displays a confirmation message.
[Link]:
same as task 1
[Link]:
same as task 1
[Link]:
// Grab elements
// Event listeners
[Link]('submit', handleSubmit);
[Link]('click', resetForm);
[Link]('click', demoFill);
// Submit function
function handleSubmit(event) {
[Link] = 'green';
// Reset function
function resetForm() {
function demoFill() {
[Link]('email').value = "test@[Link]";
[Link]('password').value = "Test@123";
[Link]('confirmPassword').value = "Test@123";
[Link]('age').value = 20;
[Link]('male').checked = true;
[Link] = 'green';
[Link] = "Demo data filled ✔";}
EXPLANATION:
This task improves user convenience. The Reset button clears the entire form and removes
error messages. The Demo Fill button automatically enters valid sample data, which helps in
quick testing. Both buttons work smoothly because they are connected through event
listeners.
Summary:
The three tasks together create a functional registration form. Task 1 handles input validation,
ensuring fields like name, email, password, gender, and age are correctly filled and showing inline
error messages with a summary for any issues. Task 2 simulates sending the form data to an API,
displaying a loading indicator, disabling the submit button during the request, and showing success
or error messages based on the response. Task 3 enhances usability with Reset and Demo Fill buttons
to clear the form or automatically fill it with valid sample data, while keeping a light green theme for
background and messages, making the form both user-friendly and visually consistent.
LAB 13:
Connecting to SQL Database and Retrieving Data
Objective:
This lab teaches how a website communicates with a database. You will learn how to store
student information in MySQL, connect it with PHP, display the data on a web page, and
allow users to search for records.
In real applications, data is not written directly inside web pages. Instead, it is stored in
databases, and PHP is used to fetch and manage that data securely.
Tools and Environment Used:
Before starting, we need a proper development setup.
XAMPP is used because it provides:
Apache, which runs PHP files
MySQL, which stores data
phpMyAdmin, which helps manage databases easily
Visual Studio Code is used to write PHP and HTML code.
Chrome browser is used to test the output.
Explanation:
The focus of this task is to present database data in a readable and user-friendly way. Raw
database data is not useful unless it is properly displayed. HTML tables help organize the data
clearly, and error handling ensures the page does not appear broken when no data exists.
Summary:
In this lab, we first created a MySQL database and table, then connected PHP to the database.
We retrieved student data and displayed it in an HTML table. Finally, we added a search
feature that allows users to filter student records securely. Through this lab, you learned the
basics of backend and frontend integration, which forms the foundation of real-world PHP-
based web applications.