Chapter 01 · HTML, CSS, JS, React, Node
HTML5 & Semantic Web Architecture
11 topics · 1 sections · beginner-friendly study notes · Updated
HTML5 gives pages meaning through a strict document skeleton, semantic elements, accessible forms, rich media and built-in browser storage.
Good HTML is the foundation that CSS, JavaScript, assistive technology and search engines all build on.
Semantic, accessible HTML improves SEO, screen-reader support and maintainability, and it is the first thing tested in front-end interviews and viva.
Marketing sites, blogs, dashboards, e-commerce pages and every web app shell begin with well-structured HTML.
HTML5 Document Structure
An HTML5 document starts with <!DOCTYPE html> and has a root <html> element containing <head> (metadata that is not displayed) and <body> (the visible content).
In short: head = information about the page, body = what users see.
Think about it
A malformed skeleton breaks rendering, character encoding and mobile layout, and everything else depends on it. Like the cover page and table of contents of a book: the browser reads it before showing any chapter.
The doctype triggers standards mode (without it browsers fall back to quirks mode).
<meta charset="UTF-8"> sets the encoding and should appear in the first 1024 bytes.
<meta name="viewport" content="width=device-width, initial-scale=1"> is required for responsive layouts on mobile.
lang on <html> helps screen readers pick pronunciation and helps translation tools.
Elements are block-level (div, p, h1) or inline (span, a, strong); void elements (img, br, input, meta, link) have no closing tag.
Scripts placed at the end of body, or loaded with defer, do not block HTML parsing.
Key points
- Doctype: Declares HTML5 and enables standards mode.
- Block vs inline: Block starts on a new line and takes full width; inline flows within text.
- Void element: Has no closing tag, e.g. img, br, input, meta.
- defer: Script attribute: download in parallel, execute after parsing finishes, in order.
Read more
Example
CodeMinimal HTML5 page: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>My First Page</title> <link rel="stylesheet" href="styles.css" /> <script src="app.js" defer></script> </head> <body> <h1>Hello, Web</h1> <p>This is <strong>HTML5</strong>.</p> </body> </html>
HTML5 Semantic Elements
Semantic elements describe the meaning of their content: header, nav, main, section, article, aside, footer, figure/figcaption, time, address. They replace anonymous div soup.
In short: Use tags that say what the content is, not just how it looks.
Think about it
Interview favourite: "Why semantic HTML?" - accessibility, SEO, readability and maintainability. Road signs: a sign shaped and coloured by meaning is understood faster than a plain white board.
There should be exactly one visible main per page.
article is self-contained and reusable on its own (blog post, product card, comment); section is a thematic grouping that normally has a heading; aside is tangential content such as a sidebar; nav holds major navigation blocks.
header and footer can be page-level or scoped inside an article.
These elements expose landmarks to screen readers and give crawlers clearer signals.
Use div/span only when no semantic element fits.
Key points
- Landmark: Region (header, nav, main, footer) that assistive tech can jump to.
- div soup: Over-use of generic div elements with no meaning.
- article vs section: article stands alone; section groups related content under a heading.
Read more
Example
CodeSemantic page layout:
<body>
<header>
<h1>TechBlog</h1>
<nav aria-label="Primary">
<a href="/">Home</a>
<a href="/posts">Posts</a>
</nav>
</header>
<main>
<article>
<h2>Why Semantic HTML?</h2>
<p>Published <time datetime="2026-01-15">15 Jan 2026</time></p>
<figure>
<img src="landmarks.png" alt="Diagram of page landmarks" />
<figcaption>Landmarks on a typical page</figcaption>
</figure>
</article>
<aside>Related links</aside>
</main>
<footer>© 2026 TechBlog</footer>
</body>HTML5 Text Formatting
Text content is structured with headings (h1-h6), paragraphs (p), lists (ul, ol, dl), quotations (blockquote, q, cite) and inline semantics (strong, em, mark, code, kbd, abbr, sub, sup, small, time).
In short: Pick the tag that matches the meaning: important, emphasised, code, quote.
Think about it
Correct text semantics give accessible structure and better search snippets, and avoid presentational markup.
strong marks importance and em marks stress emphasis; b and i are only stylistic offsets with no extra importance.
Headings build the document outline: one h1, then h2, h3 in order without skipping levels, because screen-reader users navigate by heading.
Use ul for unordered, ol for ordered and dl/dt/dd for term-definition pairs.
Whitespace collapses in HTML; use pre to preserve it and br only for genuine line breaks (such as addresses), not for spacing.
Visual size should be done with CSS, never by choosing a heading level.
Key points
Example
CodeMeaningful text markup: <h1>Study Guide</h1> <h2>Rules</h2> <p><strong>Always</strong> test your code. Press <kbd>Ctrl</kbd>+<kbd>S</kbd> to save.</p> <p>Water is H<sub>2</sub>O and E = mc<sup>2</sup>. Use <code>console.log()</code> to debug.</p> <blockquote cite="https://example.com"> <p>Simplicity is the soul of efficiency.</p> </blockquote> <ol> <li>Read</li> <li>Practice</li> </ol> <dl> <dt>DOM</dt><dd>Document Object Model</dd> </dl>
Hyperlinks and Anchors
The anchor element <a href="..."> creates hyperlinks to other pages, files, email addresses (mailto:), phone numbers (tel:) or fragments inside a page (#id). URLs can be absolute, root-relative or relative.
In short: A link is a clickable address; #id jumps to a spot on the same page.
Think about it
Links are the web. Wrong rel attributes create security holes and poor link text hurts accessibility and SEO.
target="_blank" opens a new tab and should be paired with rel="noopener noreferrer" to prevent the new page from controlling `window.
opener` and to avoid leaking the referrer.
download suggests saving instead of navigating.
Same-page navigation uses href="#section" matching an element id.
Link text must make sense out of context ("Read the pricing guide", not "click here") because screen readers list links.
rel="nofollow" and rel="sponsored" tell crawlers not to pass ranking credit.
Relative paths: `page.
html (same folder), ..
/page.
html (parent), /page.
html` (site root).
Key points
- Fragment identifier: The #id part of a URL that scrolls to an element.
- rel="noopener": Stops the opened page from accessing the opener window.
- Absolute vs relative URL: Absolute has full scheme and host; relative resolves against the current URL.
Read more
Example
CodeLink patterns: <a href="/pricing">Read the pricing guide</a> <a href="https://example.com" target="_blank" rel="noopener noreferrer">External site</a> <a href="mailto:hello@example.com">Email us</a> <a href="tel:+911234567890">Call support</a> <a href="brochure.pdf" download>Download brochure</a> <a href="#faq">Jump to FAQ</a> <!-- far below --> <h2 id="faq">Frequently Asked Questions</h2>
Images and Video Embeds
Media is embedded with <img>, <picture>, <audio>, <video> and <iframe>. Images need src and alt; video/audio accept `controls, autoplay, muted, loop, preload and multiple <source>` fallbacks.
In short: img shows pictures, video plays movies, iframe embeds other pages like YouTube.
Think about it
Media dominates page weight; correct attributes improve performance, accessibility and Core Web Vitals.
Always supply alt: descriptive text for informative images, empty alt="" for decorative ones.
Set width and height to reserve space and avoid layout shift (CLS).
loading="lazy" defers off-screen images.
srcset and sizes let the browser pick the right resolution; <picture> with <source type="image/webp"> provides format fallbacks and art direction.
For video, offer several formats (MP4/H.264, WebM), a poster frame and `<track kind="captions">` for subtitles.
Browsers block autoplay with sound, so autoplay requires muted.
<iframe> should have a title and, for untrusted content, the sandbox attribute.
Key points
- alt text: Text alternative announced by screen readers or shown when the image fails.
- srcset: List of image candidates with widths/densities for responsive loading.
- CLS: Cumulative Layout Shift - visual jumping caused by content without reserved size.
- sandbox: iframe attribute restricting scripts, forms and navigation of embedded content.
Read more
Example
CodeResponsive image and video:
<img src="hero-800.jpg"
srcset="hero-400.jpg 400w, hero-800.jpg 800w, hero-1600.jpg 1600w"
sizes="(max-width: 600px) 100vw, 800px"
width="800" height="450" loading="lazy"
alt="Students collaborating at a laptop" />
<picture>
<source srcset="logo.webp" type="image/webp" />
<img src="logo.png" alt="Company logo" width="120" height="40" />
</picture>
<video controls width="640" poster="cover.jpg" preload="metadata">
<source src="lesson.webm" type="video/webm" />
<source src="lesson.mp4" type="video/mp4" />
<track kind="captions" src="lesson.en.vtt" srclang="en" label="English" default />
Your browser does not support video.
</video>
<iframe src="https://www.youtube.com/embed/VIDEO_ID" title="Lesson video" loading="lazy" allowfullscreen></iframe>HTML Tables Structure
Tables present tabular data using <table>, <caption>, <thead>, <tbody>, <tfoot>, <tr>, <th> (header cell) and <td> (data cell), with colspan and rowspan for merged cells.
In short: Rows and columns for real data - not for page layout.
Think about it
Tables are frequently misused for layout; proper structure makes data readable by screen readers.
Use th with scope="col" or scope="row" so assistive tech associates each data cell with its headers.
caption gives the table an accessible title.
Grouping with thead/tbody/tfoot lets browsers repeat headers when printing and lets CSS style sections.
colspan merges across columns and rowspan merges down rows; complex multi-level headers need the headers attribute.
Layout with tables is obsolete - use Flexbox or Grid.
For responsiveness wrap the table in a container with overflow-x: auto.
Key points
- scope: Declares whether a th labels a column or a row.
- colspan / rowspan: Number of columns or rows a cell spans.
- caption: Visible title/description of the table.
Read more
Example
CodeAccessible data table:
<table>
<caption>Marks by subject</caption>
<thead>
<tr><th scope="col">Subject</th><th scope="col">Term 1</th><th scope="col">Term 2</th></tr>
</thead>
<tbody>
<tr><th scope="row">Maths</th><td>88</td><td>92</td></tr>
<tr><th scope="row">Physics</th><td>79</td><td>85</td></tr>
</tbody>
<tfoot>
<tr><th scope="row">Total</th><td colspan="2">344</td></tr>
</tfoot>
</table>HTML Form Fundamentals
Forms collect user input using <form>, <label>, `<input>, <select>, <textarea>, <fieldset>/<legend> and <button>. The action attribute is the destination URL and method is GET or POST; each control sends its name=value` pair.
In short: Every input needs a label and a name; the form sends the data to the server.
Think about it
Forms are the primary way users send data; wrong structure breaks submissions and accessibility.
Associate labels with for/id or by wrapping the control, which also enlarges the click target.
Only controls with a name are submitted.
GET appends data to the URL (bookmarkable, idempotent reads such as search); POST sends it in the request body (changes, passwords, large data).
enctype="multipart/form-data" is required for file uploads.
<button type="button"> does not submit; the default type inside a form is submit.
Group radios by sharing the same name.
fieldset/legend give related controls a collective label.
autocomplete tokens (email, current-password) help password managers.
Key points
Example
CodeBasic form structure:
<form action="/signup" method="post">
<label for="name">Full name</label>
<input id="name" name="name" type="text" autocomplete="name" />
<label for="country">Country</label>
<select id="country" name="country">
<option value="in">India</option>
<option value="us">United States</option>
</select>
<fieldset>
<legend>Plan</legend>
<label><input type="radio" name="plan" value="free" checked /> Free</label>
<label><input type="radio" name="plan" value="pro" /> Pro</label>
</fieldset>
<label for="bio">Bio</label>
<textarea id="bio" name="bio" rows="4"></textarea>
<button type="submit">Sign up</button>
</form>HTML5 Input Controls
HTML5 added input types such as email, url, tel, number, range, date, time, datetime-local, month, week, color, search and file, plus datalist, output, progress and meter.
In short: The right input type gives the right keyboard and built-in picker on phones and desktops.
Think about it
Picking correct types reduces input errors and improves mobile UX with zero JavaScript.
Types give mobile users the correct on-screen keyboard (type="email" shows @, tel shows a dial pad) and free built-in widgets (date pickers, colour pickers).
Useful attributes: placeholder, autofocus, min/max/step, multiple (for file and email), accept (file types), inputmode, list linking to <datalist> for suggestions.
type="password" masks text; type="hidden" carries data not shown.
Values are always strings when read from JavaScript, even for number inputs (use valueAsNumber).
Placeholders are hints, not replacements for labels.
Key points
- datalist: Predefined suggestions attached to an input through the list attribute.
- inputmode: Hints which virtual keyboard to show without changing validation.
- step: Allowed increment for number, range and date-like inputs.
Example
CodeHTML5 input types: <input type="email" name="email" placeholder="you@example.com" /> <input type="tel" name="phone" inputmode="numeric" /> <input type="number" name="qty" min="1" max="10" step="1" /> <input type="range" name="vol" min="0" max="100" value="40" /> <input type="date" name="dob" max="2015-12-31" /> <input type="color" name="theme" value="#3366ff" /> <input type="file" name="docs" accept=".pdf,image/*" multiple /> <input list="langs" name="lang" /> <datalist id="langs"><option value="JavaScript"><option value="Python"><option value="Java"></datalist> <progress value="70" max="100">70%</progress> <meter value="0.6" min="0" max="1">60%</meter>
HTML5 Form Validation
Constraint validation lets the browser check input before submission using attributes required, minlength, maxlength, min, max, pattern, type and the novalidate form attribute, with a JavaScript Constraint Validation API.
In short: Add attributes and the browser blocks bad data and shows messages for free.
Think about it
Validation prevents bad data early and is a security topic: client checks are never trusted.
pattern takes a regular expression matched against the whole value.
Invalid fields match the CSS pseudo-classes :invalid, :valid, :required, :optional, and :user-invalid (after interaction).
In JavaScript use `input.
validity` (valueMissing, typeMismatch, patternMismatch, tooShort...
), setCustomValidity("message") to craft custom errors (empty string clears) and `form.
checkValidity() / reportValidity()`.
novalidate on the form disables native bubbles when you implement custom UI.
Client-side validation is a usability aid only - always re-validate on the server, because anyone can bypass the browser.
Key points
- Constraint Validation API: JS interface: validity, setCustomValidity, checkValidity, reportValidity.
- pattern: Regex attribute the full value must match.
- :user-invalid: Pseudo-class for fields that are invalid after the user interacted.
Example
CodeNative + custom validation:
<form id="reg" action="/register" method="post">
<label for="u">Username (letters/numbers, 4-12)</label>
<input id="u" name="username" required minlength="4" maxlength="12" pattern="[A-Za-z0-9]+" />
<label for="pw">Password</label>
<input id="pw" name="password" type="password" required minlength="8" />
<label for="pw2">Confirm password</label>
<input id="pw2" type="password" required />
<button>Register</button>
</form>
<style>input:user-invalid { border: 2px solid crimson; }</style>
<script>
const pw = document.getElementById("pw");
const pw2 = document.getElementById("pw2");
pw2.addEventListener("input", () => {
pw2.setCustomValidity(pw.value === pw2.value ? "" : "Passwords do not match");
});
</script>Client Web Storage
Web Storage stores key-value string pairs in the browser: localStorage persists until cleared, sessionStorage lasts for the tab session. Cookies, IndexedDB and the Cache API are other client storage options.
In short: localStorage remembers data after you close the browser; sessionStorage forgets when the tab closes.
Think about it
Used for themes, drafts, carts and caching; questions on cookie vs localStorage vs sessionStorage are classics.
Storage is scoped by origin (scheme + host + port), holds roughly 5 MB, is synchronous (large reads block the main thread) and only stores strings - use `JSON.
stringify/JSON.
parse` for objects.
getItem returns null for missing keys.
The storage event fires in other tabs when localStorage changes.
Cookies are sent to the server on every request, have a 4 KB limit and can be HttpOnly; Web Storage is never sent automatically.
Never store passwords or sensitive tokens in localStorage: any XSS script can read it.
IndexedDB is for large structured data and offline apps.
Key points
- Origin: Combination of protocol, host and port that scopes storage.
- HttpOnly cookie: Cookie unreadable from JavaScript, safer for session ids.
- IndexedDB: Asynchronous browser database for large structured data.
Read more
Example
CodeSaving and loading preferences:
const prefs = { theme: "dark", fontSize: 16 };
localStorage.setItem("prefs", JSON.stringify(prefs));
const saved = JSON.parse(localStorage.getItem("prefs") ?? "{}");
console.log(saved.theme); // "dark"
sessionStorage.setItem("step", "2"); // cleared when the tab closes
localStorage.removeItem("prefs");
localStorage.clear();
window.addEventListener("storage", e => console.log(e.key, e.newValue)); // other tabsAccessibility & ARIA
Web accessibility (a11y) ensures people with disabilities can perceive, operate and understand content (WCAG: Perceivable, Operable, Understandable, Robust). ARIA attributes (role, aria-label, aria-labelledby, aria-expanded, aria-live) supplement native semantics when HTML cannot express a widget.
In short: Use real HTML elements first; add ARIA only to describe custom widgets.
Think about it
Accessibility is a legal requirement in many regions and widens your audience; audits check it constantly. Ramps and elevators next to stairs: designed in from the beginning they help everyone.
The first rule of ARIA: do not use ARIA if a native element exists (button beats div role="button").
Native controls come with keyboard support and roles for free.
Ensure every interactive element is reachable and operable by keyboard (Tab, Enter, Space, Esc), has a visible focus style, and sufficient colour contrast (4.5:1 for normal text).
Provide text alternatives, logical heading order, a "skip to content" link and lang.
aria-live="polite" announces dynamic updates such as toasts; aria-expanded and `aria-controls describe disclosure widgets; aria-hidden="true"` hides decorative content from assistive tech.
Wrong ARIA is worse than none because it overrides correct native semantics.
Key points
- WCAG: Web Content Accessibility Guidelines (levels A, AA, AAA).
- aria-label: Provides an accessible name when no visible text exists.
- aria-live: Region whose changes are announced by screen readers.
- Focus management: Controlling where keyboard focus lands, especially in dialogs.
Read more
Example
CodeAccessible disclosure menu:
<a class="skip" href="#main">Skip to main content</a>
<button type="button" aria-expanded="false" aria-controls="menu" id="menuBtn">Menu</button>
<ul id="menu" hidden>
<li><a href="/">Home</a></li>
</ul>
<button aria-label="Close dialog">×</button>
<div role="status" aria-live="polite" id="toast"></div>
<script>
const btn = document.getElementById("menuBtn");
btn.addEventListener("click", () => {
const open = btn.getAttribute("aria-expanded") === "true";
btn.setAttribute("aria-expanded", String(!open));
document.getElementById("menu").hidden = open;
});
</script>Solved examples
Replace this div-based layout with semantic HTML5: <div id="top"><div id="menu">...</div></div><div id="content">...</div><div id="bottom">...</div>
Semantic equivalent
Formula Applied:—Approach note: Ask: "What is this region?" and pick the element with that meaning.
Build a login form whose fields are accessible and validated by the browser.
Form markup
Formula Applied:—Approach note: Never rely on client-side validation alone - always validate on the server too.
Save a user's theme choice so it survives a page reload, and restore it on load.
JavaScript using Web Storage
Formula Applied:—Approach note: Use sessionStorage instead if the value should vanish when the tab closes.
An icon-only <div class="btn"> toggles a menu. Make it accessible.
Accessible replacement
Formula Applied:—Approach note: Native element first, ARIA second.
Real-world applications
Using HTML5 & Semantic Web Architecture in real projects
Marketing sites, blogs, dashboards, e-commerce pages and every web app shell begin with well-structured HTML.
Common mistakes
❌ Myth: Semantic tags change how the page looks by default.
Why this is wrong: Most semantic elements are just block containers with no special styling.
✅ Verified Truth: They add meaning for browsers, assistive tech and search engines; appearance comes from CSS.
⚠️ Exam Tip: Say "meaning, not looks".
❌ Myth: Placeholder text can replace a label.
Why this is wrong: Placeholders vanish on input and are not reliably announced by screen readers.
✅ Verified Truth: Always use a real <label>; placeholder is only a hint.
⚠️ Exam Tip: Accessibility questions expect label for/id.
❌ Myth: You can use as many h1 tags as you like for SEO.
Why this is wrong: A flat or illogical heading structure confuses users and assistive tech.
✅ Verified Truth: Use one clear h1 per page and nest h2-h6 in order.
⚠️ Exam Tip: Heading order is about structure, not font size.
❌ Myth: HTML5 form validation is enough to secure input.
Why this is wrong: Users can disable JavaScript or send raw requests, bypassing all browser checks.
✅ Verified Truth: Treat client validation as UX only and re-validate on the server.
⚠️ Exam Tip: State "never trust the client".
❌ Myth: localStorage is a safe place for login tokens.
Why this is wrong: Any injected script (XSS) can read localStorage.
✅ Verified Truth: Prefer HttpOnly, Secure, SameSite cookies for session credentials.
⚠️ Exam Tip: Compare cookie vs localStorage in answers.
❌ Myth: ARIA makes any div accessible.
Why this is wrong: ARIA only adds descriptions; it adds no keyboard behaviour or focus handling.
✅ Verified Truth: Use native elements; add ARIA and scripts only when no native element fits.
⚠️ Exam Tip: Quote the first rule of ARIA.
Revision notes
HTML5 gives pages meaning through a strict document skeleton, semantic elements, accessible forms, rich media and built-in browser storage. Good HTML is the foundation that CSS, JavaScript, assistive technology and search engines all build on.
High-Yield Quick Revision Points
- doctype + html/head/body, charset, viewport
- one main, one h1 per page, headings in order
- semantic > div soup (header, nav, main, article, aside, footer)
- strong/em semantic; b/i stylistic
- target=_blank needs rel=noopener noreferrer
- img: alt, width/height, lazy, srcset; video: controls, captions
- table: caption, thead/tbody, th scope
- label for/id, name required for submission
- right input type = right keyboard/picker
- required/pattern/min/max + setCustomValidity; server validates too
- localStorage persistent, sessionStorage per tab, strings only
- native HTML first, ARIA second; keyboard + contrast
Practice questions
Which element should wrap the unique primary content of a page?
Which attribute links a <label> to an <input>?
The meta tag needed for responsive layout on mobile is:
Which is a void (self-closing) element?
Which rel value should accompany target="_blank" for safety?
Which tag marks strong importance (not just bold)?
Which attribute makes a th label a whole column for screen readers?
Which storage persists after the browser is closed?
What does setCustomValidity("") do?
Which is the best first choice for a clickable control?