Coding Lesson

← All lessons

HTML: Structure

Images and descriptions

Lesson 5 of 18 · About 20 minutes

Your goal: Add an image with useful alternative text.

Learn

An image needs both a working address and a useful explanation. You will inspect the supplied practice image, improve its alternative text, and add a visible caption. Alternative text helps when the picture cannot be seen; a caption adds context for everyone.

Walkthrough: why the code works

  1. Inspect the supplied picture first

    Open the starter in the Sandbox and look at the preview. Its image uses aquaticplant1.jpg. The learning tool supplies a practice image for this exercise. Describe what you can actually see, rather than copying a description that might refer to another picture.

  2. Understand the image attributes

    src tells the browser where to find the image. alt supplies its text alternative. width="300" requests a displayed width of 300 CSS pixels unless CSS changes it. img is a void element: it does not have a closing /img tag. Keep the quoted attribute values inside its opening tag.

  3. Write alternative text for the purpose

    Replace the broad Aquatic plants label with a short description of the visible subject that matters on your page. Do not guess species or details you cannot identify. If your own image is purely decorative, empty alt can be appropriate; this exercise uses the image as part of the lesson’s content.

  4. Keep the caption with the image

    Wrap the existing img in figure and add figcaption after it. The caption might explain why the picture belongs on your hobby page. It need not repeat the alternative text word for word. Adapt the description below after inspecting the picture.

    <figure>
      <img src="/lesson-images/aquaticplant1.jpg" alt="Aquatic plants in water" width="300">
      <figcaption>An example image for my plant page.</figcaption>
    </figure>
  5. Prepare for your own image

    For a local project, place an image you own or have permission to use beside the HTML and update src to match its filename. A picture in an images folder needs a path such as images/plant.jpg. Download HTML does not bundle linked pictures. Preserve a working absolute image URL or copy the local image file with your project.

Expected results

  • The practice image appears, followed by your visible caption.

  • The alt attribute describes the actual image; it is normally not printed beneath a successfully loaded image.

  • When using your own local image, the saved page finds it at the exact path written in src.

Common mistakes and how to fix them

  • The browser shows a broken image: Compare the filename, extension and folder with src. Check capital letters after uploading; Plant.jpg and plant.jpg may differ.

  • The caption is inside the img tag: Make figcaption a separate element after img, with both inside figure.

  • Renaming .jpg to .png did not fix the image: Changing an extension does not convert the file format. Use the real filename or export the image in the desired format.

View starter code
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>My hobby page</title>
    <style></style>
  </head>

  <body>
    <h1>My hobby</h1>
    <p>I enjoy learning something new.</p>
    <img src="/lesson-images/aquaticplant1.jpg" alt="Aquatic plants" width="300">
  </body>
</html>

Your challenge

Write a more informative alt description after looking at the preview. Add a caption below the image.

Keep developing your hobby page: Download HTML before leaving the sandbox, then choose Open HTML file when returning to your project. Load saved draft restores only this lesson’s draft in this browser.

Practise in the sandbox
Show a hint

Wrap the image in figure and add a figcaption. For your own project, keep the downloaded HTML and your image in the same folder.

Show a sample answer

Try the challenge first. This is one possible answer or a snippet to adapt.

<figure>
  <img src="/lesson-images/aquaticplant1.jpg" alt="Aquatic plants growing in water" width="300">
  <figcaption>Plants in an aquatic habitat.</figcaption>
</figure>

Check your work

The image loads, its alternative text describes it, and a caption is visible.

Completion is your own check, not an automatic grade.