Skip to content

Images

Add pictures to your page

  • Lesson
  • 1 min read
  • 5 of 7 in this chapter

Adding Images

The image element has no closing tag, but it does have a src (source) attribute with the link to the image:

HTML
<img src="cheetah.png">

This code would work if there was a saved image named "cheetah.png" in the same folder as your HTML file. Instead of saving an image like that, we can also use a link to an image on the internet, for example:

HTML
<img 
src="https://images.pexels.com/photos/162313/cheetah-sitting-big-cat-feline-162313.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500">

Alt text

Images also have another attribute: alternative text. This text is shown instead of the image if, for whatever reason, the image can't be displayed. Alt text is also useful to people who use screen readers.

HTML
<img src="cheetah.png" alt="cheetah">