HTML5 and the Semantic Web: Building Meaningful Pages
HTML5 and the Semantic Web
Introduction
HTML (HyperText Markup Language) is the backbone of every website you visit — from IRCTC's booking pages to Wikipedia. HTML5, the latest major version, introduced semantic elements that give meaning to your content, not just visual structure. Understanding HTML5 is essential because India's digital economy (UPI, DigiLocker, CoWIN) runs on web technologies.
Document Structure
Every HTML5 document follows a standard structure:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Computer Institute</title>
</head>
<body>
<header>
<nav>Navigation links here</nav>
</header>
<main>
<article>
<h1>Main Content</h1>
<p>Your content here</p>
</article>
<aside>Sidebar content</aside>
</main>
<footer>Footer content</footer>
</body>
</html>Semantic Elements Explained
| Element | Purpose | Example Use |
|---|---|---|
| <header> | Introductory content or navigation | Site logo, nav bar |
| <nav> | Navigation links | Menu, breadcrumbs |
| <main> | Primary page content | Article body |
| <article> | Self-contained content | Blog post, news story |
| <section> | Thematic grouping | Chapter, tab panel |
| <aside> | Tangential content | Sidebar, related links |
| <footer> | Footer information | Copyright, contact info |
| <figure> | Self-contained illustration | Image with caption |
Why Semantics Matter
Semantic HTML matters for three critical reasons: (1) Accessibility — screen readers used by visually impaired people depend on semantic tags to navigate pages. India has 62 million visually impaired citizens. (2) SEO — search engines (Google, Bing) use semantic structure to understand and rank your content. (3) Maintainability — semantic code is easier to read, debug, and modify by other developers.
HTML5 New Input Types
HTML5 added powerful form inputs that mobile browsers optimize for:
<!-- Date picker — native on mobile -->
<input type="date" name="dob">
<!-- Email validation built in -->
<input type="email" name="email" required>
<!-- Phone number keyboard on mobile -->
<input type="tel" name="phone" pattern="[0-9]{10}">
<!-- Range slider -->
<input type="range" min="0" max="100" value="50">
<!-- Color picker -->
<input type="color" value="#ff6600">HTML5 APIs
HTML5 also introduced JavaScript APIs: Geolocation (for location-based services like Swiggy/Zomato), Canvas (for drawing graphics and games), Web Storage (localStorage for offline data), and Web Workers (background processing without freezing the UI).
Building an Indian Railway Information Page
<article>
<header>
<h2>Train 12301 — Rajdhani Express</h2>
<p>New Delhi → Howrah</p>
</header>
<section>
<h3>Schedule</h3>
<table>
<tr><th>Station</th><th>Arrival</th><th>Departure</th></tr>
<tr><td>New Delhi</td><td>—</td><td>17:00</td></tr>
<tr><td>Kanpur Central</td><td>21:35</td><td>21:40</td></tr>
<tr><td>Howrah</td><td>09:55</td><td>—</td></tr>
</table>
</section>
<aside>
<p>Tip: Book via IRCTC app for fastest confirmation.</p>
</aside>
</article>Practice Problems
1. Create a semantic HTML page for your school's website with header, navigation, main content (about section, events section), and footer.
2. Build an HTML form for a student registration system using HTML5 input types (email, date, tel, number).
3. Convert a non-semantic page (using only div and span) to use proper HTML5 semantic elements.
Key Takeaways
- HTML5 semantic elements give meaning to content structure (not just visual layout)
- Semantic HTML improves accessibility for 62 million visually impaired Indians
- New input types (date, email, tel, range) provide built-in validation and mobile optimization
- HTML5 APIs enable rich web applications (geolocation, canvas, storage)
- Every major Indian digital platform (UPI, IRCTC, CoWIN) is built on HTML foundations
CSS3 and Responsive Design
Introduction
CSS (Cascading Style Sheets) transforms plain HTML into visually stunning web pages. In India, where 70%+ of internet users access the web via smartphones, responsive design isn't optional — it's survival. This chapter covers CSS3 features, the box model, Flexbox, Grid, and media queries to build pages that look perfect on every screen size.
The CSS Box Model
Every HTML element is a rectangular box with four layers:
/* The Box Model */
.element {
/* Content — the actual text/image */
width: 300px;
height: 200px;
/* Padding — space inside the border */
padding: 20px;
/* Border — the visible edge */
border: 2px solid #333;
/* Margin — space outside the border */
margin: 10px;
/* Total width = 300 + 20*2 + 2*2 + 10*2 = 364px */
/* Fix this with box-sizing! */
box-sizing: border-box; /* Now total = 300px */
}Flexbox Layout
Flexbox makes one-dimensional layouts (rows or columns) effortless:
/* Navigation bar using Flexbox */
.navbar {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 20px;
background: linear-gradient(135deg, #667eea, #764ba2);
}
.nav-links {
display: flex;
gap: 20px;
list-style: none;
}
/* Card layout — wrapping grid of cards */
.card-container {
display: flex;
flex-wrap: wrap;
gap: 20px;
justify-content: center;
}
.card {
flex: 0 1 300px; /* Don't grow, can shrink, basis 300px */
padding: 20px;
border-radius: 12px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}CSS Grid Layout
Grid handles two-dimensional layouts (rows AND columns simultaneously):
/* Dashboard layout using CSS Grid */
.dashboard {
display: grid;
grid-template-columns: 250px 1fr 300px;
grid-template-rows: 60px 1fr 40px;
grid-template-areas:
"header header header"
"sidebar main aside"
"footer footer footer";
min-height: 100vh;
gap: 10px;
}
.header { grid-area: header; }
.sidebar { grid-area: sidebar; }
.main { grid-area: main; }
.aside { grid-area: aside; }
.footer { grid-area: footer; }Media Queries for Responsive Design
Media queries adapt your layout to different screen sizes. India's device landscape spans ₹5,000 phones (320px wide) to 4K monitors:
/* Mobile-first approach */
.container { padding: 10px; }
/* Tablet (768px and up) */
@media (min-width: 768px) {
.container { padding: 20px; max-width: 720px; margin: auto; }
.dashboard { grid-template-columns: 200px 1fr; }
}
/* Desktop (1024px and up) */
@media (min-width: 1024px) {
.container { max-width: 960px; }
.dashboard { grid-template-columns: 250px 1fr 300px; }
}
/* Large desktop (1440px and up) */
@media (min-width: 1440px) {
.container { max-width: 1200px; }
}CSS3 Modern Features
| Feature | Syntax | Use Case |
|---|---|---|
| Variables | --primary: #667eea; | Consistent theming |
| Gradients | linear-gradient(135deg, #a, #b) | Beautiful backgrounds |
| Transitions | transition: all 0.3s ease | Smooth hover effects |
| Transforms | transform: scale(1.05) | Interactive elements |
| Animations | @keyframes spin {...} | Loading spinners |
| Filters | filter: blur(5px) | Image effects |
| Clamp | font-size: clamp(1rem,2vw,2rem) | Fluid typography |
Building a Responsive Indian News Card
<style>
:root {
--primary: #ff6b35;
--dark: #1a1a2e;
--radius: 12px;
}
.news-card {
background: white;
border-radius: var(--radius);
overflow: hidden;
box-shadow: 0 4px 20px rgba(0,0,0,0.08);
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.news-card:hover {
transform: translateY(-4px);
box-shadow: 0 8px 30px rgba(0,0,0,0.15);
}
.news-card img {
width: 100%;
height: 200px;
object-fit: cover;
}
.news-card .content {
padding: 20px;
}
.news-card .tag {
background: var(--primary);
color: white;
padding: 4px 12px;
border-radius: 20px;
font-size: 0.75rem;
text-transform: uppercase;
}
</style>Practice Problems
1. Build a responsive portfolio page using CSS Grid that shows 3 columns on desktop, 2 on tablet, and 1 on mobile.
2. Create a Flipkart-style product card with hover effects using CSS transitions and transforms.
3. Implement a dark mode toggle using CSS custom properties (variables).
Key Takeaways
- The box model (content + padding + border + margin) governs all layout; use box-sizing: border-box
- Flexbox handles one-dimensional layouts (nav bars, card rows); Grid handles two-dimensional layouts (dashboards, page layouts)
- Mobile-first responsive design is essential — 70%+ of Indian users are on smartphones
- CSS custom properties (variables) enable consistent theming and easy dark mode
- Modern CSS (clamp, grid, animations) eliminates the need for most JavaScript layout hacks
JavaScript Fundamentals: Making Web Pages Interactive
1. Variables and Data Types
JavaScript has evolved significantly in how we declare variables. The modern way uses let and const instead of the older var.
// Variable Declaration
const userName = "राज"; // Constant - cannot be changed
let userBalance = 5000; // Can be reassigned
let totalPrice; // Can be declared without initialization
// Data Types in JavaScript
const stringValue = "चाय की कीमत"; // String
const numberValue = 150; // Number
const booleanValue = true; // Boolean
const arrayValue = [100, 200, 300]; // Array
const objectValue = { name: "चाय की दुकान", city: "दिल्ली" }; // Object
const undefinedVar = undefined; // Undefined
const nullVar = null; // Null
console.log(typeof stringValue); // "string"
console.log(typeof numberValue); // "number"
console.log(typeof arrayValue); // "object"
2. Functions - Reusable Blocks of Code
Functions are essential for organizing code. JavaScript supports multiple ways to write functions.
// Traditional Function Declaration
function calculateChaiPrice(quantity, pricePerCup) {
return quantity * pricePerCup;
}
// Arrow Function (Modern ES6)
const calculateWithTax = (price, taxRate = 0.05) => {
return price + (price * taxRate);
};
// Example: Build a chai price calculator
const chaiCalculator = (cups, pricePerCup = 20) => {
const subtotal = cups * pricePerCup;
const gst = subtotal * 0.05;
const total = subtotal + gst;
return {
cups,
pricePerCup,
subtotal,
gst,
total
};
};
const order = chaiCalculator(5, 25);
console.log(`5 चाय की कुल कीमत: ₹${order.total}`);
// Output: 5 चाय की कुल कीमत: ₹131.25
3. Conditionals - Making Decisions
Control the flow of your program based on conditions.
// If-else statements
const userAge = 15;
if (userAge >= 18) {
console.log("वयस्क");
} else if (userAge >= 13) {
console.log("किशोर");
} else {
console.log("बच्चा");
}
// Switch statements
const day = "बुधवार";
switch(day) {
case "सोमवार":
console.log("सप्ताह की शुरुआत");
break;
case "शुक्रवार":
console.log("सप्ताह का अंत");
break;
default:
console.log("सामान्य दिन");
}
// Ternary Operator
const discount = userAge < 18 ? 0.10 : 0.05;
console.log("छूट: " + (discount * 100) + "%");
4. Loops - Repeating Tasks
Automate repetitive tasks with loops.
// For Loop - When you know the number of iterations
const daysOfWeek = ["सोमवार", "मंगलवार", "बुधवार", "गुरुवार", "शुक्रवार", "शनिवार", "रविवार"];
for (let i = 0; i < daysOfWeek.length; i++) {
console.log(`दिन ${i + 1}: ${daysOfWeek[i]}`);
}
// While Loop - When condition is uncertain
let balance = 1000;
let withdrawal = 100;
while (balance >= withdrawal) {
balance -= withdrawal;
console.log(`शेष राशि: ₹${balance}`);
}
// Array Methods (Modern approach)
const prices = [10, 20, 15, 30];
prices.forEach((price, index) => {
console.log(`चाय #${index + 1}: ₹${price}`);
});
// Map - Transform each element
const pricesInDollars = prices.map(price => price / 83);
console.log(pricesInDollars);
// Filter - Select elements matching condition
const expensivePrices = prices.filter(price => price > 20);
console.log(expensivePrices); // [30]
5. Arrays - Collections of Data
Arrays store multiple values and provide powerful methods to manipulate them.
// Creating and Accessing Arrays
const fruits = ["सेब", "केला", "अंगूर"];
console.log(fruits[0]); // "सेब"
console.log(fruits.length); // 3
// Array Methods
fruits.push("आम"); // Add to end
fruits.unshift("नारंगी"); // Add to beginning
fruits.pop(); // Remove from end
fruits.shift(); // Remove from beginning
// Array Transformation Methods
const numbers = [1, 2, 3, 4, 5];
// Reduce - Combine all elements
const sum = numbers.reduce((total, num) => total + num, 0);
console.log(sum); // 15
// Some - Check if any element matches
const hasEven = numbers.some(num => num % 2 === 0);
console.log(hasEven); // true
// Every - Check if all elements match
const allPositive = numbers.every(num => num > 0);
console.log(allPositive); // true
// Find - Get first matching element
const firstEven = numbers.find(num => num % 2 === 0);
console.log(firstEven); // 2
// Spread Operator - Combine arrays
const array1 = [1, 2, 3];
const array2 = [4, 5, 6];
const combined = [...array1, ...array2];
console.log(combined); // [1, 2, 3, 4, 5, 6]
6. Template Literals - String Power-Up
Create dynamic strings with embedded expressions.
const storeName = "राज की चाय की दुकान";
const city = "दिल्ली";
const rating = 4.5;
// Template Literal with backticks
const message = `
दुकान: ${storeName}
शहर: ${city}
रेटिंग: ${rating} ⭐
विशेष ऑफर: ${rating >= 4.5 ? "30% छूट!" : "कोई ऑफर नहीं"}
`;
console.log(message);
// Multi-line strings
const description = `
यह एक विशेष चाय की दुकान है।
हम ताज़ी और स्वास्थ्यकर चाय बनाते हैं।
हर दिन खुला: सुबह 7 बजे से रात 10 बजे तक।
`;
console.log(description);
7. DOM Basics - Interacting with Web Pages
The Document Object Model (DOM) is how JavaScript interacts with HTML.
// Getting Elements
const heading = document.getElementById("main-heading");
const buttons = document.querySelectorAll(".btn");
const inputField = document.querySelector("input[type='number']");
// Modifying Content
heading.textContent = "स्वागत है!";
heading.innerHTML = "स्वागत है!";
// Changing Styles
heading.style.color = "red";
heading.style.fontSize = "24px";
heading.classList.add("highlight");
heading.classList.remove("hidden");
// Accessing Attributes
const link = document.querySelector("a");
console.log(link.getAttribute("href"));
link.setAttribute("href", "https://example.com");
// Creating Elements
const newParagraph = document.createElement("p");
newParagraph.textContent = "यह नया पैराग्राफ है।";
document.body.appendChild(newParagraph);
Practice Project: INR Currency Formatter
Build a function that formats numbers as Indian Rupees with proper localization.
const formatINR = (amount) => {
// Indian numbering system: 1,00,000 (not 100,000)
return new Intl.NumberFormat('en-IN', {
style: 'currency',
currency: 'INR',
}).format(amount);
};
console.log(formatINR(1000)); // ₹1,000.00
console.log(formatINR(100000)); // ₹1,00,000.00
console.log(formatINR(1000000)); // ₹10,00,000.00
// Building a Chai Order Calculator (Advanced)
const chaiOrders = [
{ name: "काली चाय", price: 20, quantity: 3 },
{ name: "दूध चाय", price: 25, quantity: 2 },
{ name: "मसाला चाय", price: 30, quantity: 1 }
];
const calculateTotal = (orders) => {
const subtotal = orders.reduce((sum, order) => sum + (order.price * order.quantity), 0);
const gst = subtotal * 0.05;
return { subtotal, gst, total: subtotal + gst };
};
const bill = calculateTotal(chaiOrders);
console.log(`कुल: ${formatINR(bill.total)}`);
Key Takeaways
- Use
constby default,letwhen reassignment is needed - Functions make code reusable and organized
- Array methods like map, filter, and reduce are powerful tools
- Template literals make string manipulation much easier
- The DOM is your gateway to interactive web pages
- Always use Intl.NumberFormat for currency in different locales
Found this useful? Share it!