KodingKaro
HTML · Beginner · Images and Media

Images, dimensions, and alternative text

Images can communicate important information, so HTML needs to describe their purpose when they cannot be seen.

✓ What you will learn in this topic

  • Explain the purpose of Images, dimensions, and alternative text in a real HTML document.
  • Choose and apply the elements shown in both examples.
  • Recognize the specific mistake described in this lesson.

Concept explanation

The img element uses src to locate an image and alt to provide its text alternative. Describe the information the image adds, not every visual detail. For decoration that adds no information, use alt=\"\" so assistive technology can skip it. Width and height provide intrinsic dimensions and help the browser reserve space before the file arrives. A nearby caption can add context that does not belong in alt.

Syntax

Use \"...\"; alt is required even when its value is empty.

Example 1: a small page

The alternative text states the useful information and dimensions describe the image’s intrinsic size.

<img src=\"seedling.jpg\" alt=\"Two green seedlings in a terracotta pot\" width=\"640\" height=\"420\">

Expected result: A seedling photo appears if the file exists; its text alternative is available when it cannot be viewed.

Example 2: a practical page

Figure groups the map with a visible caption, while alt communicates its route information.

<figure>
  <img src=\"market-map.png\" alt=\"Map showing the market entrance on King Street and accessible route to the hall\" width=\"900\" height=\"600\">
  <figcaption>Visitor map for the Saturday market.</figcaption>
</figure>

Expected result: The map appears with a caption and a detailed text alternative describing the key route.

Common mistakes

Do not omit alt on img; use meaningful text for informative images and an empty value for decorative images.

Best practices

Provide intrinsic image dimensions, captions where they add context, and captions or transcripts for media people cannot hear or see.

Practice exercise

Build an event page with an informative photo, a decorative icon, an audio clip with a transcript link, and a video with captions.

Lesson summary

  • Choose alt text based on the image’s purpose and reserve space with known dimensions.
  • Provide intrinsic image dimensions, captions where they add context, and captions or transcripts for media people cannot hear or see.

Knowledge check

What should alt contain for a decorative image?

Show the explanation

Use alt=\"\" when the image contributes no information so it is skipped by assistive technology.

Practical example

html
<img src=\"seedling.jpg\" alt=\"Two green seedlings in a terracotta pot\" width=\"640\" height=\"420\">

Expected result:

A seedling photo appears if the file exists; its text alternative is available when it cannot be viewed.

Hands-on practice task

Build an event page with an informative photo, a decorative icon, an audio clip with a transcript link, and a video with captions.

In this section

Other lessons in Images and Media

Broaden your knowledge

Related learning topics