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.altis a short description of what the picture shows.widthsets 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
- Add an image of the cat using
cat.svg. - Give it
alttext that describes the picture. - Set its
widthto200. - Add a second image,
mountain.svg, with its ownalttext.
- There is an image with
src="cat.svg" - The cat image has
alttext of at least two words - The cat image has
width="200" - There is a second image,
mountain.svg, withalttext
Lesson complete!
Next Lesson: Lists