HTML Accessibility
Previously, datalist wired suggestions to one text input. Accessibility is a wider job: make the whole page usable with keyboards, screen readers, zoom, and different contexts. Good HTML — landmarks, labels, alt, headings, real buttons — is the foundation, not a late polish layer.
Why accessibility matters
People browse without a mouse, enlarge text, or hear the page through assistive tech. A chart with no alt is silent; a search box with no label is nameless; a clickable div may never receive keyboard focus. Inclusive markup helps everyone — clearer outlines, better SEO signals from structure, and fewer “mystery controls.” Accessibility is mostly habits you apply while writing HTML, not a separate product.
Direct answer
1) Prefer semantic regions (main, nav, header, footer) and native controls (button, a, labeled inputs).
2) Give every form control a visible <label> tied with for / id.
3) Write meaningful alt for informative images; use empty alt="" only when the image is purely decorative.
4) Keep one clear h1 and nest h2–h3 without wild level skips.
5) Tab through the page: links and buttons must be reachable and operable without a pointer.
6) Add ARIA only when native HTML cannot express the role — fix structure first.
📊 Accessibility habits beginners use
| Habit | Why it helps | Beginner tip |
|---|---|---|
| Semantic landmarks | Tools jump to regions | Prefer main/nav over anonymous divs |
| Labels on controls | Names fields clearly | for= must match the control id |
| Alt on images | Describes non-text content | Say what the image communicates |
| Logical headings | Outlines the page | Do not jump h1 → h4 for style |
| Keyboard-operable controls | Not everyone uses a pointer | Prefer button/a over clickable divs |
| Native before ARIA | Roles come built-in | Repair HTML; do not wallpaper broken markup |
Labeled search with a landmark
A small search strip shows the pattern: a nav with an accessible name, a labeled search field, and a real submit button. Screen readers can announce the region and the control name; keyboard users can Tab to the input and the button.
<nav aria-label="Site">
<label for="q">Search</label>
<input id="q" name="q" type="search">
<button type="submit">Search</button>
</nav>
Reading the search demo
navmarks a navigation landmark;aria-labeldisambiguates when several navs existlabel for="q"+input id="q"gives the field an accessible namename="q"is for submit — separate from the accessible nametype="search"is a native control with expected keyboard behavior- A real
<button type="submit">is focusable and activatable with Enter/Space - Compare with last lesson: datalist helped suggestions; here the focus is naming and reachability
Headings, alt text, and a real button
A second snippet sketches article structure: an h1, a nested h2, an informative image with descriptive alt, and a submit-style action as a <button>. This is the opposite of “click here” links and unlabeled charts.
<main>
<h1>Monthly sales</h1>
<h2>Q1 results</h2>
<img src="chart.png" alt="Bar chart: sales rose from 10 to 18">
<p>Sales climbed through March.</p>
<button type="button">Download report</button>
</main>
Reading the structure demo
- One
h1sets the page topic;h2nests under it without skipping toh4 - The chart’s
altstates the takeaway, not just “image” or a filename - Decorative spacers would use
alt=""— this chart is informative, so alt is required - The action uses
<button>, not adivwith a click handler mainlandmarks the primary content for assistive tech- Next lesson adds JavaScript; keep these HTML habits when you wire behavior
Choosing what to fix first
- Unnamed fields: add labels before fancy placeholders
- Silent images that carry meaning: write alt that carries the point
- Fake controls: replace clickable
div/spanwithbuttonora - Heading soup: restore a logical outline instead of styling with random levels
- ARIA-only patches: if a native element exists, use it; ARIA supplements, it does not forgive bad structure
- Keyboard dead ends: anything you can click must be reachable with Tab and activatable with keyboard
Practice — page-wide habits
- Copy the search demo; remove the label and Tab with a screen-reader or accessibility tree — then restore
for/id. - Add a second
nav(for example footer links) and give eachnava distinctaria-label. - In the structure demo, change the chart alt to empty and note what is lost; restore a meaningful alt.
- Intentionally skip from
h1toh4, then fix the outline back toh1→h2. - Replace the button with a
divthat only has a click hint in your mind — then put the real<button>back and Tab to it. - Write one sentence: accessibility starts with HTML structure, not ARIA wallpaper.
- Peek ahead: the next lesson adds a
<script>— keep labels and buttons when behavior arrives.
Easy mistakes
- “Click here” links with no surrounding context
- Informative images with missing or empty alt
- Custom clickable
divs that ignore keyboard users - Using heading levels only for visual size
- Treating placeholder text as a substitute for
<label> - Piling ARIA roles onto broken markup instead of fixing semantics
- Forgetting that last lesson’s datalist still needed a label on the input
Summary
- Accessibility is usable structure for more people and more tools
- Landmarks, labels, alt, headings, and native buttons matter
- Keyboard reach is part of the job, not optional
- Prefer solid HTML before heavy ARIA
- Datalist taught one control; this lesson zooms out to the page
- Next: adding JavaScript to HTML pages
🧠 Test Your Knowledge
Test Your Knowledge
Challenge yourself with this interactive quiz and see how well you understand the topic
📝 Instructions
- Read each question carefully
- Select the best answer for each question
- You can retake the quiz as many times as you want
- Your progress will be shown at the top