Unit 2: Semantic HTML and Forms
I. Orientation: Semantics, Structure and the Accessibility Contract
HTML5 (W3C Recommendation, October 2014; now maintained as the WHATWG HTML Living Standard) shifted authoring away from presentational markup toward meaning. A <div class="header"> tells a browser nothing; a <header> tells it, and every assistive technology and search crawler reading it, what the region is. Every topic in this unit rests on the same contract: markup declares meaning, CSS declares appearance, and the accessibility tree is derived automatically from the former.
- Semantic element: an element whose name describes the role of its content rather than its rendering —
<article>,<nav>,<time>. Contrast<b>and<i>, which are presentational survivors retained for typographic convention only. - Non-semantic element:
<div>(block) and<span>(inline) — generic containers carrying no meaning; used only when no semantic element applies. - The accessibility tree: a parallel structure the browser builds from the DOM, exposing each node's role, name, state and value to screen readers via platform APIs (MSAA/UIA on Windows, AX on macOS).
- Implicit ARIA role: every semantic element ships with one for free.
<nav>→role="navigation",<main>→role="main",<button>→role="button". This is why "use the right element" beats "add ARIA". - Content model: HTML5 replaced block/inline with categories — flow, phrasing, sectioning, heading, embedded, interactive.
<p>accepts phrasing content only, so a<div>inside a<p>is invalid. - Document outline: derived from
<h1>–<h6>and sectioning elements; screen-reader users navigate by heading far more than by reading linearly.
II. Semantic HTML Elements
The vocabulary of meaning
A. The sectioning and grouping vocabulary
Semantic elements divide into sectioning elements (which create outline entries) and text-level elements (which annotate phrases).
<article>: independently distributable content — a blog post, a comment, a product card. Test: would it still make sense syndicated in an RSS feed alone?<section>: a thematic grouping, normally requiring a heading.<section>without a heading is usually a misused<div>.<nav>: major navigation blocks only. A footer's three legal links need no<nav>; the primary menu does.<aside>: tangentially related content — pull quotes, sidebars, related links.<header>/<footer>: scoped to their nearest sectioning ancestor. An<article>may hold its own<header>with byline and<time datetime="2026-08-04">.<figure>/<figcaption>: binds an image, diagram or code listing to its caption programmatically.- Text-level:
<em>(stress emphasis) vs<i>(alternate voice, e.g. taxonomic names);<strong>(importance) vs<b>(keywords without importance);<mark>,<abbr title="…">,<code>,<time>.
<article>
<header><h2>Semantic Markup</h2>
<p>By A. Rao · <time datetime="2026-08-04">4 Aug 2026</time></p>
</header>
<p>HTML5 introduced <abbr title="Accessible Rich Internet Applications">ARIA</abbr>-mapped elements…</p>
</article>B. Page Structure and Layout
A page's skeleton should be readable as an outline with CSS disabled.
<main>: exactly one per document, holding content unique to that page; must not be nested in<article>,<aside>,<header>,<footer>or<nav>. It is the target of "skip to content" links.- Canonical skeleton:
<body>→<header>(banner) →<nav>→<main>→<aside>→<footer>(contentinfo). - Landmarks:
banner,navigation,main,complementary,contentinfo,search,form. Screen readers offer a landmark rotor; a<div>-only page presents an empty rotor. - Disambiguating repeats: two
<nav>elements need distinguishing names —<nav aria-label="Primary">and<nav aria-label="Breadcrumb">. - Heading hierarchy: one
<h1>describing the page, then descending without skipping levels.<h1>→<h3>signals a missing section to a rotor user. - Layout belongs to CSS: Grid places
<main>and<aside>visually;orderandgrid-areachange visual order only — DOM order still governs tab and reading order, so avoid divergence.
III. Forms and Form Controls
Collecting and validating user input
A. Forms and Form Controls
A form is a container that serialises named controls into a request.
<form>attributes:action(endpoint URL),method(getappends a query string, for idempotent searches;postputs data in the body, for state changes),enctype(multipart/form-datais mandatory for<input type="file">),novalidate(suppresses native validation).- The
nameattribute: only named controls are submitted.name="email"with valuea@b.comserialises asemail=a%40b.com;idis for label binding and CSS, not submission. - Controls:
<input>,<textarea>(sized byrows/cols, value is its text content),<select>with<option>/<optgroup>andmultiple,<button>(type="submit"is the default inside a form — settype="button"for JavaScript-only buttons),<datalist>for suggestion lists,<output>for computed results. - Grouping:
<fieldset>+<legend>groups related controls; the legend is announced with each radio in the group, which is the only reliable way to name a radio set. - Labels: explicit
<label for="id">or wrapping. A label enlarges the click target and gives the control its accessible name.
<fieldset>
<legend>Delivery speed</legend>
<input type="radio" id="std" name="ship" value="standard" checked>
<label for="std">Standard (5 days)</label>
<input type="radio" id="exp" name="ship" value="express">
<label for="exp">Express (24 hours)</label>
</fieldset>B. Input Types and Attributes
The type attribute selects a control's UI, on-screen keyboard and validation algorithm.
- Text-like:
text,email(validates one@),url,tel(no validation — pattern it yourself),password,search. - Numeric and temporal:
number(withmin,max,step),range(slider),date,time,datetime-local,month,week. - Other:
checkbox,radio,file(accept=".pdf,image/*",multiple),color,hidden. - Attributes:
- Constraint:
required,min,max,minlength,maxlength,step,pattern(an anchored JS regex). - Behavioural:
placeholder(a hint, never a label substitute — it vanishes on focus),autocomplete="email"(WCAG 1.3.5 relies on it),readonly(submitted) vsdisabled(not submitted),autofocus,inputmode="numeric".
- Constraint:
C. Form Validation Basics
Constraint validation runs in the browser before submission and exposes state to CSS and JavaScript.
- Order: on submit, the browser checks each control; the first invalid one is focused and shows a native bubble; submission is blocked.
ValidityState:input.validityexposesvalueMissing,typeMismatch,patternMismatch,rangeUnderflow,rangeOverflow,tooLong,stepMismatch, andvalid.- Custom messages:
input.setCustomValidity("Passwords must match")marks the control invalid until called with"". - Styling:
:required,:invalid,:valid, and:user-invalid— the last only matches after interaction, avoiding red borders on an untouched form. - Client vs server:
- Client-side: instant, no round trip, improves UX — but trivially bypassed via devtools or curl.
- Server-side: authoritative; the only defence against injection and tampering. Client validation is a convenience, never a security control.
<label for="pin">6-digit PIN</label>
<input id="pin" name="pin" type="text" inputmode="numeric"
pattern="\d{6}" required aria-describedby="pinHelp">
<p id="pinHelp">Exactly six digits.</p>IV. Tables and Data Representation
Marking up two-dimensional relationships
A. Tables and Data Representation
A table encodes data whose meaning depends on the intersection of a row and a column — never page layout.
- Structure:
<table>→<caption>(the table's accessible name, first child) →<thead>/<tbody>/<tfoot>→<tr>→<th>/<td>. scope:<th scope="col">and<th scope="row">tell a screen reader which cells a header governs. Without it, "42" is announced bare; with it, "Rainfall, June, 42".- Complex tables:
idon headers plusheaders="h1 h2"on cells handles irregular spans; prefer splitting into simpler tables. - Spanning:
colspan/rowspan;<colgroup>/<col>for column-wide styling. - Responsive tables: wrap in a scrollable container with
overflow-x:autoandtabindex="0"so keyboard users can scroll it, rather than restacking cells and destroying header association.
V. Accessibility
Designing for the full range of users
A. Accessibility Fundamentals
Accessibility means the interface is operable by users with visual, motor, auditory or cognitive impairments, using keyboards, screen readers or switch devices.
- Accessible name: computed in order —
aria-labelledby, thenaria-label, then<label>/alt/<caption>, then contents. - Alt text:
altdescribes function, not appearance (alt="Search"on a magnifier icon); decorative images takealt=""to be skipped. - Keyboard operability: every interactive element must be reachable by Tab and triggered by Enter/Space.
<div onclick>fails both;<button>gets them free. - Focus visibility: never
outline: nonewithout a replacement:focus-visiblestyle. - ARIA rules: no ARIA is better than bad ARIA; do not change native semantics (
<button role="heading">);aria-live="polite"announces asynchronous validation errors.
B. Accessibility Standards
WCAG 2.1 (W3C Recommendation, June 2018) is the reference standard, organised under four principles and three conformance levels.
- POUR: Perceivable (1.1.1 non-text content), Operable (2.1.1 keyboard, 2.4.7 focus visible), Understandable (3.3.2 labels or instructions), Robust (4.1.2 name, role, value).
- Levels: A (minimum), AA (the legal target of the EU Web Accessibility Directive and Section 508), AAA (rarely required site-wide).
- Contrast: 4.5:1 for normal text and 3:1 for large text (≥18.66px bold or ≥24px) at AA — 1.4.3.
- WAI-ARIA 1.2: supplies roles, states and properties for widgets HTML lacks, e.g.
role="tab"witharia-selected.
C. Responsive Content Structuring
Responsive design begins in the markup: source order and element choice determine what CSS can do at any breakpoint.
- Viewport meta:
<meta name="viewport" content="width=device-width, initial-scale=1">; omit it and mobile browsers assume a ~980px canvas and shrink everything. - Responsive images:
srcsetwithwdescriptors plussizeslets the browser pick by resolution;<picture>with<source media="…">handles art direction — a cropped portrait on narrow screens. - Mobile-first source order: author the DOM in logical reading order and rearrange with Grid, so a linearised narrow view remains coherent.
- Fluid units:
remfor type (respects the user's browser font size, unlikepx),%/fr/minmax()for layout,clamp(1rem, 2.5vw, 1.5rem)for fluid scaling. - Touch targets: WCAG 2.5.5 advises a minimum of 44×44 CSS pixels — a concern for tightly stacked checkbox lists and inline links.
- Preferences:
@media (prefers-reduced-motion: reduce)and(prefers-color-scheme: dark)respond to OS-level accessibility settings.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →