Web & Mobile Development
HTML Essentials: Semantic Structure, Forms, Media and Accessibility
Beginner10 min readReviewed by Mariem Ouled on Updated
Modern HTML is a living standard, not a numbered version, and the elements you pick are an interface for browsers, assistive technology and search engines alike. This guide walks through the document skeleton, the semantic elements and what each one signals, native form validation, responsive images and media, accessible tables, and the metadata in the head that other machines read.
What you will learn
- Build a valid document skeleton and explain what the doctype, charset and lang attribute actually do
- Choose semantic elements by meaning and map them to the accessibility landmarks they expose
- Use native form controls, input types and constraint validation before reaching for JavaScript
- Deliver responsive images and accessible media with srcset, picture, alt text and captions
- Write head metadata that controls titles, canonical URLs, social previews and mobile layout
HTML has a reputation for being the easy part of front-end work, and in one sense that is fair: nothing throws an exception, nothing fails to compile, and a page with mismatched tags still renders. That forgiveness is exactly what makes it easy to write badly. The parser silently repairs your mistakes, so a document can be structurally meaningless and still look correct on your screen, while a screen reader announces it as an undifferentiated wall of text and a crawler struggles to work out what the page is about.
The useful way to think about markup is as an interface with several consumers. A browser uses it to build the DOM and the accessibility tree. Assistive technology navigates that tree by landmark, heading and control. Search engines extract structure and metadata from it. Your own JavaScript queries it. Choosing elements deliberately serves all four at once. This guide covers the parts of the language that repay that deliberation: the document skeleton, the semantic vocabulary, the head, forms, media and the accessibility rules that markup alone can satisfy.
The specification you are writing against
There is no HTML6 coming. Since 2019 there has been one specification — the WHATWG HTML Living Standard — and it is updated continuously rather than released as versions. When people say "HTML5" today they mean the modern element set and the browser APIs that arrived with it, not a frozen edition. For everyday reference the MDN documentation is more readable than the specification itself, and it carries browser-support tables that the specification does not.
A minimal, correct document looks like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Order history — Northwind</title>
</head>
<body>
<!-- content -->
</body>
</html>
Every line there earns its place. <!DOCTYPE html> is not a version declaration any more; it is the switch that puts the browser into standards mode instead of the quirks mode it keeps around for documents written in the 1990s. The lang attribute tells screen readers which pronunciation rules to use and helps translation tools; omitting it makes an English page read aloud with French phonetics on a French system. The character encoding declaration must appear within the first 1024 bytes of the file, which is why it comes first — and it should always be UTF-8. The viewport meta tag stops mobile browsers from rendering the page at a simulated desktop width and then zooming out.
Note also what is missing: no closing slash is required on void elements, attribute values only need quoting when they contain spaces or special characters, and <html>, <head> and <body> tags are technically optional because the parser infers them. Write them anyway. The inference rules are subtle, and being explicit costs three lines.
Elements that carry meaning
The sectioning and grouping elements exist so that the shape of a document is machine-readable. Most of them map directly onto an accessibility landmark, which is what lets a screen-reader user jump straight to navigation or to the main content instead of listening from the top every time.
| Element | Use it for | Landmark exposed |
|---|---|---|
header | Introductory content for the page or a section | banner, when a direct child of body |
nav | A block of major navigation links | navigation |
main | The dominant content, once per page | main |
article | A self-contained item that would make sense syndicated | article |
section | A thematic grouping, normally with a heading | region, only when it has an accessible name |
aside | Tangential content such as a sidebar or pull quote | complementary |
footer | Closing information for the page or a section | contentinfo, when a direct child of body |
figure / figcaption | Media with an associated caption | none |
Two of these are routinely misused. section is not a generic box: it only becomes a navigable region when it has an accessible name, usually supplied by a heading referenced with aria-labelledby. And article does not mean "blog post" — a comment, a product card and a forum reply are all articles, because the test is whether the block would still make sense if it were lifted out and shown on its own.
Headings are the other half of the structure. Screen-reader users navigate by heading more than by any other mechanism, so the levels must describe a real hierarchy: one h1 naming the page, h2 for its major parts, h3 for subdivisions of those. Never pick a level for its default font size — that is what CSS is for — and never skip a level on the way down. A div is still the right answer when a wrapper exists purely for layout and no element describes what is inside it; the problem is only reaching for it first.
The head, and the metadata other machines read
The head is where you talk to systems that never render your page. A production document usually carries more than the minimum:
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Refund policy — Northwind Support</title>
<meta name="description" content="How refunds are calculated, how long they take and what to do if one is late." />
<link rel="canonical" href="https://example.com/support/refunds" />
<meta property="og:type" content="article" />
<meta property="og:title" content="Refund policy" />
<meta property="og:description" content="How refunds are calculated and how long they take." />
<meta property="og:image" content="https://example.com/img/refunds-card.png" />
<meta name="twitter:card" content="summary_large_image" />
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
<meta name="theme-color" content="#0f172a" />
<link rel="preconnect" href="https://fonts.example.net" crossorigin />
</head>
The title is the single most valuable string on the page: it becomes the browser tab, the bookmark, the first thing a screen reader announces on load, and usually the search result headline. Write it specific-first, site-last. The description is not a ranking factor but it is often used verbatim as the result snippet, so it should read like a sentence rather than a keyword list. The canonical link resolves duplicate-URL problems — tracking parameters, trailing slashes, print variants — by naming the address you want indexed.
Open Graph tags control how a link renders when someone pastes it into a chat or social app. They are cheap to add and conspicuously absent on most internal tools. Resource hints such as preconnect and preload shave latency off third-party origins; used indiscriminately they do the opposite, and the trade-offs are worth understanding alongside the wider techniques in application performance.
Forms, inputs and the validation you get for free
A form is the most functionally dense part of most pages and the place where hand-rolled JavaScript most often replaces something the browser already does better.
<form action="/subscribe" method="post">
<fieldset>
<legend>Delivery details</legend>
<label for="email">Email address</label>
<input id="email" name="email" type="email" autocomplete="email" required />
<label for="postcode">Postcode</label>
<input id="postcode" name="postcode" type="text" inputmode="numeric"
pattern="[0-9]{5}" autocomplete="postal-code" required
aria-describedby="postcode-hint" />
<p id="postcode-hint">Five digits, no spaces.</p>
<label for="qty">Quantity</label>
<input id="qty" name="qty" type="number" min="1" max="20" step="1" value="1" />
</fieldset>
<button type="submit">Subscribe</button>
</form>
Every control needs an accessible name, and the reliable way to give it one is a label whose for matches the input's id. Placeholder text is not a label: it disappears when typing starts, it fails contrast requirements in most designs, and some assistive technology ignores it. The name attribute is what appears in the submitted payload, so a control without one submits nothing.
Choosing the right type buys behaviour you would otherwise write by hand — an appropriate mobile keyboard, a date picker, a colour picker, format checking. Combine that with required, pattern, min, max, step and maxlength and you have declarative validation that works without a single line of script, exposes :invalid and :user-invalid to CSS, and is keyboard accessible by construction. When you need custom rules, the Constraint Validation API lets you keep the same machinery: call setCustomValidity() on the element, or add novalidate to the form and drive the messages yourself.
Getting autocomplete tokens right is a small change with an outsized effect on completion rates, because it lets the browser and password manager fill known values. And none of this is a security boundary: attributes can be edited in devtools and requests can be sent directly to your endpoint, so the server must revalidate everything and answer with a precise status code — the distinction between a malformed body and a semantically invalid one is covered in the HTTP status code reference.
Images, media and responsive delivery
Images are usually the largest bytes on a page, so markup choices here dominate load time.
<figure>
<img src="/img/chart-800.avif"
srcset="/img/chart-400.avif 400w,
/img/chart-800.avif 800w,
/img/chart-1600.avif 1600w"
sizes="(min-width: 60rem) 40rem, 100vw"
width="1600" height="900"
loading="lazy" decoding="async"
alt="Monthly refund volume falling from 1,200 in January to 300 in June." />
<figcaption>Refund volume after the policy change.</figcaption>
</figure>
srcset offers the browser several resolutions of the same image and sizes tells it how wide the image will actually be laid out, so it can pick before the CSS has been parsed. Always set width and height: they let the browser reserve the right box before the file arrives, which removes the layout shift that pushes text around as a page loads. loading="lazy" defers off-screen images, but never apply it to the image at the top of the page — that is the one you want fetched first.
When you need genuinely different sources rather than different sizes — a square crop on mobile, or a modern format with a fallback — use picture with several source elements and a final img. Whatever the wrapper, the img carries the alt text, and writing it well is the single highest-value accessibility habit: describe the information the image conveys in its context, not the file. A decorative flourish takes alt="" so it is skipped entirely; omitting the attribute instead makes screen readers read the file name aloud. Before shipping assets it is worth running them through an optimiser such as the image compressor or resizing oversized originals with the image resizer.
Video and audio follow the same logic. Add controls unless you are replacing them with accessible ones, provide captions with a track element of kind="captions", supply a poster frame, and avoid autoplay with sound. Use preload="metadata" rather than the default so that a page with several clips does not start downloading all of them.
Tables that survive a screen reader
Tables are for data, never for layout. The markup that makes one navigable is small:
<table>
<caption>Refunds by region, first half of 2026</caption>
<thead>
<tr><th scope="col">Region</th><th scope="col">Requests</th><th scope="col">Median days</th></tr>
</thead>
<tbody>
<tr><th scope="row">North</th><td>1,204</td><td>3.1</td></tr>
<tr><th scope="row">South</th><td>884</td><td>4.6</td></tr>
</tbody>
</table>
The caption names the table, th with scope tells assistive technology which cells are headers for which direction, and marking the first cell of each row as a row header means a screen reader can announce "North, median days, 3.1" instead of a bare number. For irregular tables with merged cells, headers and id attributes let you associate cells explicitly. If a table is wide, wrap it in a scrolling container with tabindex="0" and a role so keyboard users can reach the overflow.
The APIs the platform gives you
Alongside the elements, browsers expose a large standard library that is worth knowing before you add a dependency for it. localStorage and sessionStorage hold small string values synchronously and are perfect for a theme preference — and wrong for anything sensitive, since any script on the origin can read them. IndexedDB handles structured, larger, asynchronous storage. canvas gives a pixel surface for charts and image processing, while inline SVG stays crisp and stays in the DOM where it can be styled and made accessible. The History API rewrites the address bar without a reload, which is how client-side routers work. Web Workers move expensive computation off the main thread. Custom elements let you package a widget as a real tag with its own encapsulated styles. Most of these are reached through JavaScript, and the language features you need for them are covered in JavaScript fundamentals.
Validating, and the mistakes that survive review
Run the W3C markup validator, or an equivalent linter in your build, and treat its output as a build error. Because the parser repairs mistakes silently, validation is the only cheap way to catch structural problems. The recurring ones:
- Duplicate
idvalues, usually from a repeated template. Label associations and fragment links then point at whichever element came first. - Inputs with no label, hidden behind a placeholder or an icon with no accessible name.
- Heading levels chosen for size, producing an outline that jumps from
h1toh4. - Interactive
divelements with a click handler and no keyboard support. If it behaves like a button, make it abutton. alttext that repeats the caption or starts with "image of", which screen readers already announce.- Missing
widthandheighton images, which is the most common cause of layout shift. - Nested interactive controls, such as a link inside a button, which produce undefined keyboard behaviour.
- ARIA used to patch bad markup. A wrong role is worse than no role; the first rule of ARIA is to use the native element instead.
Key takeaways
- HTML is a living standard with no version numbers; write against the WHATWG specification and check support on MDN rather than looking for the next release.
- Elements are an interface for browsers, assistive technology and crawlers at once — choose them by meaning, and the accessibility landmarks and document outline come for free.
- The head controls how machines see the page: an accurate title, a real description, a canonical URL and Open Graph tags cost minutes and pay off permanently.
- Native form controls, input types and constraint validation deliver accessible, keyboard-friendly validation with no script, but they never replace validation on the server.
- Responsive images with
srcset, explicit dimensions, honestalttext and captioned media are the cheapest performance and accessibility wins available. - Validate your markup and treat the recurring faults — duplicate ids, unlabelled inputs, clickable divs, ARIA papering over the wrong element — as defects rather than style opinions.
Sources and further reading
Frequently asked questions
- Is HTML5 still the current version of HTML?
- No. HTML stopped being released as numbered versions in 2019, when the W3C and the WHATWG agreed that the WHATWG HTML Living Standard would be the single specification. It is updated continuously, so features arrive without a version bump. The phrase HTML5 survives as shorthand for the modern element set and the browser APIs that shipped alongside it, but there is nothing newer called HTML6 to wait for.
- When should I use a div instead of a semantic element?
- Use a div when the only reason the wrapper exists is styling or layout, and no existing element describes the content. If the block is site navigation, a self-contained piece of content, a page footer or the main body of the document, the corresponding semantic element gives assistive technology a landmark for free. Reaching for a div first and adding an ARIA role later is more work and easier to get wrong.
- Do I still need client-side validation if the server validates?
- Yes, but for a different reason. Browser constraint validation gives instant, keyboard-accessible feedback and stops obviously malformed submissions, which is a usability win. It is not a security control, because anyone can disable JavaScript, edit the attributes or post directly to your endpoint. Treat every field as untrusted on the server and return a precise error status when it fails.
- What is the difference between srcset and the picture element?
- srcset with sizes lets the browser choose among versions of the same image that differ only in resolution; the browser decides using viewport width, device pixel ratio and its own heuristics. The picture element is for cases where you must control the choice yourself — a different crop on small screens, or an AVIF file with a JPEG fallback for browsers that cannot decode it.