Skip to content
FORGENO ADS GAMESUnlock all $8

HTML · Unit 2: Images and page structure · Lesson 1 of 5

Images and alt text

<img> shows a picture.

Opens this lesson in Code Academy. Lessons open one after another, and each unit opens when you pass the checkpoint quiz before it (you can take a checkpoint early to skip ahead). If this lesson is not open yet, the button shows you its unit on your map.

The idea

<img> shows a picture. src is the address of the image and alt is a text description. <img> is an empty element, so it has no closing tag.

Alt text is read aloud by screen readers and shown if the image fails to load. Describe what matters in the picture in a short phrase.

If an image is only decoration, give it an empty alt (alt="") so screen readers skip it.

Worked example

HTML

<img src="https://example.com/lake.jpg" alt="A wooden canoe on a calm lake at sunrise">

The preview never loads images from other sites, so you see the alt text, just like someone whose image failed to load.

Key terms

Image
<img src="..." alt="...">: an empty element that shows a picture.
Alt text
A short description of an image, read by screen readers and shown if the image fails to load.

Practise it in Code Academy

It has 4 exercises (multiple choice, fill in the blank, fix the broken code and write code from a prompt) and takes about 6 minutes. Every answer is checked as you go, and feedback names the exact mistake. Hints and the solution are there if you get stuck.

Every lesson is free: no ads, no lives and no paywall.