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".
Console
- 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
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.
- MDN: The img element
- W3C WAI: Images tutorial (alt decision tree)
- web.dev: Cumulative Layout Shift
- MDN: The video element
Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.