Alternatives and Labels for Images, Media and Inputs
Give every image the alt text its context needs, every video its captions, and every form control a programmatic label — the three text bridges that carry meaning out of pixels.
Contentsand lesson path
On this page
- Why it matters
- Alt text: one attribute, three decisions
- Captions and transcripts for video and audio
- A label for every control
- Check your understanding
- Apply it
- Review prompt
Lessons of Semantic HTML
- Anatomy of an HTML Document Concept · 15 min
- Headings, Landmarks and the Page Outline Worked example · 20 min
- Choosing Elements by Meaning, Not Looks Concept · 20 min
- Alternatives and Labels for Images, Media and Inputs Concept · 20 min
- Lab: Mark Up an Article Page and Inspect Its Accessibility Tree Lab · 30 min
- Check: Spot the Semantic Errors Knowledge check · 8 questions
What you will learn
- Provide text alternatives and labels: meaningful alt text, captions for media, and a programmatic label for every form control.
01. Why it matters
An image is a picture to software: pixels with no meaning. A text input is a box: it has no idea what belongs in it. The only way either becomes usable for everyone — screen-reader users, voice-control users, people on slow connections where images fail to load, search engines — is text that stands in for it. That is what the alt attribute on images and the label element on form controls provide.
These two attributes are also the most common failures in real markup, and both are cheap to fix once you know the decisions involved. Neither is about compliance theatre: a missing alt turns every image into a distraction, and a missing label turns a form into guesswork. The habit this lesson builds is asking, for every picture and every field, "what would a reader need here if they could not see it?" — then writing exactly that much, and no more.
02. Alt text: one attribute, three decisions
Every img must have an alt attribute — the validator enforces that — but the value depends on what the image is doing in the page:
- Informative: the image conveys information the surrounding text does not. Write the description that someone skipping the image would need, in the context of the page — not a caption of what the picture looks like, and usually without "image of", because a screen reader already announces it as an image. A photo of a heron on a nature-reserve page becomes "A grey heron standing in shallow water at dawn".
- Decorative: the image adds atmosphere but no information. Write
alt=""— the empty string — which tells assistive technology to skip it entirely. Omitting the attribute is not the same thing: a missing alt is an error, and screen readers may fall back to announcing the file name. - Functional: the image is a control, such as a logo inside a link. The alt names what the control does ("Back to the home page"), not what the picture shows.
<img src="hero-heron.jpg"
alt="A grey heron standing in shallow water at dawn"
width="800" height="450">
<img src="divider-reeds.svg" alt="" width="800" height="24">
<figure>
<img src="hide-430.jpg"
alt="Visitors watching birds from inside observation hide 4"
width="640" height="427">
<figcaption>Hide 4 at first light, from the visitor trail.</figcaption>
</figure>The figure case splits the work in two: alt replaces the image, figcaption reads alongside it. When the adjacent caption already conveys the image's message in full, WAI guidance allows an empty alt="" to avoid forcing screen-reader users to listen to the same description twice. But when the image depicts details not mentioned in the caption, provide a concise alt describing what is pictured while figcaption provides context — the two serve complementary roles.
03. Captions and transcripts for video and audio
Video and audio carry meaning through time, and the elements that play them have no alt attribute to fall back on. The platform answer is the track element: a WebVTT caption file synchronised with the video, which deaf and hard-of-hearing users read and search engines can index. Captions must carry the speech and the sounds that matter — a caption track that says only the dialogue while a door slams on-screen has dropped information.
Two companions make the media genuinely usable: a transcript link for people who prefer or need plain text, and meaningful fallback content inside the video element for browsers that cannot play it at all. controls belongs on the element too, so keyboard users can reach the player.
<video controls width="640" src="fen-december.mp4">
<track kind="captions" src="fen-december-en.vtt" srclang="en"
label="English" default>
<p>Your browser cannot play this video.
<a href="fen-december-transcript.html">Read the transcript</a> instead.</p>
</video>04. A label for every control
A visible hint next to a text box is decoration until the two are connected. The label element makes the connection: associate it with its control using for pointing at the control's id (the robust way), or wrap the control inside the label. Once linked, the label becomes the control's accessible name — what a screen reader announces, what voice-control users say to reach the field, and what clicking focuses. A placeholder is only an unreliable last-resort name: it vanishes on the first keystroke, often has weak contrast, and does not serve as a permanent visible label.
<label for="visit-date">Visit date</label>
<input id="visit-date" name="visit-date" type="date" required>
<fieldset>
<legend>Ticket type</legend>
<label><input type="radio" name="ticket" value="adult"> Adult</label>
<label><input type="radio" name="ticket" value="child"> Child</label>
</fieldset>
<label for="email">Email address</label>
<input id="email" name="email" type="email" autocomplete="email" required>The radio group shows the two-level pattern: fieldset groups the related controls and legend names the group, so a screen-reader user on the second radio still hears "Ticket type". autocomplete on the email field lets browsers — and people filling forms under time pressure — complete it in one step.
One trap worth knowing: the recommended settings of html-validate do not check labels by default, so a page can pass with an unlabelled input. Turn the check on explicitly in your config and let the validator catch what your eyes skip:
{
"extends": ["html-validate:recommended"],
"rules": { "input-missing-label": "error" }
}To see the validator at work, save this small page with common markup errors as bad.html, next to the config above. It repeats the missing lang from the first lesson and adds a missing alt, an unlabelled input and an icon button with no type and no text:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Winter fen walk</title>
</head>
<body>
<img src="fen-map.png">
<p>Book a place on the guided walk.</p>
<input type="email" name="email">
<button><svg width="16" height="16" aria-hidden="true"></svg></button>
</body>
</html>With html-validate installed as in the lab (npm install [email protected]), run npx html-validate --formatter text bad.html. It reports one line per problem; the tool prefixes each line with the full path of the file, trimmed below:
2:2: error [element-required-attributes] <html> is missing required "lang" attribute
8:6: error [wcag/h37] <img> is missing required "alt" attribute
10:6: error [input-missing-label] <input> element does not have a <label>
11:6: error [no-implicit-button-type] <button> is missing recommended "type" attribute
11:6: error [text-content] <button> must have accessible textFive errors, each pinpointing a specific accessibility gap: the missing lang attribute from the first lesson, a missing alt attribute on an image, an unlabelled form input, a button missing its explicit type, and an icon button without accessible text. Fixing them is mechanical once the validator has named them. The full run, on a realistic page, is in the lab.
05. Check your understanding
06. Apply it
Audit a page you have built against the three bridges: every img has an alt that matches its role (informative, decorative, functional); every video has a caption track or a transcript; every input, select and textarea has a label or another accessible name, and grouped radios have a fieldset and legend. Run the validator with the label rule enabled, fix what it lists, and read each piece of alt text back in context — the page should read as if the images were never there. The skill's practice task applies the same checklist to the article page.
07. Review prompt
From memory: give the three kinds of image with the alt value each needs, say why a missing alt attribute is worse than an empty one, explain what a track element adds to a video, and list the two ways to connect a label to a control plus why a placeholder is only an unreliable fallback.
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.