HTML Basics and Practical Examples
HTML Basics and Practical Examples
<!DOCTYPE html>
<html>
<head>
<title>HTML Basics Practical</title>
</head>
<body>
<p>This webpage is created for the HTML practical to understand elements and
tags.</p>
<h2>About HTML</h2>
<p>HTML stands for HyperText Markup Language. It is used to create web pages.</p>
<h2>Example of Elements</h2>
<ul>
<li>Heading Element (h1, h2,...)</li>
<li>Paragraph Element (p)</li>
<li>List Element (ul, ol, li)</li>
<li>Image Element (img)</li>
</ul>
<h2>Example Image</h2>
<img src="[Link] alt="Sample Image">
<h2>Example Link</h2>
<a href="[Link] here to visit Google</a>
<hr>
<p>End of Practical.</p>
</body>
</html>
2. Practicing basic and advanced text for formatting.
<!DOCTYPE html>
<html>
<head>
<title>Text Formatting Practical</title>
</head>
<body>
<h2>Basic Formatting</h2>
<p>
1|Pa ge
<b>Bold Text</b><br>
<i>Italic Text</i><br>
<u>Underlined Text</u><br>
<strong>Strong (Important) Text</strong><br>
<em>Emphasized Text</em><br>
<small>Small Text Example</small><br>
Here is <mark>Highlighted</mark> text.<br>
Chemical Formula: H<sub>2</sub>O <br>
Math Expression: x<sup>2</sup> + y<sup>2</sup>
</p>
<h2>Advanced Formatting</h2>
<p>
<blockquote>
This is a long quotation written using the blockquote tag.
It is automatically indented by the browser.
</blockquote>
<h3>Code Example:</h3>
<code>[Link]("Hello World");</code><br><br>
<h3>Preformatted Text:</h3>
<pre>
This text preserves
spaces and
indentation exactly
as typed.
</pre>
<h3>BDO Example</h3>
Normal: Hello<br>
Reverse Text: <bdo dir="rtl">Hello</bdo>
</p>
</body>
</html>
2|Pa ge
3. Practice use of image, video and sound in HTML documents.
<!DOCTYPE html>
<html>
<head>
<title>Multimedia Practice</title>
</head>
<body>
<h1>Multimedia Demo</h1>
<h2>1. Image</h2>
<img src="[Link]" width="300" alt="Beautiful Flower">
<h2>2. Video</h2>
<video src="nature.mp4" width="400" controls></video>
<h2>3. Audio</h2>
<audio src="music.mp3" controls></audio>
</body>
</html>
4. Designing of web pages- Document layout, list, tables.
<!DOCTYPE html>
<html>
<head>
<title>Web Page Design Example</title>
</head>
<body>
<header>
<h1>ABC College</h1>
</header>
<nav>
<a href="#">Home</a> |
<a href="#">Departments</a> |
<a href="#">Admissions</a>
</nav>
<section>
<h2>Departments</h2>
<ul>
<li>Computer Science</li>
<li>Mechanical</li>
<li>Civil Engineering</li>
</ul>
</section>
3|Pa ge
<section>
<h2>Student Result Table</h2>
<table border="1" cellpadding="8">
<tr>
<th>Name</th>
<th>Subject</th>
<th>Marks</th>
</tr>
<tr>
<td>Aryan</td>
<td>Math</td>
<td>88</td>
</tr>
<tr>
<td>Riya</td>
<td>Science</td>
<td>92</td>
</tr>
</table>
</section>
<footer>
<p>© 2025 ABC College</p>
</footer>
</body>
</html>
5. Practicing Hyperlink of web pages, working with frames.
<!DOCTYPE html>
<html>
<head>
<title>Hyperlink Practice</title>
<style>
body {
font-family: Arial;
background: #f2f2f2;
}
.nav {
background: #333;
padding: 10px;
}
.nav a {
color: white;
margin-right: 15px;
text-decoration: none;
font-weight: bold;
}
a:hover {
color: yellow;
}
4|Pa ge
</style>
</head>
<body>
<h1>Welcome to My Webpage</h1>
<h2>Types of Hyperlinks</h2>
<ul>
<li><a href="#section1">Jump to Section 1 (Internal
Link)</a></li>
<li><a href="[Link]">Go to About Page</a></li>
<li><a href="[Link]">Open Contact Page</a></li>
<li><a href="[Link] Email</a></li>
<li><a href="[Link] Us</a></li>
<li><a href="[Link] target="_blank">Visit
Wikipedia</a></li>
<li><a href="[Link]">
<img src="[Link]" width="150" height="100" alt="Click
Me">
</a> (Image Hyperlink)</li>
</ul>
</body>
</html>
File 2: [Link]
<!DOCTYPE html>
<html>
<head>
<title>About Us</title>
</head>
<body style="font-family: Arial;">
<h1>About Our Website</h1>
<p>This is the about page. Here we describe information about
us.</p>
File 3: [Link]
<!DOCTYPE html>
<html>
5|Pa ge
<head>
<title>Contact Page</title>
</head>
<body style="font-family: Arial;">
<h1>Contact Information</h1>
</body>
</html>
FRAMES EXAMPLE (HTML Frameset)
File 4: [Link]
<!DOCTYPE html>
<html>
<head>
<title>Frameset Example</title>
</head>
<frameset rows="20%,*">
</frameset>
</html>
File 5: [Link]
<!DOCTYPE html>
<html>
<head>
<title>Menu</title>
</head>
<body style="font-family: Arial;">
<h2>Navigation Menu</h2>
<ul>
<li><a href="[Link]" target="myframe">About</a></li>
<li><a href="[Link]" target="myframe">Contact</a></li>
<li><a href="[Link]" target="myframe">Home</a></li>
<li><a href="[Link]
target="myframe">Google</a></li>
</ul>
</body>
</html>
6|Pa ge
6. Working with forms and controls.
<!DOCTYPE html>
<html>
<head>
<title>HTML Form Example</title>
<style>
body {
font-family: Arial;
background: #f0f0f0;
}
form {
background: white;
padding: 25px;
width: 500px;
margin: 20px auto;
border-radius: 8px;
box-shadow: 0 0 10px #aaa;
}
label {
font-weight: bold;
}
input, select, textarea {
width: 95%;
padding: 8px;
margin: 6px 0 15px 0;
border-radius: 5px;
border: 1px solid #aaa;
}
.submit-btn {
width: 150px;
background: #4CAF50;
color: white;
border: none;
padding: 10px;
cursor: pointer;
border-radius: 5px;
}
.reset-btn {
width: 150px;
background: red;
color: white;
border: none;
padding: 10px;
cursor: pointer;
border-radius: 5px;
}
.controls {
7|Pa ge
width: 50%;
}
</style>
</head>
<body>
<fieldset>
<legend><b>Personal Information</b></legend>
<label>Full Name:</label>
<input type="text" name="fullname" required>
<label>Email:</label>
<input type="email" name="email" required>
<label>Password:</label>
<input type="password" name="password" required>
<label>Age:</label>
<input type="number" name="age" min="1" max="100">
</fieldset>
<fieldset>
<legend><b>Gender</b></legend>
<input type="radio" name="gender" value="Male"> Male
<br>
<input type="radio" name="gender" value="Female"> Female
<br>
<input type="radio" name="gender" value="Other"> Other
</fieldset>
<fieldset>
<legend><b>Hobbies</b></legend>
<input type="checkbox" name="hobby" value="Reading"> Reading <br>
<input type="checkbox" name="hobby" value="Sports"> Sports <br>
<input type="checkbox" name="hobby" value="Music"> Music <br>
<input type="checkbox" name="hobby" value="Travel"> Travel
</fieldset>
<label>Select Country:</label>
8|Pa ge
<select name="country">
<option value="India">India</option>
<option value="USA">USA</option>
<option value="Japan">Japan</option>
<option value="Australia">Australia</option>
</select>
<label>Date of Birth:</label>
<input type="date" name="dob">
<label>Select Color:</label>
<input type="color" name="favcolor">
<label>Experience (1 to 10):</label>
<input type="range" name="experience" min="1" max="10">
<label>Address:</label>
<textarea name="address" rows="4"></textarea>
<center>
<input type="submit" value="Submit Form" class="submit-btn">
<input type="reset" value="Reset" class="reset-btn">
</center>
</form>
</body>
</html>
7. Acquaintance with creating style sheet, CSS properties and styling.
<!DOCTYPE html>
<html>
<head>
<title>CSS Example</title>
9|Pa ge
h1 {
color: darkblue;
text-align: center;
font-size: 40px;
}
.box {
background-color: white;
width: 400px;
padding: 20px;
margin: 30px auto;
border: 3px solid black;
border-radius: 10px;
box-shadow: 0 0 10px gray;
}
p{
font-size: 18px;
color: #333;
text-align: justify;
}
.highlight {
color: red;
font-weight: bold;
text-decoration: underline;
}
.btn {
background-color: blue;
color: white;
padding: 10px;
border-radius: 5px;
text-align: center;
display: inline-block;
width: 150px;
}
.btn:hover {
background-color: darkblue;
cursor: pointer;
}
</style>
</head>
<body>
10 | P a g e
<h1>CSS Styling Example</h1>
<div class="box">
<p>This is an example of a <span class="highlight">CSS styled</span> web page.</p>
<p>We used background colors, padding, borders, margin, box-shadow, and font
styling.</p>
</body>
</html>
8. Working with background, text, font, list properties.
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: #e8e8e8;
background-image: url('[Link]
background-repeat: no-repeat;
background-attachment: fixed;
font-family: Arial;
h1 {
color: darkblue;
text-align: center;
text-decoration: underline;
text-transform: uppercase;
11 | P a g e
}
p{
color: #333;
text-align: justify;
line-height: 1.5;
text-indent: 40px;
.font-section {
font-size: 20px;
font-weight: bold;
font-style: italic;
color: #800000;
background-color: #fff5e6;
padding: 10px;
.custom-list {
background-color: white;
width: 300px;
padding: 15px;
border-radius: 10px;
.custom-list2 {
12 | P a g e
list-style-type: none; /* remove bullets */
padding: 0;
.custom-list2 li {
background-color: #d1e7fc;
padding: 8px;
margin-bottom: 5px;
border-radius: 5px;
.container {
width: 80%;
background-color: white;
padding: 20px;
border-radius: 15px;
</style>
</head>
<body>
<div class="container">
<p>
This paragraph shows the use of text properties like color, line spacing,
13 | P a g e
text alignment, and indentation. You can see how the text is neatly styled
using CSS.
</p>
<div class="font-section">
</div>
<ul class="custom-list">
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
<ul class="custom-list2">
<li>Web Design</li>
<li>Web Development</li>
<li>Database</li>
</ul>
</div>
</body>
</html>
14 | P a g e
<title>CSS Box Properties Example</title>
<style>
body {
font-family: Arial;
background-color: #f0f0f0;
}
/* MAIN BOX */
.box {
width: 400px; /* box width */
height: auto; /* height adjusts automatically */
background-color: white;
padding: 20px; /* inner spacing */
margin: 30px auto; /* center the box */
border: 5px solid black; /* border thickness, style, color */
border-radius: 15px; /* rounded corners */
box-shadow: 0 0 15px gray; /* outer shadow */
overflow: auto; /* show scroll if content overflows */
}
/* SECOND BOX */
.small-box {
width: 250px;
height: 150px;
padding: 10px;
margin: 20px auto;
background-color: #ffe7d1;
border: 3px dashed brown;
border-radius: 20px;
outline: 4px solid blue; /* outline outside border */
outline-offset: 5px; /* spacing between border & outline */
}
</style>
15 | P a g e
</head>
<body>
<div class="box">
<h2>Main Box Model</h2>
<p>
This box demonstrates the essential CSS box model features:
margin, padding, border, width, height, border-radius, and box-shadow.
</p>
<p>
The box is centered using <b>margin: auto</b> and has a white background
with a shadow effect to give a card-like appearance.
</p>
</div>
<div class="small-box">
<h3>Second Styled Box</h3>
<p>This box shows dashed borders, outlines, and rounded corners.</p>
</div>
</body>
</html>
10. Develop simple calculator for addition, subtraction, multiplication and division operation
using java script.
<!DOCTYPE html>
<html>
<head>
<title>Simple Calculator</title>
<style>
body {
font-family: Arial;
background-color: #f0f0f0;
}
.calculator {
width: 300px;
margin: 50px auto;
background: white;
16 | P a g e
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px gray;
}
input, button {
width: 90%;
padding: 10px;
margin: 8px 0;
font-size: 18px;
}
button {
background: blue;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
}
button:hover {
background: darkblue;
}
.result {
font-size: 22px;
font-weight: bold;
margin-top: 15px;
text-align: center;
}
</style>
</head>
<body>
<div class="calculator">
<h2 style="text-align:center;">Simple Calculator</h2>
17 | P a g e
<script>
function add() {
var n1 = parseFloat([Link]("num1").value);
var n2 = parseFloat([Link]("num2").value);
[Link]("result").innerHTML = "Result: " + (n1 + n2);
}
function sub() {
var n1 = parseFloat([Link]("num1").value);
var n2 = parseFloat([Link]("num2").value);
[Link]("result").innerHTML = "Result: " + (n1 - n2);
}
function mul() {
var n1 = parseFloat([Link]("num1").value);
var n2 = parseFloat([Link]("num2").value);
[Link]("result").innerHTML = "Result: " + (n1 * n2);
}
function div() {
var n1 = parseFloat([Link]("num1").value);
var n2 = parseFloat([Link]("num2").value);
if (n2 === 0) {
[Link]("result").innerHTML = "Error: Cannot divide by zero!";
} else {
[Link]("result").innerHTML = "Result: " + (n1 / n2);
}
}
</script>
</body>
</html>
11. Create HTML page with java script which takes integer number as a input and tells
whether the number is odd or even.
<!DOCTYPE html>
<html>
<head>
<title>Odd or Even Checker</title>
<script>
function checkNumber() {
// Get the value from input box
let num = [Link]("number").value;
// Convert to integer
18 | P a g e
num = parseInt(num);
<body>
<h2>Odd or Even Checker</h2>
<label>Enter a Number:</label>
<input type="text" id="number">
<button onclick="checkNumber()">Check</button>
<h3 id="result"></h3>
</body>
</html>
12. Create HTML page that contains form with fields name, Email, mobile number, gender,
favorite colour and button; now write a java script code to validate each entry. Also write
a code to combine and display the information in text box when button is clicked.
<!DOCTYPE html>
<html>
<head>
<title>Form Validation and Display</title>
<script>
function validateForm() {
// Getting values
let name = [Link]("name").[Link]();
let email = [Link]("email").[Link]();
let mobile = [Link]("mobile").[Link]();
// Name validation
if (name == "") {
19 | P a g e
alert("Please enter your name");
return false;
}
// Gender validation
if (gender === null) {
alert("Please select your gender");
return false;
}
// Color validation
if (color == "") {
alert("Please select your favorite color");
return false;
}
[Link]("result").value = resultText;
return true;
}
</script>
</head>
<body>
<h2>Form Validation Example</h2>
20 | P a g e
<form>
<label>Name:</label><br>
<input type="text" id="name"><br><br>
<label>Email:</label><br>
<input type="text" id="email"><br><br>
<label>Mobile Number:</label><br>
<input type="text" id="mobile"><br><br>
<label>Gender:</label><br>
<input type="radio" name="gender" value="Male"> Male
<input type="radio" name="gender" value="Female"> Female<br><br>
<label>Favorite Colour:</label><br>
<input type="color" id="color"><br><br>
<h3>Combined Information:</h3>
<textarea id="result" rows="7" cols="40"></textarea>
</body>
</html>
13. Write a PHP program to check if number is prime or not.
<?php
// Function to check prime
function isPrime($num) {
// 0, 1 and negative numbers are not prime
if ($num <= 1) {
return false;
}
// Input number
$number = 29;
if (isPrime($number)) {
echo "$number is a Prime Number";
21 | P a g e
} else {
echo "$number is NOT a Prime Number";
}
?>
14. Write a PHP program to print first ten Fibonacci numbers.
<?php
?>
15. Create a MySQL data base and connect with PHP.
22 | P a g e
Step 3: Create a PHP File to Connect with MySQL
<?php
$host = "localhost"; // MySQL server
$user = "root"; // MySQL username
$pass = ""; // MySQL password (blank in XAMPP/WAMP)
$db = "studentDB"; // Database name
// Create connection
$conn = new mysqli($host, $user, $pass, $db);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
16. V
USE userDB;
This file takes Name, Address, Email, Mobile number and stores them into MySQL.
<!DOCTYPE html>
<html>
<head>
<title>User Registration</title>
</head>
<body>
<h2>Register User</h2>
23 | P a g e
<form action="[Link]" method="POST">
Name: <input type="text" name="name" required><br><br>
Address: <input type="text" name="address" required><br><br>
Email: <input type="email" name="email" required><br><br>
Mobile: <input type="text" name="mobile" required><br><br>
<?php
if (isset($_POST["submit"])) {
if ($conn->connect_error) {
die("Connection Failed: " . $conn->connect_error);
}
$conn->close();
}
?>
</body>
</html>
$uppercaseName = strtoupper($name);
echo "Name in uppercase (string function): $uppercaseName <br>";
24 | P a g e
Step 3: [Link] (Display All Users in HTML Table)
This file retrieves and displays all user data from MySQL.
<!DOCTYPE html>
<html>
<head>
<title>Display Users</title>
</head>
<body>
<?php
// Step 1: Connect to database
$conn = new mysqli("localhost", "root", "", "userDB");
if ($conn->connect_error) {
die("Connection Failed: " . $conn->connect_error);
}
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['address']."</td>";
echo "<td>".$row['email']."</td>";
echo "<td>".$row['mobile']."</td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='5'>No Users Found</td></tr>";
}
$conn->close();
?>
</table>
</body>
</html>
25 | P a g e
17. Using HTML, CSS, JavaScript, PHP, MySQL, design a authentication module of a web
page.
Step 1: Create MySQL Database + Table
Run this SQL in phpMyAdmin:
CREATE DATABASE authDB;
USE authDB;
.container {
width: 350px;
margin: 80px auto;
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px gray;
}
input {
width: 100%;
padding: 10px;
margin: 8px 0;
}
button {
width: 100%;
padding: 10px;
background: blue;
border: none;
color: white;
cursor: pointer;
font-size: 16px;
}
button:hover {
background: darkblue;
26 | P a g e
}
.error {
color: red;
margin: 5px 0;
}
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$username = $_POST["username"];
$email = $_POST["email"];
$password = password_hash($_POST["password"], PASSWORD_DEFAULT);
if ($conn->query($sql)) {
echo "<script>alert('Registration Successful!');
[Link]='[Link]';</script>";
} else {
echo "<script>alert('Error: User already exists!!');</script>";
}
$conn->close();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>User Registration</title>
<link rel="stylesheet" href="[Link]">
</head>
<body>
<div class="container">
<h2>Register</h2>
<form method="post">
27 | P a g e
<input type="text" name="username" placeholder="Enter username" required>
<input type="email" name="email" placeholder="Enter email" required>
<input type="password" name="password" id="pass" placeholder="Enter password"
required>
</body>
</html>
if (isset($_POST['login'])) {
$username = $_POST["username"];
$password = $_POST["password"];
if ($result->num_rows == 1) {
$row = $result->fetch_assoc();
if (password_verify($password, $row['password'])) {
$_SESSION["username"] = $username;
header("Location: [Link]");
} else {
echo "<script>alert('Invalid Password');</script>";
}
} else {
echo "<script>alert('User Not Found');</script>";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<link rel="stylesheet" href="[Link]">
</head>
28 | P a g e
<body>
<div class="container">
<h2>Login</h2>
<form method="post">
<input type="text" name="username" placeholder="Enter username" required>
<input type="password" name="password" placeholder="Enter password" required>
</body>
</html>
if (!isset($_SESSION['username'])) {
header("Location: [Link]");
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
<link rel="stylesheet" href="[Link]">
</head>
<body>
<div class="container">
<h2>Welcome, <?php echo $_SESSION['username']; ?>!</h2>
<p>You are logged in.</p>
<a href="[Link]">
<button>Logout</button>
</a>
</div>
</body>
</html>
29 | P a g e
Step 6: [Link]
<?php
session_start();
session_destroy();
header("Location: [Link]");
?>
30 | P a g e