Web Programming Answer Sheet
Web Programming Answer Sheet
Ans. The key differences between HTML4 and XHTML in terms of syntax rules are:
1. Case Sensitivity:
o HTML4 is not case-sensitive. Both uppercase and lowercase tags are allowed
(<TITLE> or <title>).
o XHTML is case-sensitive, and all tags and attributes must be in lowercase (<title>).
2. Tag Closing:
o XHTML requires self-closing tags with a forward slash (<br />, <img />).
3. Attribute Quotation:
4. Attribute Minimization:
5. Nesting of Elements:
6. Doctype Declaration:
o XHTML requires a strict DOCTYPE declaration and the xmlns attribute in the root
element.
7. Empty Elements:
These rules make XHTML more consistent and well-structured but also stricter compared to HTML4.
Q.2 Explain the purpose of <!doctype> declaration and why it's important in html documents
Ans. The <!DOCTYPE> declaration in HTML documents defines the document type and version of
HTML being used. Its primary purpose is to help web browsers understand how to render the
webpage correctly.
Purpose of <!DOCTYPE>:
1. Document Type Identification: It informs the browser about the type and version of HTML
(HTML4, XHTML, or HTML5) the document is written in.
2. Rendering Mode Control: The declaration triggers one of the following rendering modes in
browsers:
o Standards Mode: The browser renders the page according to the latest web
standards.
o Quirks Mode: Without <!DOCTYPE>, browsers may interpret the page with old,
inconsistent rendering methods.
3. Cross-Browser Consistency: Ensures that the web page looks the same across different
browsers by enforcing standard rules.
4. Validation: Helps validators check if the HTML code follows the proper syntax rules.
Example:
HTML5:
html
<!DOCTYPE html>
<html>
<head>
<title>Example Page</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
HTML4 Transitional:
html
Without the <!DOCTYPE> declaration, the browser might switch to quirks mode, leading to
inconsistent layout and unpredictable behavior. It ensures that modern web standards are applied,
resulting in more reliable and consistent web pages.
Q.3 How do meta tags affect seo and what are the essential meta tags every webpage should have?
ANS Meta tags play a crucial role in SEO (Search Engine Optimization) by providing
important information about a webpage to search engines and browsers. They help search
engines understand the page content, improving visibility and ranking in search results.
1. Improved Search Ranking: Properly used meta tags can improve a website's ranking
by offering clear information about the page.
2. Click-Through Rate (CTR): Meta descriptions help attract users to click on search
results by offering a brief, appealing summary.
3. Indexing Control: Meta tags like robots tell search engines whether to index a page
or follow its links.
4. Content Relevance: Meta tags help search engines understand the page content and
match it with user search queries.
html
<meta charset="UTF-8">
html
3. Meta Description
Provides a brief summary of the page (around 150-160 characters). It directly affects
CTR.
Example:
html
<meta name="description" content="Discover the best laptops for
students with high performance and budget-friendly prices.">
5. Meta Robots
Controls how search engines index and follow links on the page.
Example:
html
html
7. Meta Author
Specifies the author's name.
Example:
html
<meta name="author" content="John Doe">
html
<meta http-equiv="refresh" content="10">
Q.4 What is the difference between div and span tag elements and when each should be used?
Ans. The div and span tags in HTML are both used for grouping and organizing content, but they
serve different purposes based on how they affect the layout and structure of a webpage.
Type of
Block-level element Inline element
Element
Layout Starts on a new line and takes up the full Stays inline with other elements without
Behavior width available breaking the line
Used for grouping larger content blocks like Used to style or manipulate specific parts
Purpose
paragraphs, images, forms, or sections of text within a line
Common Layout divisions, containers for styling or Highlighting a portion of text or applying
Feature div span
div:
Example:
html
<div class="container">
<h1>Welcome</h1>
</div>
span:
o Apply CSS or JavaScript to specific portions of text without breaking the line.
Example:
html
Use span to style or manipulate small pieces of text inline without affecting layout.
Q.5 How does the box model work in css what are its components
Ans. The CSS Box Model is a fundamental concept that defines how elements are structured and
displayed on a webpage. It represents how content, padding, borders, and margins combine to
determine the total size and layout of an element.
1. Content
o The innermost part where text, images, or other content is displayed.
2. Padding
o Example:
padding: 20px;
3. Border
o Its thickness, style, and color can be customized using properties like border-width,
border-style, and border-color.
o Example:
4. Margin
o The outermost space between the element and its neighboring elements.
o It creates spacing outside the border, pushing elements away from each other.
o Example:
margin: 15px;
Example Calculation:
If an element has:
width: 200px
padding: 10px
border: 5px
margin: 15px
By default, the box model uses the content-box model, where padding and border are added outside
the specified width.
To include padding and borders within the specified width, use:
box-sizing: border-box;
Conclusion:
The CSS Box Model is essential for designing web layouts, controlling spacing, and managing element
dimensions. Understanding how its components interact helps create more consistent and
predictable web designs.
Q.6 What is the difference between get and post methods in form submission
Ans. The GET and POST methods are two common ways to send data from an HTML form to the
server in web applications. They differ in how data is transmitted, security, and intended use.
Data Sends data in the URL query string (e.g., ? Sends data in the request body, not
Transmission name=John&age=25) visible in the URL
Less secure because data is exposed in the More secure as data is hidden from the
Security
URL URL
For retrieving data without side effects For submitting sensitive or large data
Use Case
(like search queries) (like login forms or file uploads)
When to Use:
GET:
o Example:
html
<form method="GET" action="/search">
<button type="submit">Search</button>
</form>
POST:
o Example:
html
<button type="submit">Login</button>
</form>
Q.7 Explain the difference between relative and absolute positioning in css
Ans: In CSS, relative and absolute positioning are two different methods used to control the layout
and placement of elements on a webpage.
1. Relative Positioning
The element moves from its original place but still occupies its space:
html
</div>
The box will move 20px down and 30px right but still leave its original space empty.
2. Absolute Positioning
The element moves freely without occupying space:
html
Parent
</div>
</div>
The red box will be positioned 20px down and 30px right relative to the parent div.
Q.8 How do you create a responsive navigation menu using html and css
Ans. How to Create a Responsive Navigation Menu Using HTML and CSS
A responsive navigation menu automatically adjusts its layout to fit different screen sizes like
desktops, tablets, and mobile devices.
1. HTML Structure
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<nav>
<div class="logo">MyWebsite</div>
<ul class="nav-links">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>
<div class="menu-icon">☰</div>
</nav>
<script>
menuIcon.onclick = () => {
navLinks.classList.toggle('show');
</script>
</body>
</html>
2. CSS Styling
*{
margin: 0;
padding: 0;
box-sizing: border-box;
body {
nav {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px;
background-color: #333;
color: white;
.logo {
font-size: 24px;
font-weight: bold;
.nav-links {
display: flex;
list-style: none;
}
.nav-links li {
margin: 0 15px;
.nav-links a {
text-decoration: none;
color: white;
transition: 0.3s;
.nav-links a:hover {
color: #00bcd4;
.menu-icon {
display: none;
font-size: 28px;
cursor: pointer;
.show {
display: flex;
flex-direction: column;
text-align: center;
position: absolute;
top: 70px;
right: 20px;
background: #333;
width: 200px;
border-radius: 10px;
}
.show li {
margin: 10px 0;
.nav-links {
display: none;
flex-direction: column;
.menu-icon {
display: block;
Explanation:
1. HTML Structure:
o The navigation menu contains a logo, menu links, and a menu icon (hamburger icon).
2. CSS:
o On small screens (max-width: 768px), the menu icon appears, and the navigation
links are hidden.
3. JavaScript:
o The onclick event adds or removes the .show class to display the menu.
Q.9 What are the event bubbling and event capturing in javascript
In JavaScript, when an event occurs on a nested element, it can be handled in two phases: Event
Bubbling and Event Capturing. These phases define the order in which event handlers are executed
on parent and child elements.
1. Event Bubbling
Definition: In event bubbling, the event is first triggered on the target element (child) and
then propagates upwards to its parent elements in the DOM hierarchy.
Example: HTML:
html
<div id="parent">
</div>
JavaScript:
js
document.getElementById("parent").addEventListener("click", () => {
console.log("Parent Clicked");
});
document.getElementById("child").addEventListener("click", () => {
console.log("Child Clicked");
});
nginx
Child Clicked
Parent Clicked
Explanation: The event starts from the child element and bubbles up to the parent.
To enable event capturing, the third parameter of addEventListener() must be set to true.
Example:
document.getElementById("parent").addEventListener("click", () => {
console.log("Parent Clicked");
}, true);
document.getElementById("child").addEventListener("click", () => {
console.log("Child Clicked");
}, true);
Output:
nginx
Parent Clicked
Child Clicked
Explanation: The event starts from the parent and moves down to the child.
Propagation Direction Bottom to Top (Child → Parent) Top to Bottom (Parent → Child)
Use Case Most commonly used Rarely used, mainly for special cases
js
event.stopPropagation();
Create a simple form with input fields for name, email, and password.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Form Validation</title>
</head>
<body>
<h2>Registration Form</h2>
<label>Name:</label>
<label>Email:</label>
<label>Password:</label>
<button type="submit">Submit</button>
</form>
<script src="script.js"></script>
</body>
</html>
2. CSS for Basic Styling (Optional)
body {
form {
width: 300px;
padding: 20px;
border-radius: 10px;
input {
width: 100%;
padding: 10px;
margin-bottom: 10px;
button {
padding: 10px;
background: #5cb85c;
color: white;
border: none;
cursor: pointer;
button:hover {
background: #4cae4c;
}
3. JavaScript Validation
js
CopyEdit
function validateForm() {
// Name validation
alert("Name is required");
return false;
// Email validation
if (!email.match(emailPattern)) {
return false;
// Password validation
if (password.length < 6) {
return false;
4. How It Works
1. The onsubmit event is triggered when the user submits the form.
3. If validation fails, an alert message is displayed, and the form is not submitted.
The return false; statement stops the form from submitting if validation fails
DOM Traversal and Manipulation are core concepts in JavaScript that allow developers to navigate
and modify HTML elements dynamically.
What is DOM?
The Document Object Model (DOM) represents the structure of an HTML document as a tree-like
hierarchy where each element is a node.
1. DOM Traversal
DOM Traversal means navigating through different elements (nodes) of the DOM hierarchy to access
or manipulate them.
Method Description
nextElementSibling /
Selects the next or previous sibling element
previousElementSibling
Example:
<div id="parent">
<p>Child 1</p>
<p>Child 2</p>
</div>
<script>
</script>
2. DOM Manipulation
DOM Manipulation means changing, adding, or removing elements or their properties in the
document dynamically.
Method Description
Example:
html
<div id="container">Hello</div>
<script>
container.appendChild(newPara);
</script>
Event-Based Manipulation
You can manipulate the DOM when certain user actions (like clicks) happen.
Example:
html
function changeText() {
</script>
Q.12 What is the purpose of the fieldset and legend elements in html forms
In HTML, the <fieldset> and <legend> elements are used to improve the structure, accessibility, and
clarity of forms.
1. <fieldset> Element
The <fieldset> element is used to group related form controls (like input fields, checkboxes, or radio
buttons) together inside a box, making the form easier to understand and organize.
Syntax:
html
<fieldset>
<legend>Personal Information</legend>
<label>Name:</label>
<label>Email:</label>
</fieldset>
Purpose of <fieldset>:
2. <legend> Element
The <legend> element acts as a caption or title for the <fieldset> element, giving users context about
what the grouped fields represent.
Purpose of <legend>:
<fieldset>
<legend>Login Details</legend>
<label>Username:</label>
<label>Password:</label>
<button type="submit">Login</button>
</fieldset>
Output:
A box will appear around the input fields with the text "Login Details" as the title of the section.
Q.13 How do you create a drop-down menu that shows submenus on hover using css
Ans. How to Create a Drop-Down Menu with Submenus on Hover Using CSS
A drop-down menu with submenus can be created using only HTML and CSS without any JavaScript.
The submenu appears when the user hovers over the parent menu item.
HTML Structure
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dropdown Menu</title>
</head>
<body>
<nav>
<ul class="menu">
<li><a href="#">Home</a></li>
<li>
<ul class="submenu">
<li><a href="#">SEO</a></li>
<li><a href="#">Marketing</a></li>
</ul>
</li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</body>
</html>
CSS Styling
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
nav {
background-color: #333;
text-align: center;
.menu {
list-style: none;
display: flex;
justify-content: center;
.menu li {
position: relative;
.menu a {
text-decoration: none;
color: white;
display: block;
.menu a:hover {
background-color: #555;
}
.submenu {
list-style: none;
position: absolute;
top: 100%;
left: 0;
background-color: #444;
width: 150px;
.submenu li {
.submenu li:last-child {
border-bottom: none;
.submenu a {
padding: 10px;
Explanation:
2. When the user hovers over the parent li element, the submenu becomes visible using
display: block.
3. The position: absolute ensures the submenu is positioned below the parent menu item.
Q.14 What are the different ways to include css in an html document?
Ans. n HTML, CSS (Cascading Style Sheets) is used to style the appearance of web pages. There are
three main ways to include CSS in an HTML document:
1. Inline CSS
CSS is applied directly within an HTML element using the style attribute.
Syntax:
html
Advantages:
Easy to apply.
Disadvantages:
Not reusable.
2. Internal CSS
CSS is written inside the <style> tag within the <head> section of the HTML document.
Syntax:
html
<!DOCTYPE html>
<html>
<head>
<style>
p{
color: green;
font-size: 18px;
</style>
</head>
<body>
</body>
</html>
Advantages:
Disadvantages:
Can make the HTML document large if many styles are added.
3. External CSS
CSS is written in a separate .css file and linked to the HTML document using the <link> tag.
Syntax:
HTML File:
html
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
CopyEdit
p{
color: red;
font-size: 22px;
Advantages:
Easy to maintain.
Disadvantages:
Not suitable for small projects if only a few styles are needed.
Ans In JavaScript, both === and == are comparison operators, but they work differently in terms of
type checking and value comparison.
1. == (Equality Operator)
The == operator is known as the loose equality operator. It compares only the values of two
variables but does not consider their data types.
Example:
🔑 How It Works:
Type Conversion: Automatically converts one data type to another before comparison.
Less Strict: It tries to make the data types the same before comparing the values.
Example:
🔑 How It Works:
No Type Conversion: It compares the values directly without converting their types.
More Strict: Both the value and the type must be the same to return true.
When to Use:
Section C
Q.1 Explain in detail the evolution of html form from its basic markup language roots to modern
xhtml, discussing the key structural differences syntax rules and document type declarations.
Ans Evolution of HTML Form from Basic Markup Language to Modern XHTML
The HTML form has undergone significant changes since the early days of the web. It evolved from a
simple data collection method to a more structured and standardized system with better semantics,
syntax rules, and validation.
Key Features:
o Simple input elements like <input>, <textarea>, and <select>.
o No built-in validation.
Example:
html
</form>
Introduced more input types like checkboxes, radio buttons, and hidden fields.
Allowed the use of <fieldset> and <legend> for grouping form elements.
Optional document type declarations like HTML Transitional, Strict, and Frameset.
Example:
html
<fieldset>
<legend>Personal Information</legend>
</fieldset>
</form>
XHTML was introduced to combine the flexibility of HTML with the strict rules of XML.
Example:
html
<fieldset>
<legend>Login</legend>
</fieldset>
</form>
Introduced semantic elements and new input types like email, url, number, date, and
search.
Example:
html
<label>Email:</label>
</form>
Validation No No Yes
Feature HTML 4.01 XHTML 1.0 HTML5
Q.2 Describe the complete anatomy of an HTML head section and its significance in modern web
development analyse how different matter tags including viewport capsit and SEO related text affect
web page behaviour and search engine optimisation provide examples of essential had elements and
explain their impact on website performance associability and user experience
Ans The HTML <head> section plays a vital role in defining the structure, performance, and behavior
of a web page. It contains meta-information, external resources, and instructions that influence how
the page is rendered by browsers and indexed by search engines.
The <head> section provides essential metadata and references that help:
Controls the page's width and Makes the site responsive and mobile-
<meta name="viewport">
scaling on mobile devices friendly.
Example:
Impact:
SEO meta tags help search engines understand and rank the webpage content.
Example:
<meta name="description" content="Learn web development with our comprehensive HTML and
CSS tutorials.">
Impact:
Example:
html
Impact:
CSS enhances the layout and design.
6. Favicon
Q.3 Compare and contrast the various positioning methods in CSS (static relative absolute fixed and
sticky )with practical examples how do these positioning method interact with the document flow
Ans. CSS provides different positioning methods to control the layout of elements on a webpage.
These methods determine how elements are placed within the document flow and how they interact
with other elements.
Definition: This is the default positioning method. Elements are placed according to the
normal document flow.
Interaction with Document Flow: Elements are arranged one after another from top to
bottom.
Example:
html
2. Relative Positioning
Interaction with Document Flow: The element remains in the document flow but can be
offset using top, left, right, or bottom properties.
Example:
</div>
Definition: Positions the element relative to its nearest positioned ancestor (not the entire
document).
Interaction with Document Flow: The element is removed from the normal document flow.
Example:
html
</div>
</div>
✅ Impact: The element does not affect surrounding elements and can overlap other content.
4. Fixed Positioning
Definition: Positions the element relative to the viewport (browser window), remaining in
the same place even when the page is scrolled.
Interaction with Document Flow: The element is removed from the normal document flow.
Example:
html
</div>
5. Sticky Positioning
Definition: Behaves like relative positioning until a specified scroll position is reached, then
it becomes fixed.
Interaction with Document Flow: The element remains part of the document flow but
becomes fixed at a certain position.
Example:
html
</div>
Comparison Table
Yes (until
Sticky Yes Yes Navigation menus, table headers
scrolled)
Conclusion
Choosing the right positioning method is essential for creating a well-structured and responsive
layout. Use static for default behavior, relative for small adjustments, absolute for floating elements,
fixed for elements that need to stay visible, and sticky for interactive layouts that change with
scrolling.