Module 5
Module 5
HTML BASICS
• Basic Structure: HTML documents consist of a <head> for meta-information and a <body> for
the visible content.
• Titles: The <title> tag in the <head> defines the page title, which appears in the browser tab.
• Text Structuring: Use <p> for paragraphs and <br> for line breaks to control text flow.
• Headings: Six levels of headings (<h1> to <h6>) organize content by importance.
• Text Formatting: Change text size and color using heading tags or inline styles.
• Images: The <img> tag embeds images, with src for the image path and alt for alternative text.
• Links: The <a> tag creates hyperlinks to other pages or resources.
• Alignment: CSS properties like text-align and margin:auto; align text and images.
• Iframes: The <iframe> tag embeds other web pages within the current page.
<html>
<head>
<title>My First Web Page</title>
</head>
<body>
<h1>Welcome to My Web Page</h1>
<p>This is a paragraph</p>
</body>
</html>
Definition:
HTML (Hypertext Markup Language) is the standard language used to create and design web
pages. It consists of various elements represented by tags, which can be enhanced with attributes
to define their properties and behavior.
1. <html>
o Description: The root element that contains all other HTML elements.
o Example:
2. <head>
o Description: Contains meta-information about the document, such as title, links to
stylesheets, and scripts.
o Example:
<head>
<title>Page Title</title>
</head>
3. <title>
o Description: Sets the title of the web page, displayed on the browser's title bar or
tab.
o Example:
4. <body>
o Description: Contains the content of the web page, including text, images, links,
etc.
o Example:
<body>
<h1>Hello, World!</h1>
</body>
5. <h1> to <h6>
o Description: Heading tags define headings of different levels, with <h1> being the
highest and <h6> the lowest.
o Example:
<h1>This is a Heading</h1>
<h2>This is a Subheading</h2>
6. <p>
o Description: Defines a paragraph of text.
o Example:
<p>This is a paragraph.</p>
7. <a>
o Description: Creates a hyperlink to another page or resource.
o Attributes:
▪ href: Specifies the URL of the page the link goes to.
o Example:
8. <img>
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
<ol>
<li>First Item</li>
<li>Second Item</li>
</ol>
10. <li>
o Description: Represents a list item in both ordered and unordered lists.
o Example:
<li>List Item</li>
11. <div>
o Description: A block-level container for grouping content.
o Example:
<div>
<p>This is a paragraph inside a div.</p>
</div>
12. <span>
o Description: An inline container used to mark up a part of a text or a document.
o Example:
Common Attributes
• id
o Description: Assigns a unique identifier to an HTML element.
o Example:
<div id="uniqueId">Content</div>
• class
• style
o Description: Applies inline CSS styles directly to an element.
o Example:
• title
o Description: Provides additional information about an element, often displayed as a
tooltip on hover.
o Example:
• target
o Description: Specifies how to open the linked document.
o Example:
Concept:
• Every HTML document begins with a structure that includes a <head> and a <body> section.
• The <title> tag, placed inside the <head>, defines the title of the web page, which is displayed
on the browser tab, bookmarks, and search engine results.
HTML Code:
<html>
<head>
<title>My First Web Page</title>
</head>
<body>
<h1>Welcome to My Web Page</h1>
</body>
</html>
Output: Explanation:
2. Controlling the Flow of Text with Paragraph and Line Break Tags
Concept:
• HTML provides tags to control the flow and structure of text. The <p> tag is used to create
paragraphs, adding a block-level space before and after the content.
• The <br> tag creates a line break within text, without starting a new paragraph.
HTML Code:
Output:
Explanation:
3. Changing the Size of Text Using Heading Level Tags and the Font Tag size Attribute
• Definition: Used to define headings in an HTML document. The numbers indicate the
importance and size, where <h1> is the most important (largest) and <h6> is the least
important (smallest).
• Example: <h1>Heading 1</h1> renders a large text for titles or main headings.
• <h1>: Main title or most important heading (e.g., page or article title).
• <h2>: Subheading, used for sections under the main heading.
• <h3>: Subheading, used for subsections within an <h2> section.
• <h4>: Subheading, used for subsections within an <h3> section.
• <h5>: Subheading, used for subsections within an <h4> section.
• <h6>: Least important heading, typically used for small, less important subsections.
• Definition: An older HTML tag used to change the appearance of text, such as its size,
color, and font family. Although outdated, it's still valid in older HTML documents.
• Example: <font size="4">This text is medium-sized</font>. This tag changes the size of text
based on values from 1 (smallest) to 7 (largest).
3. size Attribute
• Definition: An attribute used within the <font> tag to control the text size. It takes numeric
values from 1 (smallest) to 7 (largest).
• Example: <font size="3">This text is medium-sized</font> changes the font size to a
medium size.
Example
<!DOCTYPE html>
<html>
<head>
<title>Text Size Example</title>
</head>
<body>
<!-- Heading tags from largest to smallest -->
<h1>Heading 1: The largest heading</h1>
<h2>Heading 2: Slightly smaller than h1</h2>
<h3>Heading 3: Mid-sized heading</h3>
<h4>Heading 4: Smaller than h3</h4>
<h5>Heading 5: Second smallest heading</h5>
<h6>Heading 6: The smallest heading</h6>
Output :
The <font> tag allows you to specify the color using the color attribute. However, this method is
deprecated in modern HTML and should generally be avoided.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Change Text Color with Font Tag</title>
</head>
<body>
<font color="red">This text is red.</font><br>
<font color="blue">This text is blue.</font>
</body>
</html>
Output:
Using CSS (Cascading Style Sheets) is the modern and preferred way to change text color in HTML.
You can use the style attribute directly in the HTML tags or define the styles in a separate CSS
section or file.
▪ a. Inline CSS
This method applies the color directly to the HTML element using the style attribute.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Change Text Color with Inline CSS</title>
</head>
<body>
<p style="color: red;">This text is red.</p>
<p style="color: blue;">This text is blue.</p>
</body>
▪ b. Internal CSS
This method allows you to define the text color inside a <style> block within the <head> section of
the document.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Change Text Color with Internal CSS</title>
<style>
p {
color: green; /* All paragraphs will be green */
}
h1 {
color: navy; /* All h1 headings will be navy */
}
</style>
</head>
<body>
<h1>Case Study Report</h1>
<p>This is a sample paragraph in green text.</p>
</body>
</html>
In this method, the CSS code is stored in a separate file, and the HTML file references it. This is the
most scalable and maintainable approach.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="[Link]">
<title>Change Text Color with External CSS</title>
</head>
<body>
<h1>Report Overview</h1>
<p>This is a sample paragraph with styles from an external CSS
file.</p>
</body>
</html>
h1 {
color: purple;
}
p {
Summary:
Concept:
• The <img> tag embeds images into a web page. The src attribute specifies the path to the image,
while the alt attribute provides alternative text for accessibility and when the image cannot be
displayed.
HTML Code:
Output:
Explanation:
Output
CSS provides the text-align property, which is the modern way to align text.
<html>
<head>
<title>Align Text with CSS</title>
<style>
.left-align {
text-align: left;
}
.center-align {
text-align: center;
}
.right-align {
text-align: right;
}
</style>
</head>
<body>
<p class="left-align">This text is left-aligned.</p>
<p class="center-align">This text is center-aligned.</p>
<p class="right-align">This text is right-aligned.</p>
</body>
</html>
You can align images using the HTML align attribute or CSS for modern web development.
The align attribute could be used with <img> to align images relative to surrounding text or page
layout.
<!DOCTYPE html>
<html>
<head>
<title>Align Image with Attribute</title>
</head>
<body>
<img src="[Link]" align="left" alt="Sample Image" width="200" height="150">
<p>This text wraps around the image.</p>
</body>
</html>
Output:
For better control and modern usage, CSS float and text-align properties are used to align images.
<!DOCTYPE html>
<html>
<head>
<title>Align Image with CSS</title>
<style>
.left-image {
float: left;
margin-right: 10px;
}
.center-image {
display: block;
margin-left: auto;
margin-right: auto;
}
.right-image {
float: right;
Aligning multimedia elements in HTML allows images, videos, and audio to be positioned
relative to surrounding text or page layout, enhancing content flow and user experience.
<html>
<head>
<title>Align Video with Attribute</title>
</head>
<body>
<video src="sample-video.mp4" align="right" width="320" height="240"
controls>
</video>
<p>This text wraps around the video.</p>
</body>
</html>
Output:
Although align is not supported on <audio> elements in HTML5, here’s an example for the sake of
understanding:
<html>
<head>
<title>Align Audio with Attribute</title>
</head>
<body>
<audio src="sample-audio.mp3" align="left" controls>
Your browser does not support the audio element.
</audio>
<p>This text appears beside the audio player (if align attribute were
supported).</p>
</body>
</html>
Output:
<html>
<head>
<title>Align Audio with CSS</title>
<style>
.audio-left {
float: left;
margin-right: 10px;
}
</style>
</head>
<body>
<audio src="sample-audio.mp3" class="audio-left" controls>
Your browser does not support the audio element.
</audio>
<p>This text wraps around the audio player using CSS.</p>
</body>
</html>
Concept:
• The <a> tag (anchor tag) creates a hyperlink to another web page or resource. The href attribute
specifies the link’s target destination.
HTML Code:
Output:
Explanation:
Concept:
• The <iframe> tag embeds another HTML document within the current page, allowing multiple
pages to be displayed simultaneously.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Display Multiple Web Pages</title>
</head>
<body>
</body>
</html>
Explanation:
• <iframe> tag: Embeds an external web page inside the current HTML page.
• src attribute: Specifies the URL of the web page to be embedded.
• width and height attributes: Set the dimensions of the iframe (you can adjust these values
to fit your needs).
• title attribute: Provides a description of the iframe content for accessibility purposes.
Semantic HTML refers to the use of HTML markup that conveys meaning about the content it
contains. Using appropriate semantic elements helps improve accessibility, enhance search engine
optimization (SEO), and create a clearer structure for developers and users alike.
A well-structured web page typically consists of several key components. Below is an example of a
basic semantic web page layout using only HTML tags:
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Travel Blog</title>
</head>
<body>
<header>
<h1>Explore the World</h1>
</header>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#destinations">Destinations</a></li>
<li><a href="#travel-tips">Travel Tips</a></li>
<main>
<article>
<h2>Featured Destination: Bali</h2>
<p>Bali is known for its stunning beaches, vibrant culture, and lush
landscapes. Discover the hidden gems and tourist spots that make Bali a must-
visit.</p>
</article>
<aside>
<h2>Travel Resources</h2>
<p>Planning your next adventure can be an exciting yet overwhelming
task, but there are plenty of helpful resources to make the process smoother and
more enjoyable. Travel blogs often provide firsthand accounts and tips from
travelers who have experienced the destinations you’re considering. Websites like
TripAdvisor and Lonely Planet offer reviews, recommendations, and detailed
itineraries that can help you decide where to go and what to see. For those
interested in cultural experiences, platforms like Airbnb Experiences allow you to
book unique activities hosted by locals, from cooking classes to guided tours. If
you prefer a more structured approach, consider using travel planning apps like
Roadtrippers or Kayak, which allow you to map out your journey, find
accommodations, and track your budget all in one place.
Social media platforms, especially Instagram and Pinterest, are invaluable for
visual inspiration, showcasing breathtaking landscapes and hidden gems through
stunning photographs. Additionally, YouTube channels dedicated to travel can
provide you with video tours and travel vlogs that showcase destinations from the
perspective of fellow adventurers. For those concerned about budgeting, websites
like Skyscanner and Google Flights can help you compare flight prices, while
Hostelworld offers affordable lodging options. Don’t forget to check out travel
forums like Reddit's r/travel, where you can ask questions and gain insights from
seasoned travelers. Finally, local tourism websites often have valuable resources,
including maps, event calendars, and travel guides tailored to specific regions.
With these resources at your fingertips, your next adventure can be well-planned
and truly memorable.</p>
<ul>
<li><a href="#flights">Best Flight Deals</a></li>
<li><a href="#accommodations">Top Accommodations</a></li>
<li><a href="#itineraries">Sample Itineraries</a></li>
</ul>
Flights are often the first step in your travel planning process. Selecting the
right flight can not only save you money but also enhance your overall travel
experience. It’s essential to compare various airlines and booking platforms, as
prices can fluctuate significantly. Consider factors like layover times, flight
durations, and departure/arrival times that suit your schedule. Flexible travel
Accommodations are another vital aspect of travel planning. The type of lodging you
choose can greatly impact your experience, from luxurious hotels to budget-friendly
hostels and vacation rentals. Platforms like Airbnb and [Link] offer a wide
range of options tailored to different preferences and budgets. Consider the
location of your accommodation in relation to major attractions, transportation
options, and local dining. Reviews and ratings can guide you in making informed
choices, ensuring your stay is comfortable and enjoyable.
</aside>
</main>
<footer>
<p>© 2024 Explore the World. All rights reserved.</p>
</footer>
</body>
</html>
Output:
1. <header>
o Purpose: This element contains introductory content for the webpage, such as the
title or logo.
2. <nav>
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Web Page Layout</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
header {
background-color: #4CAF50;
color: white;
text-align: center;
padding: 10px 0;
}
nav {
background-color: #333;
<nav>
<a href="#home">Home</a>
<a href="#about">About</a>
<a href="#services">Services</a>
<main>
<div class="content">
<h2>Main Content Area</h2>
<p>This is where the main content of the web page goes.</p>
</div>
<div class="sidebar">
<h2>Sidebar</h2>
<p>This is the sidebar area where additional information can be
placed.</p>
</div>
</main>
<footer>
<p>Footer © 2024</p>
</footer>
</body>
</html>
1. <!DOCTYPE html>: Declares the document type and version of HTML being used (HTML5).
2. <html lang="en">: The root element of the HTML document, specifying the language as
English.
3. <head>: Contains meta-information about the document, such as character set, viewport
settings, and the title.
4. <style>: Inline CSS styles define the appearance of different sections of the page.
5. <body>: Contains all the visible content of the web page.
6. <header>: Represents the introductory content or header of the page. It often contains the
title or logo.
7. <nav>: The navigation bar contains links to other sections or pages of the website.
8. <main>: The main content area where the primary information is displayed. It uses a
flexbox layout to create two sections: content and sidebar.
o .content: The main section for displaying content.
o .sidebar: A side area for additional information or links.
9. <footer>: Represents the footer of the page, often containing copyright information and
links to privacy policies or terms of service.
Sections
In HTML, a <section> element is a semantic tag used to define a standalone section of content
within a document. This element is typically used to group related content and can contain various
types of content, such as headings, paragraphs, images, and more.
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Example of Section Element</title>
</head>
<body>
<header>
<h1>Welcome to My Website</h1>
</header>
<section>
<h2>About Us</h2>
<p>We are a company dedicated to providing the best services in the
industry.</p>
</section>
<section>
<h2>Our Services</h2>
<p>We offer a wide range of services to meet our clients' needs.</p>
</section>
<section>
<h2>Contact Us</h2>
<p>If you have any questions, feel free to reach out to us!</p>
</section>
<footer>
<p>© 2024 My Website. All rights reserved.</p>
</footer>
</body>
Output:
• Unlike <div>, which is a generic container without semantic meaning, the <section>
element carries significance regarding the document's structure. Other semantic elements
include <article>, <header>, <footer>, and <aside>, each serving specific purposes in
organizing and clarifying content within the HTML document.
HTML TABLES
Overview
HTML tables are used to organize and display data in a structured, grid-like format, consisting of rows
and columns. They are particularly useful for presenting tabular data such as schedules, financial
reports, or comparison charts.
Basic Structure:
Example:
<table>
<tr><th>Product</th><th>Price</th></tr>
Styling:
• Use border for basic borders or CSS for advanced styling like padding and background colors.
Spanning:
Example:
<tr>
<td colspan="2">Merged Cell</td>
</tr>
Caption:
HTML tables are essential for displaying structured data clearly and efficiently.
1. Creating a Table with Cells that Span Multiple Columns or Multiple Rows
Definition:
Creating tables with cells that span multiple columns or rows is a way to organize data effectively
in a structured format. In HTML, you can achieve this by using the colspan and rowspan attributes
within the <td> (table data) or <th> (table header) tags. This allows for a more flexible layout of
tabular data.
<html>
<head>
<title>Table with Colspan and Rowspan</title>
</head>
<body>
<table border="1">
<tr>
<th colspan="3">Student Information</th>
</tr>
<tr>
<th>Name</th>
<th>Age</th>
<th>Grade</th>
Output:
Explanation:
Table Structure:
• The first row contains a single header cell that spans three columns.
• The second row contains headers for Name, Age, and Grade.
• The third and fourth rows contain data for Jill and Eve.
• The fifth and sixth rows contain data for John, with "John" occupying the first column of
both rows.
Definition:
Setting the border width and colors for tables and their cells in HTML enhances the visual appeal
and readability of tabular data. You can specify the width and color of the table border and cell
borders directly within the HTML markup using attributes in the <table> and <td> (table data) tags.
<html>
<head>
<title>Table with Borders</title>
</head>
<body>
<table border="2" bordercolor="blue" cellspacing="0" cellpadding="5">
<tr>
<th style="border: 2px solid red;">Firstname</th>
<th style="border: 2px solid red;">Lastname</th>
<th style="border: 2px solid red;">Age</th>
</tr>
<tr>
<td style="border: 1px solid green;">Jill</td>
<td style="border: 1px solid green;">Smith</td>
<td style="border: 1px solid green;">50</td>
</tr>
<tr>
<td style="border: 1px solid green;">Eve</td>
<td style="border: 1px solid green;">Jackson</td>
<td style="border: 1px solid green;">94</td>
</tr>
<tr>
<td style="border: 1px solid green;">John</td>
<td style="border: 1px solid green;">Doe</td>
<td style="border: 1px solid green;">80</td>
</tr>
</table>
</body>
</html>
Output:
Definition:
Using background images and colors in HTML allows you to enhance the visual appeal of your web
pages. While CSS is typically used for styling, you can set background colors and images directly in
HTML by using attributes within HTML tags.
Here’s how to set a background color and a background image using only HTML tags.
To set a background color for the entire page, you can use the bgcolor attribute in the <body> tag:
<html>
<head>
<title>Background Color Example</title>
</head>
<body bgcolor="lightblue">
<h1>Welcome to My Web Page</h1>
<p>This is an example of a web page with a light blue background color.</p>
</body>
</html>
• bgcolor="lightblue": Sets the background color of the entire web page to light blue.
Output:
To set a background image for the entire page, you can use the background attribute in the
<body> tag:
<html>
<head>
<title>Background Image Example</title>
</head>
<body background="[Link]">
<h1>Welcome to My Web Page</h1>
<p>This is an example of a web page with a background image.</p>
</body>
</html>
Output
<html>
<head>
<title>Background Color and Image Example</title>
</head>
<body bgcolor="lightblue" background="[Link]">
<h1>Welcome to My Web Page</h1>
<p>This is an example of a web page with a light blue background color and a
background image.</p>
</body>
</html>
• In this example, the light blue color will show through the areas of the image that are
transparent.
Definition:
Aligning a table on a web page involves positioning the table at specific locations like the center,
left, or right. This can be done using the align attribute in the HTML <table> tag.
<html>
<head>
<title>Center Aligned Table</title>
</head>
<body>
<table align="center" border="1">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
Output :
To align the table to the left, simply change the align value in the <table> tag like this:
To align the table to the right, change the align value to:
Summary of Changes:
By changing the value of the align attribute, you can easily control the positioning of the table on
your web page.
Definition:
Displaying a gallery of thumbnails within a table is an effective way to present images on a
website. It organizes images into a structured layout, allowing visitors to easily browse and select
For instance, if you own a real estate company, you might want to showcase photographs of
various homes you are marketing. By providing a thumbnail gallery, you give site visitors the
option to view a larger image by clicking on a smaller version. This approach is beneficial as it
reduces loading times and lets users choose what they want to view.
To create a thumbnail gallery using a table, you can set up a table where each cell contains a
thumbnail image. The thumbnail images are linked to their corresponding full-size images using
<a> tags with the href attribute.
<html>
<head>
<title>Thumbnail Gallery</title>
</head>
<body>
<h1>Gallery of Homes</h1>
<table border="4" cellpadding="0" cellspacing="2" width="137"
bgcolor="#ffccff">
<tr>
<td align="center" valign="middle">
<a href="[Link]
<img src="D:\A-JAIN\FCA\LAB\[Link]" alt="Home 1">
</a>
</td>
<tr>
<td align="center" valign="middle">
<a target="_blank" href="D:\A-JAIN\FCA\LAB\[Link]">
<img src="D:\A-JAIN\FCA\LAB\[Link]" alt="Forest" style="width:150px">
</a>
</td>
Output:
• Table Structure: The <table> tag creates a table with a border, cell padding, and cell
spacing defined. Each <td> (table data) cell contains a thumbnail image.
• Linking Thumbnails: The <a> tag wraps around each <img> tag. The href attribute in the
<a> tag links to the web page containing the full-size image. For example, <a
href="page_1.htm"> links the thumbnail home_1.jpg to its full-size counterpart on
page_1.htm.
• Image Source: The src attribute of the <img> tag specifies the path to the thumbnail image.
HTML FORMS
Overview
HTML forms are used to collect user input and send it to a server for processing. They are crucial for
interactive websites and applications. Here's an overview of key elements and attributes related to
HTML forms:
Key Elements
Key Attributes
Example
<form action="/submit" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"
placeholder="you@[Link]" required><br><br>
Definition:
HTML forms processing involves the interaction between a web browser and a web server when a
visitor submits information via a web form. This process includes sending form data to the server,
executing scripts to handle the data, and providing feedback to the user.
• Webpage Request: The visitor's browser requests a webpage from the web server.
• Form Display: The server sends the form to the browser for the visitor to fill out.
• Form Submission: Upon clicking Submit, the browser sends the form data back to the
server.
• Data Processing: The server uses a CGI script to process the form results, which may
involve storing data or initiating transactions.
• Confirmation: The script generates a confirmation message and sends it to the web server.
• User Feedback: The server delivers the confirmation message back to the visitor's browser
for display.
Description:
A single-line input field is used for short text entries such as names, email addresses, or usernames.
HTML Code:
<label for="name">Name:</label>
<input type="text" id="name" name="name">
• <label for="name">: Provides a label for the input field with the for attribute linking it to the
input field's id.
• <input type="text">: Defines a single-line text input field.
• id: Identifies the input element uniquely.
• name: Defines the name of the input field, used when submitting form data.
Output:
Description:
A multiline input field (textarea) allows users to enter longer blocks of text, such as comments or
messages.
HTML Code:
<label for="comments">Comments:</label>
<textarea id="comments" name="comments" rows="4" cols="50"></textarea>
Explanation:
Output:
Displays a larger text area where users can input and view multiple lines of text.
3. Text Element
Description:
The text element is used for standard text input fields.
<label for="username">Username:</label>
<input type="text" id="username" name="username">
Explanation:
Output:
4. Number Element
Description:
The number element allows users to input numeric values with optional constraints on the range.
HTML Code:
<label for="age">Age:</label>
<input type="number" id="age" name="age" min="0" max="120">
Explanation:
Output:
5. Checkboxes
Description:
Checkboxes let users select one or more options from a list.
Explanation:
Output:
6. Radio Buttons
Description:
Radio buttons allow users to select only one option from a set of choices.
HTML Code:
<label><input type="radio" name="gender" value="male"> Male</label>
<label><input type="radio" name="gender" value="female"> Female</label>
Explanation:
Output:
Description:
A drop-down list allows users to select one option from a list of options.
<label for="country">Country:</label>
<select id="country" name="country">
<option value="india">India</option>
<option value="usa">USA</option>
<option value="uk">UK</option>
</select>
Explanation:
Output:
8. Reset Button
Description:
A reset button clears all the fields in the form to their default values.
HTML Code:
Explanation:
Output:
<html>
<head>
<title>Form without Reset Button</title>
</head>
<body>
<form>
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
If you still want to show a reset button but prevent its use, you can include the disabled attribute
to disable it.
<html>
<head>
<title>Disabled Reset Button</title>
</head> <body>
<form>
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
3. Use JavaScript
Description:
To prevent accidental clearing of form data, use a confirmation dialog.
<form onreset="return confirm('Are you sure you want to reset the form?');">
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<input type="reset" value="Reset">
</form>
Explanation:
• onreset: JavaScript event handler that shows a confirmation dialog when resetting the form.
Output:
Displays a
confirmation
dialog when the
reset button is
clicked,
preventing
accidental form
clearing.
Description:
A submit button sends the form data to the server for processing.
HTML Code:
Explanation:
Output:
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sample Form</title>
</head>
<body>
<h1>Registration Form</h1>
<form action="/submit" method="post" onsubmit="return confirm('Do you really
want to submit the form?');">
<!-- Single-line Input Field -->
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<br><br>
Output:
• The onsubmit attribute in the <form> tag ensures that the user is prompted to confirm
before submitting.
• The onclick attribute in the reset button prompts the user to confirm before clearing the
form.
Overview:
• IT Act 2000: Aims to provide legal recognition to electronic records, digital signatures, and
electronic contracts. It promotes e-commerce and addresses cybercrimes and digital
transactions.
• Amendments 2008: Updates the Act to address new cyber threats and enhance data privacy
protections.
Key Sections:
• Section 43: Defines penalties for damage to computer systems, unauthorized access, and
data destruction.
• Section 66: Addresses offenses like hacking, identity theft, and cyber terrorism. It prescribes
penalties and imprisonment.
• Section 72: Deals with breach of confidentiality and privacy by individuals who have access
to personal information due to their professional roles.
Details:
Overview: The Digital Personal Data Protection Act 2024 (DPDPA 2024) is a comprehensive
legislation enacted in India to regulate the processing of personal data. It aims to safeguard
individual privacy by setting out clear guidelines for data collection, usage, and management.
Salient Features:
Key Takeaways:
• The DPDPA 2024 emphasizes protecting individual privacy and ensuring responsible data
handling practices by organizations.
• It establishes clear rights for data subjects and outlines obligations for data controllers and
processors.
• Organizations must stay compliant with the Act to avoid penalties and contribute to the
protection of personal data in India.
HTML Form Validation refers to the process of ensuring that the data entered by users in a web
form meets specified criteria before the form can be submitted. This validation helps improve user
experience by preventing errors and ensuring that only valid data is sent to the server.
Below is an example of a simple form that includes validation for required fields, email format, and
password length using HTML attributes.
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form Validation Example</title>
</head>
<body>
Output:
1. required:
o Definition: This attribute specifies that the user must fill out this field before
submitting the form.
2. type="email":