Images, Media and Tables
Add images with meaningful alt text and the right file format, embed audio and video, and build accessible tables for data with headers and captions.
Welcome back!
Step 1 of 14Learn
Images and alt text
Images are added with the void element img:
<img src="images/storefront.jpg" alt="Our bakery's blue storefront on Main Street" width="800" height="533">- src is the path to the image file, relative or absolute, just like a link.
- alt is a text alternative. Screen readers read it aloud, and browsers show it if the image fails to load.
- width and height tell the browser the image's proportions before it downloads, so the page doesn't jump around as images appear. CSS can still resize the image.
Writing good alt text is a skill. Describe what the image communicates in context, briefly:
- A product photo: "Red waterproof hiking boot, side view."
- A chart: summarize its point, "Sales doubled between 2023 and 2025," and give the full data in text or a table nearby.
- A purely decorative image (a swirl or background flourish): use an empty alt,
alt="", so screen readers skip it. Don't leave alt out entirely, or some screen readers will read the file name instead.
Avoid starting with "Image of..." because screen readers already announce that it's an image. And never put important text only inside an image: it can't be read by screen readers, translated or found by search engines.
Step 2 of 14Practice · What would you do?
What would you do?
A charity's home page has a large photo of volunteers planting trees, with the heading "Join our spring planting day" in normal text below it. What is the best alt text for the photo?
Step 3 of 14Diagram
Writing alt text: a decision tree
Tap a shape with to see more.
- An image on your page
- Purely decorative?
Then use alt="" so screen readers skip it.
- Carries information?
- Contains text
Put that text in the alt.
- Is a link or button
Describe where it goes or what it does.
- A photo or illustration
Describe what matters in this context, in a short sentence.
Step 4 of 14Learn
Choosing image formats
Image files are often the heaviest part of a web page, so the format and size you choose affect how fast your page loads, especially on phones.
| Format | Best for | Notes |
|---|---|---|
| JPEG | Photos | Lossy compression; small files; no transparency |
| PNG | Screenshots, graphics with sharp edges or transparency | Lossless; larger files for photos |
| WebP / AVIF | Photos and graphics | Modern formats; usually much smaller than JPEG or PNG at similar quality; supported by current browsers |
| SVG | Logos, icons, simple illustrations | Vector format made of shapes; sharp at any size; tiny files for simple graphics |
| GIF | Very simple animations | Old format; video is usually a better choice for animation |
Two practical rules:
- Resize before uploading. A photo straight from a phone might be 4,000 pixels wide and 5 MB. If it displays at 800 pixels wide, resize it to about that size (or twice that for sharp high-density screens). The file can shrink to a tenth of its size.
- Compress. Free tools reduce file size with little visible change.
For images that sit below the first screen, adding loading="lazy" tells the browser to wait until the user scrolls near them, so the top of the page appears sooner.
Step 5 of 14Practice · Match the pairs
Match each image with the most suitable format.
Tap an answer, then tap the place where it belongs (or drag it there).
- A company logo that must look sharp at any size
- A product photo for a site with older tools that only accept common formats
- A screenshot of software with small text
- A photo where you want the smallest file at similar quality in modern browsers
Step 6 of 14Compare
Image formats at a glance
| Aspect | JPEG | PNG | WebP | SVG |
|---|---|---|---|---|
| Best for | Photos | Screenshots, images needing sharp edges or transparency | Photos and graphics, smaller files | Logos, icons, simple illustrations |
| Transparency | No | Yes | Yes | Yes |
| Scaling | Pixels: blurs if enlarged | Pixels | Pixels | Vector: sharp at any size |
| File size | Small for photos | Large for photos | Usually smallest | Tiny for simple shapes |
Step 7 of 14Note
Step 8 of 14Practice · Work it out
A photo is 4,000 × 3,000 pixels but displays at 800 pixels wide on your page. If you resize it to 800 pixels wide keeping its proportions, how many pixels tall will it be?
Step 9 of 14Practice · Chart
Pixels in the photo before and after resizing
Shrinking width and height by 5 each cuts the pixel count by 25. Browsers download every pixel, even ones they then throw away by scaling down.
Tap the version that loads faster on a phone.
Tap the bar that answers the question, then press Check.
Step 10 of 14Note
Step 11 of 14Learn
Tables are for data, not layout
A table shows data in rows and columns: a price comparison, a timetable, sports results. Here's an accessible table:
<table>
<caption>Membership plans</caption>
<thead>
<tr><th scope="col">Plan</th><th scope="col">Monthly price</th><th scope="col">Classes</th></tr>
</thead>
<tbody>
<tr><th scope="row">Basic</th><td>$20</td><td>4</td></tr>
<tr><th scope="row">Unlimited</th><td>$45</td><td>Unlimited</td></tr>
</tbody>
</table>The parts:
- table wraps everything.
- caption gives the table a title, which screen readers announce first.
- tr is a table row.
- th is a header cell; td is a regular data cell.
- scope="col" or scope="row" tells assistive technology whether a header labels a column or a row, so a screen reader can say "Unlimited, Monthly price, $45."
- thead and tbody group header and body rows.
In the early 2000s, developers used tables to lay out entire pages. Don't do that: layout tables confuse screen readers, break on small screens and are hard to maintain. Use tables only for tabular data, and use CSS (Flexbox and Grid, coming later) for layout.
Step 12 of 14Practice · Put in order
Put these table elements in order from the outermost to the innermost.
Drag the items, or use the arrow buttons, to put them in order.
- table
- tr
- tbody
- td
Step 13 of 14Diagram
The structure of an accessible data table
Tap a shape with to see more.
- table
- caption
A visible title that says what the table shows.
- thead
- tbody
- tr
- th scope="col"
Header cells tell screen readers what each column means.
- tr
- td
Ordinary data cells.
Step 14 of 14Practice · Select all that apply
Which practices make a data table more accessible? Select all that apply.
Select all that apply.
Lesson complete!