Skip to content

HTML Images, Video and Audio: img, alt Text, figure, srcset and Lazy Loading

NeedMyTools Academy

Sign in free to read the full lesson

Sign in or create a free account

Free forever. No card, no paywall.

Images are often the heaviest part of a page and the part people with low vision or slow connections struggle with most. A few attributes decide whether an image is described to blind visitors, whether the page jumps around while it loads, and whether a phone downloads a 4 MB photo it shows at 400 pixels wide. This lesson covers images first, then video and audio.

Quick answer

Use <img src="photo.jpg" alt="what the image shows" width="800" height="600">. Write alt text that replaces the image for someone who cannot see it, or alt="" for purely decorative images. Width and height stop layout jumps, and loading="lazy" delays images further down the page.

20 min read and practice · Content checked on 20 October 2026

In this lesson you will

  • Write alt text that actually helps
  • Stop layout shift and save data with width, height, srcset and lazy loading
  • Embed video and audio that people can control

The img element and alt text

<img> is a void element: no closing tag. src is the image address, written like a link URL. alt is the text alternative. Screen readers read it, browsers show it if the image fails to load, and search engines use it to understand the image.

Good alt text says what the image means in this place, briefly. A product photo might be "Black leather office chair, front view". A chart needs its key fact: "Sales rose from 2 to 5 million dirhams between 2023 and 2025". Do not start with "image of"; screen readers already say it is an image.

If an image is only decoration, such as a background swirl, write alt="" (empty, not missing). Screen readers then skip it. If you leave alt out completely, many screen readers read the file name instead, such as "IMG underscore 4 0 2 1 dot jpg".

Try it: alt text, and what happens when an image fails
Code
ResultUpdates as you type
Console
  1. Console messages, errors, form data and clicked links appear here.

Sign in free to read the full lesson

You are reading the free preview. Create a free account (it takes one minute, no password) to unlock the rest of this lesson and track your progress.

Unlocks after sign-in:

  • 2 more sections with live code examples
  • Common mistakes to avoid
  • Hands-on coding exercise with automatic checks
  • Practice quiz and the graded lesson test
Sign in or create a free account

Free forever. No card, no paywall.

Questions people ask

How long should alt text be?

As short as possible while still doing the job, usually one sentence. There is no official character limit. If an image needs a long explanation, such as a detailed chart, describe it in the page text or a caption and keep alt short.

Which image format should I use?

Photos: WebP or AVIF where possible, JPEG as a fallback. Logos and icons: SVG. Screenshots with text: PNG or WebP. All modern browsers support WebP; you can offer AVIF with a fallback using <picture>.

Can I use any image I find on Google?

No. Most images are protected by copyright. Use your own photos, images you have a licence for, or free libraries whose licence allows your use, and keep a note of the source.

What is the difference between img and a CSS background image?

Use <img> when the image is content that means something. Use a CSS background for pure decoration. Background images have no alt text, so screen readers do not know they exist.

Should I host videos on my own site?

Short clips are fine. For long videos a video platform usually handles streaming quality, captions and bandwidth better. Self-hosted video costs bandwidth every time it plays.

Sources

Facts in this lesson were checked against these official pages on 20 October 2026.

Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.