smartyfy.mrindigi.com

Web Development Pro | Lesson 004 | Images, Alternatives, and Figures

Web Development Pro · Lesson 04 of 60

Module 1: HTML foundations

In this lesson

Prerequisites and learning outcomes

Complete lesson 3 first. This lesson builds on image purpose, alt text, and dimensions. By the end, you can choose useful text alternatives and reserve image space without distortion. Plan 10–15 minutes for the core explanation and additional time for the worked practice.

Begin with the image's job

A workshop page might use a photograph to show a repair activity, a logo to identify the group, or a diagram to explain a bicycle part. These images do different jobs. Before writing alt text, ask what the reader would lose if the image were unavailable. The answer depends on the surrounding content and purpose, not just the objects visible in the file.

For an informative photograph, a concise alternative can communicate the relevant information. For a purely decorative flourish, alt="" lets assistive technology skip it. Leaving the alt attribute out is different: the browser or assistive technology may expose a filename or otherwise handle the missing alternative. An empty alternative is a deliberate editorial decision, not an excuse to ignore important content.

Write alternatives in context

Suppose the page already says “Bicycle tube patching, Saturday at 10.” A nearby decorative photo of a wheel may not need to repeat those words. But an image showing the three places to check for tire damage needs an equivalent explanation. A short alt can name the diagram, while adjacent text supplies the complete instructions. A complex chart rarely fits well into one enormous attribute.

Avoid automatically beginning every alternative with “Image of.” The element's role is often already announced. Describe what matters: “Volunteer showing a participant how to locate a puncture” is useful when collaboration is the point. Do not infer someone's identity, mood, or personal characteristics from a photo when those facts are not established or relevant.

<figure>
  <img src="images/repair-tools.svg"
       width="640" height="360"
       alt="A tire lever, a patch, and a hand pump laid out for repair">
  <figcaption>Three tools used in the bicycle basics session.</figcaption>
</figure>
<img src="images/divider.svg" width="320" height="16" alt="">

Both SVG files are supplied with this lesson's standalone example. The first figure groups an image with its caption. The caption is visible context, and the alternative communicates the important visual content. They need not repeat the same sentence. The second image is only a divider, so its empty alternative prevents decorative information from interrupting the reading flow.

Keep dimensions honest

The width and height attributes describe the image's intrinsic dimensions or a matching aspect ratio. They help the browser reserve space before the image finishes loading. Without reserved space, content may jump when the image appears. CSS can still resize the image responsively. A common later rule is max-width: 100%; height: auto, which keeps it within a container while preserving its proportions.

Do not force a 640-by-360 image into a square by setting unrelated width and height values unless intentional cropping is implemented with CSS. Stretching changes the image's geometry. Cropping can also remove important content, such as text or the exact part a repair diagram identifies. Review the chosen crop at the actual displayed size rather than only viewing the original asset.

Image files also have byte sizes, which are different from dimensions in pixels. A large photograph can contain far more data than a simple icon at the same width. Resize and compress assets appropriately, and choose a suitable format. SVG suits many simple diagrams; photographic formats suit photographs. Later lessons compare responsive alternatives, but the first principle is to avoid shipping unnecessary data.

Make linked images understandable

If an image is the only content of a link, its alternative normally supplies the link's accessible name. A logo linking home should communicate that destination or the organization's name in context. A vague alternative such as “picture” gives almost no navigation help. If adjacent text inside the same link already provides the name, an empty image alternative can avoid duplication.

Never use text embedded in an image as the only way to convey essential workshop details when real HTML text can do the job. Image text is harder to resize, translate, search, and adapt to user preferences. An image may illustrate the schedule, but the dates and session names should remain available as actual text.

Verify failure as well as success

Temporarily change the image path in a disposable copy and inspect what remains understandable. A browser may display some alternative text when loading fails, but that visual behavior is not a complete test of screen-reader output. Also check that the file path matches the real filename exactly and that the supplied asset is licensed or created for the project.

Static tests can confirm that every img has an alt attribute and numeric dimensions. They cannot determine whether the alternative expresses the image's purpose. Review each image alongside its heading and nearby text. This is an editorial judgment supported by structural checks, not replaced by them.

Worked practice

Worked exercise 1: Choose empty or descriptive alt

Task: A small swirl separates two sections and adds no information. Worked answer: use alt="" if the swirl is an img, or consider a CSS decoration. Describing it as “blue swirl decoration” would add noise to the reading sequence without helping a visitor understand the workshop.

Worked exercise 2: Preserve proportions

Task: A 640-by-360 image must fit a 320-pixel-wide area. Worked answer: its proportional height is 180 pixels, because both dimensions are halved. Prefer responsive CSS rather than hardcoding every display size. Keep the width and height attributes at a matching ratio so the browser can reserve the correct shape.

Worked exercise 3: Repair an image-only link

Task: A link to the schedule contains only an image with alt="calendar icon". Worked answer: use a meaningful link name such as “Workshop schedule,” either as the alternative or visible text. The visitor needs to know the destination, not merely the visual symbol used to represent it.

Knowledge check

Question 1

What does alt="" usually communicate? A) The author forgot to supply an alternative. B) The image is intentionally decorative in context. C) The caption always replaces the need to assess image purpose. D) The image’s filename should be used as its description.

Check question 1: answer and explanation

Answer: B. An empty alternative deliberately removes noninformative image content from the reading flow.

Question 2

Why provide matching width and height attributes? A) To reserve an aspect ratio. B) To set the image file’s compression level. C) To guarantee the image can never exceed its container. D) To describe the visual information to screen readers.

Check question 2: answer and explanation

Answer: A. The browser can allocate space before loading and reduce layout shifts.

Question 3

What should a complex diagram receive? A) A short label with no equivalent for the diagram’s details. B) A filename so users can locate the original. C) An appropriate short alternative plus a fuller equivalent when needed. D) A caption that repeats the surrounding heading but omits the diagram’s relationships.

Check question 3: answer and explanation

Answer: C. The information must remain available beyond the image itself.

Question 4

Which is usually best for essential event details? A) Text embedded only in a poster. B) Real HTML text. C) A background image containing the schedule. D) A link to an image with no equivalent text.

Check question 4: answer and explanation

Answer: B. HTML text can adapt to resizing, translation, and assistive access.

Question 5

Can a missing-alt checker judge the quality of every alternative? A) Yes, because any nonempty alt is meaningful. B) Yes, if every image also has width and height. C) Yes, if filenames describe the image subjects. D) No.

Check question 5: answer and explanation

Answer: D. Purpose and surrounding context require human judgment beyond attribute presence.

Sources and further reading