Add Images With Alt Text

Your seed swap page links back up the folder tree, and like every page on Rosa’s site so far, it’s all text. Rosa has photos of the plots, and she wants one of Mei’s plot 7 on the home page.

In this lesson, you’ll put that photo on the page, write alt text that does its job for people who can’t see it, give it a caption, and choose a file format for each kind of image. Start by getting the photo onto the page.

Put a Photo on the Page

A photo is a file of its own, so the page needs an element that points at it. The course comes with a set of photos of the garden. Download them here and unzip the file:

In VS Code’s Explorer, create an images/ folder inside garden/ and copy plot-7.jpg from the photos into it. It’s Mei’s plot, a raised bed of tomatoes and lettuce, 1200 pixels wide. For now, the browser shows a photo at full size, so it may spill past the window.

Then open index.html and add these lines inside <main>, after the welcome paragraph:

Language: HTML
<img
  src="images/plot-7.jpg"
  alt="Plot 7, a raised bed of staked tomatoes and lettuce"
>

Like <meta>, <img> is a void element with no end tag. Its two attributes do different jobs:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.