Week 11 · HTML5, accessibility, encoding and beyond HTML
The one-minute story
HTML is a building, and the web has been renovating it for 30 years. The first version was a plain hall with signboards. Then people added tiny shops (forms), then decorations (CSS and scripts), and the rules got messy because every browser built differently. HTML5 is the big, tidy renovation: named rooms (header, nav, main, footer) so that visitors and machines know where things are; built-in appliances (audio, video, canvas) so you do not need outside plug-ins; and cupboards inside the visitor's own browser (web storage).
Two more things make a building good for everyone: ramps and lifts (accessibility, so people who cannot see, hear or use a mouse can still enter), and a common language on the signboards (character encoding, so "₹" on your page does not turn into garbage on someone else's screen).
By the end of this week you can:
- say how HTML 4, XHTML and HTML5 differ and use the semantic elements;
- name the four accessibility principles and the guideline under each, and spot which principle an example follows;
- calculate the size of a text in bits for a fixed-length encoding, and explain ASCII, Unicode, UTF-8 and UTF-16;
- compare cookies, localStorage, sessionStorage and IndexedDB;
- explain, at concept level, WebSockets, service workers and PWAs, web components, and the formats JSON, XML and Markdown.
Words you need
- SGML - an old, very general markup language; HTML 4 was defined with it, XML is a simplified form of it.
- XHTML - HTML rewritten with the strict rules of XML (every tag closed, lower case).
- Semantic element - a tag that says what the content means (
<nav>,<article>), not only how it looks. - Accessibility (a11y) - making a site usable by people with disabilities.
- WCAG - Web Content Accessibility Guidelines, the standard with four principles (POUR).
- ARIA - attributes like
roleandaria-labelthat describe elements to screen readers. - Character set / encoding - a table of characters and the rule for turning them into bytes.
- Code point - the number of a character in Unicode, written
U+20B9. - Mojibake - garbled text caused by reading bytes with the wrong encoding.
- Web storage - key-value storage in the browser (
localStorage,sessionStorage). - Service worker - a script that runs in the background of the browser, between your page and the network.
- PWA - progressive web app: a website that behaves like an installable app.
- Viewport - the visible area of the page on the user's screen.
Idea 1: A short history and what HTML5 added
| Version | Year (approx.) | What to remember |
|---|---|---|
| HTML 2.0, 3.2 | 1995 to 1997 | early, many browser-specific tags |
| HTML 4.01 | 1999 | defined using SGML; separates structure (HTML) and style (CSS) |
| XHTML 1.0 | 2000 | HTML 4 rewritten as XML; strict: tags must be closed and nested, lower case |
| HTML5 | finished 2014 | not SGML-based; has its own parsing rules; forgiving; adds multimedia, canvas, semantic tags, new inputs; backwards compatible |
So XHTML is based on XML, which is itself based on SGML. HTML5 is a living standard kept by WHATWG and W3C. Two facts that exams love: "HTML gets separated from SGML in HTML4" is false (that happened with HTML5), and "HTML5 is not backwards compatible" is false (old pages still work).
Other facts: HTML tag names and attribute names are case-insensitive (<DIV> and <div> are the same). The HTML5 doctype is just <!DOCTYPE html>. For large sites, external CSS is preferred over internal or inline CSS (one cached file, shared by all pages).
HTML5 added four big families of things:
- Semantic structure:
<header> <nav> <main> <section> <article> <aside> <footer>. - Richer forms: new input types and attributes with built-in checking.
- Multimedia and graphics:
<audio>,<video>,<canvas>, inline<svg>. - APIs: web storage, WebSockets, geolocation, service workers, drag and drop.
Idea 2: Semantic elements, new inputs, media
A page made of only <div> tags is called "div soup": a screen reader cannot tell the menu from the footer. Semantic tags fix this.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Recipe blog</title>
</head>
<body>
<header><h1>Recipe blog</h1></header>
<nav>
<a href="/">Home</a>
<a href="/about">About</a>
</nav>
<main>
<article>
<h2>Masala dosa</h2>
<section>
<h3>Ingredients</h3>
<ul><li>rice</li><li>urad dal</li></ul> <!-- order does not matter -->
</section>
<section>
<h3>Steps</h3>
<ol><li>Soak</li><li>Grind</li><li>Cook</li></ol> <!-- order matters -->
</section>
</article>
<aside>Related: sambar recipe</aside>
</main>
<footer>Copyright 2026</footer>
</body>
</html>
| Tag | Meaning |
|---|---|
<header> | intro or top of the page / of a section |
<nav> | main navigation links |
<main> | the main content; only one per page |
<section> | a themed group of content, usually with a heading |
<article> | self-contained item that makes sense on its own (a post, a news story) |
<aside> | side content, related but not central |
<footer> | bottom of the page / section |
Use <ul> for an unordered list (ingredients) and <ol> for an ordered list (steps); a paper question asks exactly this. Semantic tags have no visual effect by default; they help screen readers, search engines and you.
New input types and form attributes give free validation and the right mobile keyboard:
<form>
<label for="em">Email</label>
<input type="email" id="em" name="em" required placeholder="you@example.com">
<label for="dob">Date of birth</label>
<input type="date" id="dob" name="dob">
<label for="age">Age</label>
<input type="number" id="age" name="age" min="18" max="60">
<input type="range" name="vol" min="0" max="10">
<input type="color" name="c">
<input type="url" name="site">
<input type="tel" name="phone" pattern="[0-9]{10}">
<input type="search" name="q" autofocus>
<button>Send</button>
</form>
Other new types: time, datetime-local, month, week. Attributes: required, placeholder, pattern (a regular expression), min/max/step, autofocus, autocomplete, disabled, readonly, and <datalist> for suggestions. Remember: this browser-side checking is only for convenience. The server must still validate (the user can bypass the browser).
Multimedia and graphics
<video controls width="320" poster="cover.jpg">
<source src="clip.mp4" type="video/mp4">
<source src="clip.webm" type="video/webm">
<track kind="captions" src="clip.vtt" srclang="en" label="English">
Your browser does not support video.
</video>
<audio controls src="song.mp3"></audio>
<canvas id="c" width="200" height="100"></canvas>
<script>
const ctx = document.getElementById("c").getContext("2d");
ctx.fillStyle = "teal";
ctx.fillRect(10, 10, 80, 50); // x, y, width, height: a pixel drawing
</script>
<svg width="100" height="100"><circle cx="50" cy="50" r="40" fill="orange"/></svg>
<audio>and<video>play without Flash or other plug-ins;controlsshows the player buttons; several<source>lines let the browser pick a format it knows;<track>adds captions or subtitles.<canvas>is a pixel grid you paint with JavaScript (games, charts). Pixels do not remember what shapes they came from.- SVG is vector graphics written as XML; each shape stays an element in the page that can be styled, scripted and scaled without blur.
<main>appears once;<article>is not the same as<section>(an article could be read alone, a section is a part of something).- Canvas = pixels (JavaScript); SVG = shapes (markup). Do not swap them.
requiredandtype="email"stop most bad input in the browser, but never replace server-side checks.
Idea 3: Accessibility
Many people live with some disability: blind, low vision, colour blind, deaf, with motor problems, or with dyslexia. Accessibility also helps everyone (captions in a noisy bus, keyboard use when the touchpad is broken). The standard is WCAG, built on four principles, remembered as POUR:
| Principle | The question | Guidelines under it | Examples |
|---|---|---|---|
| Perceivable | Can users sense the content? | text alternatives for non-text content; captions and alternatives for audio and video; content that can be shown in different ways; easier to see and hear (colour contrast, resizable text) | alt text on images, captions, good contrast |
| Operable | Can users use the controls? | everything works from the keyboard; enough time to read and use content; no seizure-causing flashing; navigable (skip links, clear titles, focus order); input modalities beyond the keyboard (touch, voice) | tab order, visible focus, no content flashing more than 3 times a second |
| Understandable | Can users understand the content and the interface? | readable text (set the page language); predictable behaviour; input assistance: labels, instructions, error messages that help people avoid and correct mistakes | <label> plus a hint text, clear error text |
| Robust | Does it work with different browsers and assistive technology? | valid, compatible markup; name, role and value exposed to tools | semantic HTML, ARIA used correctly |
<!-- Perceivable: text alternative for an image -->
<img src="chart.png" alt="Bar chart: sales rose from 10 to 40 in 2025">
<!-- Understandable: label and instruction attached to the input -->
<label for="word">Search for a word:</label>
<input type="text" id="word" aria-describedby="hint">
<p id="hint">Enter a word to find relevant results.</p>
<button>Start Search</button>
<!-- Operable: a real button works with Tab, Enter and Space. A div does not. -->
<button onclick="save()">Save</button>
<div onclick="save()">Save</div> <!-- bad: not focusable, no role -->
<!-- Robust: ARIA when no native tag fits -->
<div role="alert" aria-live="polite">Saved successfully</div>
<button aria-label="Close dialog">X</button>
ARIA (Accessible Rich Internet Applications) adds role="..." (what it is), aria-label="..." (a name for screen readers), aria-live (announce changes), aria-expanded, aria-hidden. The first rule of ARIA: use a native HTML element if one exists (<button>, <nav>); use ARIA only to fill gaps. Also: alt="" (empty) for purely decorative images; never use colour alone to show meaning; contrast ratio at least 4.5 to 1 for normal text (WCAG AA); every form control gets a <label>; the page must be fully usable with the keyboard (Tab, Shift+Tab, Enter, Esc).
Question. Match each example to a principle: (a) an alt attribute on an image; (b) a form with a label and an instruction under the input; (c) the website works with keyboard only and also with voice control; (d) "Give users enough time to read and use content"; (e) valid markup that works with screen readers.
Solution. (a) Perceivable (text alternative). (b) Understandable (labels and input assistance; this is the real paper example with "Search for a word"). (c) Operable. (d) Operable, so it is the odd one out in "which is NOT a perceivable principle". (e) Robust.
- "Which is not a perceivable principle?" The answer is usually the sentence about time (enough time, no seizures), because that belongs to Operable. Text alternatives, captions and "easier to see and hear" are Perceivable.
- Seizures and physical reactions: Operable, not Perceivable.
- "Helps developers avoid and correct mistakes": Understandable (input assistance).
- "Works with different input modalities beyond the keyboard": Operable.
Idea 4: Character encoding
A computer stores only numbers. To store text, we agree on a character set (a table: number for each character) and an encoding (how the number becomes bytes).
- ASCII: 7 bits per character, 128 characters (English letters, digits, punctuation, control codes). Usually stored in one byte with the top bit 0.
Ais 65,ais 97,0is 48. - Unicode: one table for all writing systems (over a million possible code points, written
U+0041forA,U+20B9for the rupee sign,U+1F600for a smiley). Unicode is the table; UTF-8, UTF-16 and UTF-32 are three ways to encode it. - UTF-32 (UCS-4): fixed 4 bytes (32 bits) for every character. Simple, but wasteful.
- UCS-2: fixed 2 bytes (16 bits), only the first 65,536 code points.
- UTF-16: 2 bytes for the common ones, 4 bytes (a surrogate pair) for the rest; variable length.
- UTF-8: variable length, 1 to 4 bytes. Can encode every Unicode character. The first 128 code points are encoded exactly like ASCII (1 byte), so every ASCII file is already valid UTF-8. UTF-8 is the encoding of the web.
| Code point range | UTF-8 bytes | Example | Real UTF-8 bytes |
|---|---|---|---|
| U+0000 to U+007F | 1 | A U+0041 | 41 |
| U+0080 to U+07FF | 2 | é U+00E9 | C3 A9 |
| U+0800 to U+FFFF | 3 | ₹ U+20B9 | E2 82 B9 |
| U+10000 to U+10FFFF | 4 | smiley U+1F600 | F0 9F 98 80 |
(All checked with Python.) For the text made of h, é, l, l, o, a space, the rupee sign, a space and the smiley U+1F600, we get 9 characters but 15 bytes in UTF-8, 20 bytes in UTF-16 and 36 bytes in UTF-32. Lesson: number of characters is not number of bytes.
s = "héllo"
print(len(s)) # 5 characters
print(len(s.encode("utf-8"))) # 6 bytes (é takes 2)
print(len(s.encode("utf-32-le"))) # 20 bytes (5 x 4)
Declaring the encoding. Put <meta charset="utf-8"> as one of the first things in <head> (within the first 1024 bytes), and make the server send Content-Type: text/html; charset=utf-8. If the browser guesses wrongly, you get mojibake. For example, the UTF-8 bytes C3 A9 of é read as Latin-1 become the two characters é, so "café" shows as "café". Another bug: saving the file in one encoding and declaring another. Fix: save as UTF-8 and declare UTF-8 everywhere (also the database and the response header).
The exam sums on encoding
Fixed-length "minimum encoding". If a text uses a character set with N distinct characters, each character needs at least the ceiling of log2 N bits. Total bits = (number of characters in the text) times (bits per character).
Question. The sentence "the five boxing wizards jump quickly" is saved with the minimum fixed-length encoding of its own character set. How many bits?
Solution. The sentence has 36 characters (letters and spaces). Distinct characters: the 26 letters of the alphabet appear (it is a pangram) plus the space: 27. So the ceiling of log2 27 is 5 bits (4 bits give only 16 codes, 5 bits give 32). Size = 36 x 5 = 180 bits. (The "sphinx of black quartz judge my vow" version has 35 characters, 27 distinct, so 175 bits; "pack my box with five dozen liquor jugs" has 39 characters, 27 distinct, so 195 bits. Checked: these are the three real options marked correct.)
Question. A document of 2000 characters uses only 8 characters. Five digits are added to the set. By how many bits does the document grow?
Solution. Before: 8 characters need 3 bits (since 8 = 2 to the 3). After: 13 characters need the ceiling of log2 13 is 4 bits. Growth per character is 1 bit, so 2000 x 1 = 2000 bits. (Same pattern: 10 characters to 17 characters means 4 to 5 bits, and 1000 characters grow by 1000 bits.)
Question (a). A text of only alphanumeric characters takes 35,552 bits in UCS-4 (32 bits per character). How many bits in 7-bit ASCII?
Solution. Characters = 35552 / 32 = 1111. In ASCII: 1111 x 7 = 7777 bits. (Same method: 136000 / 32 = 4250 characters, x 7 = 29750 bits; in UCS-2 320000 bits means 20000 characters, x 7 = 140000 bits.)
Question (b). A fixed-length document of a 13-character set has size 3 kilobytes (1 KB = 1000 bytes). How many characters?
Solution. 13 characters need 4 bits. 3 KB = 3000 x 8 = 24000 bits. Characters = 24000 / 4 = 6000. (With a set of 12 distinct characters the answer is also 4 bits; 2 KB then gives 16000 / 4 = 4000.)
- Distinct characters, not the length of the text, decide the bits per character. Count the space as a character.
- Use the ceiling of log2 (27 distinct needs 5 bits, never 4.75).
- Read the unit carefully (bits or bytes, KB = 1000 or 1024 as the question says).
- UTF-8 is variable, UTF-32 is fixed (4 bytes). "Both UTF-8 and UTF-32 are variable length" is false.
- UTF-8 is not limited to 65,536 characters; it can encode all of Unicode.
- ASCII text is identical in UTF-8, but a non-ASCII character in a file declared as ASCII breaks.
Idea 5: Storing data in the browser
| Storage | Size (about) | Lifetime | Sent to server? | Data type | Use for |
|---|---|---|---|---|---|
| Cookie | about 4 KB each | until expiry (or tab close if no expiry) | yes, with every request | text | session id, login |
| localStorage | about 5 MB per site | stays until cleared by code or user | no | strings | theme, saved preferences |
| sessionStorage | about 5 MB per site | one tab; gone when the tab closes | no | strings | form draft in one tab |
| IndexedDB | large (hundreds of MB, browser decides) | stays | no | structured objects, files | offline data for PWAs |
localStorage.setItem("theme", "dark");
console.log(localStorage.getItem("theme")); // "dark"
localStorage.setItem("count", 5);
console.log(typeof localStorage.getItem("count")); // "string" (everything is text)
localStorage.setItem("user", JSON.stringify({name: "Asha"}));
const u = JSON.parse(localStorage.getItem("user")); // back to an object
console.log(u.name); // "Asha"
localStorage.removeItem("theme");
sessionStorage.setItem("draft", "hello"); // lost when the tab is closed
Rules: storage is per origin (scheme + host + port); pages on other sites cannot read it. The API is synchronous and stores only strings (so use JSON.stringify and JSON.parse). Never store passwords or secrets there: any script on your page can read it (an XSS attack). IndexedDB is asynchronous and holds objects, indexes and files.
Idea 6: Beyond request and response
WebSockets. Normal HTTP: the browser asks, the server answers, the connection ends. A WebSocket keeps one connection open in both directions, so either side can send a message at any time (chat, live scores, multiplayer games). It starts as an HTTP request that is "upgraded" (URL starts with ws:// or wss://).
Server-sent events (SSE). The browser opens a connection and the server pushes text events down it one way only (server to browser): a news ticker, progress bar, notifications. Simpler than WebSockets; the browser reconnects automatically (EventSource in JavaScript).
Polling (older idea): the browser asks again and again, for example every 5 seconds. Simple, but wasteful.
Progressive Web Apps (PWA) and service workers. A service worker is a JavaScript file that the browser runs in the background, separately from the page. It sits between the page and the network and can cache files and answer requests when offline, and receive push notifications. A PWA is an ordinary website plus: HTTPS, a web app manifest (a JSON file with name, icons, colours so it can be "installed" on the home screen), and a service worker (offline and speed).
// register the worker from your page
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("/sw.js");
}
// sw.js: cache a file at install time, answer from cache first
self.addEventListener("install", e =>
e.waitUntil(caches.open("v1").then(c => c.addAll(["/", "/style.css"]))));
self.addEventListener("fetch", e =>
e.respondWith(caches.match(e.request).then(r => r || fetch(e.request))));
Web components let you make your own HTML tags that work in any page. They are three technologies: Custom Elements (define <my-card>), Shadow DOM (private DOM and CSS that does not leak out) and HTML Templates (<template>, inert markup you clone). WebAssembly is something else (fast compiled code in the browser) and is not a web component; neither is SVG.
<hello-user name="Asha"></hello-user>
<script>
class HelloUser extends HTMLElement {
connectedCallback() {
const root = this.attachShadow({mode: "open"}); // Shadow DOM
root.innerHTML = "<p>Hello, " + this.getAttribute("name") + "!</p>";
}
}
customElements.define("hello-user", HelloUser); // names must contain a hyphen
</script>
This shows "Hello, Asha!" Custom element names must contain a hyphen.
Idea 7: Data formats and responsive design
| Format | Looks like | Notes |
|---|---|---|
| JSON | {"name": "Asha", "marks": [90, 85]} | keys in double quotes; types: string, number, true/false, null, list, object; the default for web APIs |
| XML | <student id="7"><name>Asha</name></student> | tags and attributes; based on SGML; both human and machine readable |
| Markdown | # Title, **bold**, - item | plain text that converts to HTML; for documents and README files |
| CSV | name,marks lines | tables; simple |
Checked with Python: json.loads of {"name": "Asha", "marks": [90, 85], "passed": true, "address": null} gives a dictionary whose marks[1] is 85, passed is the Python True and address is None. XML parsing with xml.etree.ElementTree gives tag student, attribute id equal to '7', and element text always as strings.
Responsive design means one page that fits phone, tablet and desktop. Three tools:
- The viewport meta tag:
<meta name="viewport" content="width=device-width, initial-scale=1">. Without it, a phone pretends to be about 980 pixels wide and shrinks the page. - Flexible layout: percentages,
flex,grid,max-width. - Media queries:
@media (max-width: 600px) { .menu { display: none; } }.
For your project viva. Open your own pages and check: <meta charset="utf-8"> and the viewport tag are present; the page uses <header>, <nav>, <main>, <footer>; every image has alt; every input has a <label>; text contrast is good; you can reach every button with only the Tab key. The examiner may ask: "Why UTF-8?", "What is the viewport tag for?" and "How is your site accessible?"
Your turn
A message of 500 characters uses only the letters a to z, a space and a full stop. How many bits are needed with the minimum fixed encoding?
Need a hint?
Count distinct characters, then the ceiling of the log.
Show the full solution
Distinct: 26 + 1 + 1 = 28, so the ceiling of log2 28 is 5 bits. Total 500 x 5 = 2500 bits.
A document takes 152,000 bits in UCS-4. How many bits in 7-bit ASCII?
Need a hint?
Divide by 32, multiply by 7.
Show the full solution
152000 / 32 = 4750 characters; 4750 x 7 = 33250 bits.
How many bytes does the string "a₹é" need in UTF-8?
Need a hint?
Use the table: 1, 3, 2.
Show the full solution
a is 1 byte, ₹ (U+20B9) is 3 bytes, é (U+00E9) is 2 bytes: 6 bytes, for 3 characters.
For each, say Perceivable, Operable, Understandable or Robust: (a) captions on a video; (b) a keyboard-reachable menu; (c) an error message that says what to fix; (d) markup that works across browsers and screen readers.
Need a hint?
Think POUR.
Show the full solution
(a) Perceivable. (b) Operable. (c) Understandable. (d) Robust.
Choose cookie, localStorage, sessionStorage or IndexedDB: (a) remember the dark theme for next month; (b) keep a half-written form while the tab is open; (c) store thousands of records for offline use; (d) the browser must send a login token with every request.
Need a hint?
Think lifetime and who receives it.
Show the full solution
(a) localStorage. (b) sessionStorage. (c) IndexedDB. (d) a cookie, since only cookies are sent automatically to the server.
Exam radar
The keyword match for this week gives about 24 distinct graded questions (about 36 Quiz 1, 12 Quiz 2 and 35 End Term keyword hits; the count is coarse, and a few hits are stray list-tag questions). This week has few matched questions overall, but they repeat very reliably:
- Encoding size calculations are the single most frequent type (about 12 of the 24): minimum encoding of a pangram ("pack my box...", "sphinx of black quartz...", "the five boxing wizards..."), characters in a given file size, size growth after adding characters, and "UCS-4 / UCS-2 bits to ASCII 7-bit bits".
- Accessibility principles (about 6 questions): "which is NOT a perceivable principle", which principle an HTML snippet follows (alt text is Perceivable, label plus hint is Understandable), "input modalities beyond the keyboard" is Operable.
- UTF-8 / UTF-32 statements (true/false: variable vs fixed length; case-insensitive tags; external CSS preferred).
- Web components (2 questions: "which helps create custom elements", "which is not a web component": WebAssembly).
- HTML history (HTML4 vs HTML5, XHTML based on XML, SGML).
- No past questions were found on cookies vs localStorage, WebSockets, PWAs or Markdown in this match, but they are part of the week and likely for viva or newer papers.
- Pangram sums: count distinct characters including the space; use the ceiling of the log.
- "Not Perceivable" is the sentence about time or seizures: that is Operable.
- UTF-8 is variable (1 to 4 bytes) and fully Unicode-capable; UTF-32 is fixed at 4 bytes.
- HTML5 is not SGML-based and is backwards compatible; XHTML is XML-based.
- Web Assembly is not a web component.
Quick quiz
Which of the following is NOT a correct perceivable accessibility principle?
- Provide text alternatives for non-text content.
- Provide captions and other alternatives for multimedia.
- Make it easier for users to see and hear content.
- Give users enough time to read and use content.
A sentence has 40 characters and uses 20 distinct characters. With minimum fixed-length encoding, its size is...
- 100 bits
- 160 bits
- 200 bits
- 320 bits
A document takes 64,000 bits in UCS-4. Its size in 7-bit ASCII will be...
- 8,000 bits
- 14,000 bits
- 28,000 bits
- 64,000 bits
Select all TRUE statements. (select all that apply)
- UTF-8 is a variable-length encoding that can represent all Unicode characters.
- UTF-32 is a fixed-length encoding where each character takes 4 bytes.
- Both UTF-8 and UTF-32 are variable length encodings.
- UTF-8 can only encode 65,536 characters.
Which of these is NOT a web component technology?
- Custom Elements
- Shadow DOM
- HTML Templates
- WebAssembly
Data in sessionStorage is...
- sent with every HTTP request
- kept for many years
- available to one browser tab and gone when it closes
- shared with all websites
Viva: say it out loud
Why did you use semantic tags such as nav and main?
They tell browsers, search engines and screen readers what each part of the page is, so a blind user can jump straight to the main content. The page also becomes easier for me to read and maintain than a pile of divs.
What are the four principles of web accessibility?
Perceivable, Operable, Understandable, Robust, in short POUR. Perceivable means users can sense the content, for example alt text and captions. Operable means they can use it, for example with the keyboard. Understandable means clear labels and error help. Robust means it works with many browsers and assistive tools.
Why do you write meta charset utf-8?
It tells the browser to decode the bytes as UTF-8, which supports every language. If the encoding is guessed wrongly, text shows as garbage, which is called mojibake. I also keep the files, the response header and the database in UTF-8.
What is the difference between a character, a code point and a byte?
A character is a symbol, a code point is its number in Unicode, like U+20B9, and a byte is 8 bits. UTF-8 turns one code point into 1 to 4 bytes, so a text can have fewer characters than bytes.
Compare cookies and localStorage.
A cookie is small, is sent to the server with every request and can expire, so it suits session ids. localStorage is bigger, stays in the browser, is never sent automatically and holds only strings, so it suits preferences. Neither should hold secrets.
What is a WebSocket and how is it different from normal HTTP?
HTTP is request then response, and the connection ends. A WebSocket stays open and lets both browser and server send messages any time, so it suits chat and live updates. Server-sent events are one-way, from server to browser.
What makes a website a PWA?
It is served over HTTPS, has a manifest file with name and icons, and registers a service worker that caches files and handles requests, so it can work offline and be installed like an app.
Why do you need the viewport meta tag?
Without it, phones show the page as a wide desktop page and shrink it. With width=device-width, initial-scale=1 the layout uses the real screen width, so my CSS media queries work.
Recap
- HTML 4 (SGML) then XHTML (strict XML) then HTML5 (own parser, forgiving, backwards compatible, new features).
- Semantic tags: header, nav, main, section, article, aside, footer. New inputs (email, date, number, range, color) with
required,pattern,min,maxgive built-in checks, but the server must validate. <audio>,<video>,<canvas>(pixels, JavaScript) and<svg>(vector markup) need no plug-ins.- POUR: Perceivable (alt, captions, contrast), Operable (keyboard, enough time, no seizures, input modalities), Understandable (labels, predictable, input help), Robust (valid markup, ARIA).
- Encoding: ASCII 7 bits; Unicode is the table; UTF-8 variable 1 to 4 bytes (ASCII compatible); UTF-16 2 or 4; UTF-32 fixed 4; declare
<meta charset="utf-8">. Minimum fixed bits per character is the ceiling of log2 of distinct characters. - Storage: cookie (sent to server), localStorage (persistent), sessionStorage (one tab), IndexedDB (large structured).
- WebSocket two-way; SSE one-way push; service worker gives offline and caching in a PWA; web components = custom elements + shadow DOM + templates.
- JSON, XML and Markdown are text formats; the viewport meta tag plus media queries give responsive design.
- Bits per character (fixed, minimum) = ceiling of log2 of the number of distinct characters; total = characters x bits
- UCS-4 bits / 32 x 7 = ASCII 7-bit bits; UCS-2 bits / 16 x 7 = ASCII bits
- UTF-8: U+0000-007F 1 byte; to U+07FF 2; to U+FFFF 3; to U+10FFFF 4. UTF-32 always 4 bytes
<meta charset="utf-8">and<meta name="viewport" content="width=device-width, initial-scale=1">localStorage.setItem(k, v),getItem(k),removeItem(k); useJSON.stringify/JSON.parse- POUR = Perceivable, Operable, Understandable, Robust; ARIA:
role,aria-label,aria-live ws:///wss://WebSocket;new EventSource(url)for SSE;navigator.serviceWorker.register("/sw.js")- Custom element:
customElements.define("my-tag", Class)(name has a hyphen)
- MAD2 week 3 - The web frontend: SPAs, browser storage and tooling: HTML5 storage, accessibility and PWAs are the platform features that modern frontends build on.
Practise with real exam questions
These come straight from past papers (with the real figures and the official answer key). Open 42 real questions on this week All End Term papers