HTML Basics · Lesson 5 of 11

Images

Pictures are added with the <img> tag. Like <br>, it is an empty element with no closing tag. Everything it needs is in its attributes:

<img src="cat.svg" alt="An orange cat looking at the camera" width="200">
  • src (source) is the address of the picture file.
  • alt is a short description of what the picture shows.
  • width sets the size in pixels. The height follows automatically, so the picture keeps its shape.

Why alt text matters

The alt text is read aloud by screen readers, shown when a picture fails to load, and used by search engines. Describe what is in the picture, in a few words, as if telling someone over the phone. Do not start with "picture of".

Practice pictures

This editor has four pictures built in for you to practice with: cat.svg, dog.svg, mountain.svg and logo.svg. On a real website, src would point to a file in your site's folder or to a full address.

A picture as a link

Because tags can be nested, you can put an image inside a link to make the picture clickable:

<a href="https://example.com"><img src="logo.svg" alt="Example home page"></a>

Your Task

  1. Add an image of the cat using cat.svg.
  2. Give it alt text that describes the picture.
  3. Set its width to 200.
  4. Add a second image, mountain.svg, with its own alt text.
  • There is an image with src="cat.svg"
  • The cat image has alt text of at least two words
  • The cat image has width="200"
  • There is a second image, mountain.svg, with alt text