Tsallaka zuwa abun ciki
Justice Tech School

Images

The img element shows a picture. It has no closing tag. src is the file and alt is a text description.

Always write a useful alt. It is read aloud to blind users and shown if the image fails to load.

Example
<img src="data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 width=%27160%27 height=%2790%27%3E%3Crect width=%27160%27 height=%2790%27 fill=%27%23166534%27/%3E%3Ctext x=%2780%27 y=%2752%27 fill=%27white%27 text-anchor=%27middle%27 font-size=%2720%27%3ESample%3C/text%3E%3C/svg%3E" alt="A green sample banner" width="160">
  • Set width and height so the page does not jump while the image loads.

Exercise

Add the attribute that describes the image for screen readers.

<img src="cat.jpg" ="A sleeping cat">

Quiz Test

What is the alt attribute for?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.